Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7275461imu; Wed, 14 Nov 2018 14:41:14 -0800 (PST) X-Google-Smtp-Source: AJdET5fc6rwmH+iyCV5Vp6DniMcrg+iP078KAVo2h21WIKmYTPCANYNdQV84F8PQfgHADetEgwy5 X-Received: by 2002:a17:902:9009:: with SMTP id a9-v6mr3791898plp.134.1542235274511; Wed, 14 Nov 2018 14:41:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235274; cv=none; d=google.com; s=arc-20160816; b=xgPGIpiJmeHZrM3jQt3wn+2eQoEBpMM34DX4qVdgWoRoCs4SyIkqKVEl2v7e3LNLpi KXlJYB0ZKHMTiyiL43MnmPkUzoYtWcuL5PXgqUvLXpRewLnfGiOnAlWofX9tiM3Pihyz uYjv41DHCwiH63iJIrNdyRf8ONBzWFCNYbppxQM92oAwhAkbKcmfJKi1g4Y/WSYqU8NR p/ROmX5S0bzyulQA4ABh9vCU8/vuzAj5TKiM2L7wZvqTvfELYKG83PNxK8UrEVqBKKZc wnCfih/Cys+rFN1bsYOXJx84yFCeq5Ct9RJ/bLf/vIVqv5XmIDLVeZVvrKC1hmjamK0R TXsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=u1WxGoZIYq851L6Ru5t0I+SPtt+gTuCqD+RSfFjxE7U=; b=rxFIGcb5PS5IvT7h1OJTgZmhZUGCUM6B5qXWJ6BxO6rCxdmWcvWisVm1Njibko8eP+ JStnvQWe6UfLY9x+TK4NhLYA9wYHEUMK83xfEU4Y7uAXe0c0JG3reVcVdlFY1dMNCnZH iyMN+2Yi7HKLh8wjxhsOuDMl5Y30etxRFmTC8jExIhHOVBxKF9jBB7MpGaOkRRx9zWIY PQBWrzzPPtbVNa///9N2/NCg/0TF+9THSxV50JvXhc6Pvw+zkOdvlUFBgg1dqlcrMWSa K4QtkrZgCS5UA0IaPtD1jPAghZvGaqOS0L3inzPRWt5YsGxKkREwMQXCtnngWbdF5/0f ZJuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m2pZWqA6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o69-v6si30236952pfo.78.2018.11.14.14.41.00; Wed, 14 Nov 2018 14:41:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m2pZWqA6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729080AbeKOI10 (ORCPT + 99 others); Thu, 15 Nov 2018 03:27:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:34416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729032AbeKOI10 (ORCPT ); Thu, 15 Nov 2018 03:27:26 -0500 Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C5C6022520; Wed, 14 Nov 2018 22:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542234142; bh=gBQg2d1D88jv3FxnUPFkv8Z5gUs9Ya6aolVT3+ZfWUE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m2pZWqA6elEAMwFd2pj+tiA6/c9+1u79t3wefx/PEHGrQEpu2GJRJRiWZ78ZLHuo/ I/xebMYtiKxVT1nCxLMkfX52uPgnfOhDtuNSyQeTqRmc7lKMjlSVHOxC57MJVfOROb 4iJc5dxM0ukLgMiMG6Co9OcWdfLaXTneH7UdX3u4= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Denis Bolotin , Michal Kalderon , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL 4.19 60/73] qed: Fix memory/entry leak in qed_init_sp_request() Date: Wed, 14 Nov 2018 17:21:54 -0500 Message-Id: <20181114222207.98701-60-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114222207.98701-1-sashal@kernel.org> References: <20181114222207.98701-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Denis Bolotin [ Upstream commit 39477551df940ddb1339203817de04f5caaacf7a ] Free the allocated SPQ entry or return the acquired SPQ entry to the free list in error flows. Signed-off-by: Denis Bolotin Signed-off-by: Michal Kalderon Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- .../net/ethernet/qlogic/qed/qed_sp_commands.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qed/qed_sp_commands.c b/drivers/net/ethernet/qlogic/qed/qed_sp_commands.c index 77b6248ad3b9..e86a1ea23613 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_sp_commands.c +++ b/drivers/net/ethernet/qlogic/qed/qed_sp_commands.c @@ -80,7 +80,7 @@ int qed_sp_init_request(struct qed_hwfn *p_hwfn, case QED_SPQ_MODE_BLOCK: if (!p_data->p_comp_data) - return -EINVAL; + goto err; p_ent->comp_cb.cookie = p_data->p_comp_data->cookie; break; @@ -95,7 +95,7 @@ int qed_sp_init_request(struct qed_hwfn *p_hwfn, default: DP_NOTICE(p_hwfn, "Unknown SPQE completion mode %d\n", p_ent->comp_mode); - return -EINVAL; + goto err; } DP_VERBOSE(p_hwfn, QED_MSG_SPQ, @@ -109,6 +109,18 @@ int qed_sp_init_request(struct qed_hwfn *p_hwfn, memset(&p_ent->ramrod, 0, sizeof(p_ent->ramrod)); return 0; + +err: + /* qed_spq_get_entry() can either get an entry from the free_pool, + * or, if no entries are left, allocate a new entry and add it to + * the unlimited_pending list. + */ + if (p_ent->queue == &p_hwfn->p_spq->unlimited_pending) + kfree(p_ent); + else + qed_spq_return_entry(p_hwfn, p_ent); + + return -EINVAL; } static enum tunnel_clss qed_tunn_clss_to_fw_clss(u8 type) -- 2.17.1