From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8BAF15CAD for ; Tue, 8 Nov 2022 13:59:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A355C433D6; Tue, 8 Nov 2022 13:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1667915985; bh=1EftSQSugeLnLQeL9Q+r8Sx3dqvD+l3CF1+F5HegrDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fr1l/MoBUzL12WQKXxL6BaENid5f5q51bP6LGbViaadUtjg25jezfAChTa3xZokON pm+clqZGTrGSICl++WZV1MjvQXBAQ2fFRpbn8IB3UNGLic/Cw8mGsHyQIgVQ+GU2de WHrLCWT3qK6piPaZRE1rVrUPotEUhllxAKqoOMa4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shang XiaoJing , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 029/144] nfc: nxp-nci: Fix potential memory leak in nxp_nci_send() Date: Tue, 8 Nov 2022 14:38:26 +0100 Message-Id: <20221108133346.512227508@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221108133345.346704162@linuxfoundation.org> References: <20221108133345.346704162@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Shang XiaoJing [ Upstream commit 7bf1ed6aff0f70434bd0cdd45495e83f1dffb551 ] nxp_nci_send() will call nxp_nci_i2c_write(), and only free skb when nxp_nci_i2c_write() failed. However, even if the nxp_nci_i2c_write() run succeeds, the skb will not be freed in nxp_nci_i2c_write(). As the result, the skb will memleak. nxp_nci_send() should also free the skb when nxp_nci_i2c_write() succeeds. Fixes: dece45855a8b ("NFC: nxp-nci: Add support for NXP NCI chips") Signed-off-by: Shang XiaoJing Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/nfc/nxp-nci/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/nfc/nxp-nci/core.c b/drivers/nfc/nxp-nci/core.c index 518e2afb43a8..13c433eb694d 100644 --- a/drivers/nfc/nxp-nci/core.c +++ b/drivers/nfc/nxp-nci/core.c @@ -77,10 +77,13 @@ static int nxp_nci_send(struct nci_dev *ndev, struct sk_buff *skb) return -EINVAL; r = info->phy_ops->write(info->phy_id, skb); - if (r < 0) + if (r < 0) { kfree_skb(skb); + return r; + } - return r; + consume_skb(skb); + return 0; } static const struct nci_ops nxp_nci_ops = { -- 2.35.1