From patchwork Wed Dec 27 16:02:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 13505352 X-Patchwork-Delegate: kuba@kernel.org Received: from mout.web.de (mout.web.de [212.227.15.4]) (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 585F446534; Wed, 27 Dec 2023 16:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="nXKyQupF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1703692924; x=1704297724; i=markus.elfring@web.de; bh=16Blx+9N7z4bjqF+m7XVewE8iR9w3Nt9BYK+5r91TuE=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References: In-Reply-To; b=nXKyQupFmo4m64oK7Py/UPodRNB3Pkrvj3shcnAfO2VQxs7d9/u5Ag3vc20ym/GO 8T6B/pCtyLiaT5LUVgZpD4AZTmoi5L4QF/bVf+xqET27S5e0ACm6PY7Q0x6+/TSBK kDuqYBwr9jiHYPXH+AE7bTapOzwThYXh/HBJZcPMmkLc2OhLVtBRuwxKTAVSqQw/E 92xQqq93cZhiQs0MwCQ6Jg5yLqlRraQceUdCULwYzPX1QxZoe14Ox4NOaGhLcJx9q uR0Y9PwZ7HvjZGNlGtUdNhcHC6kA9bqmOqQENrZIgCtAgawxp1/WaH1GBZD+ZyORm ucvyUHan+B2/NBlxzg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.85.95]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1N7QUL-1rBDIP0ksn-017MNO; Wed, 27 Dec 2023 17:02:04 +0100 Message-ID: <0a98d3b6-e0ec-408a-aa2d-f2b23dcff26f@web.de> Date: Wed, 27 Dec 2023 17:02:03 +0100 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/2] nfc: mei_phy: Return directly after a failed kzalloc() in mei_nfc_send() Content-Language: en-GB From: Markus Elfring To: netdev@vger.kernel.org, kernel-janitors@vger.kernel.org, Krzysztof Kozlowski Cc: LKML , cocci@inria.fr References: <9a683f73-c5a2-4b80-af1b-01540834a3dd@web.de> In-Reply-To: <9a683f73-c5a2-4b80-af1b-01540834a3dd@web.de> X-Provags-ID: V03:K1:W/Z8o/ebT8qpjn7mjOZHqGDXLydJr/iUnte/oPoN9Zad6aSwnd7 oNHLsGSs4G2L5LWejGRz55i4BzHmghDJS26wD0kCFK1fQ14uOyh5V6eysxyvezJtsDqZqhT 6+h7hUlmjX5oCaUBtQ2wH6Kg/wQU58+EWPUZlz1eVHEY5APPwLTiKJtgKflCal6fhmnODBd 2m9sNG/OAtgrng0ux2Gfg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:RwLqXCnTS9U=;WB/CrvRL8cCZcbwoyAyBMq31xJZ Yh+p0YHY2Z9lkWI3ozXZwEXCOK6KYLocBXOlpsf6A9hcfX0vbGz36Cj4t3JnValiIhhFNk/lK g4L7ZpP8o6aIpEo44fl/Nm25vBrgBWCPxX4Lu4csC8mlkblRhsPSoXhAPDSxyaiJPVFzr9R8r 5lV6YA43DJi9v4OMdT5DuqAReYNWrEVDq8bXAP8Hy9sFbM0712pW8ub5Hf0CZejYH1vdG8zNC 755xYwVuODj+XXWrAt+ENVw6l6RXWF/qPbGQlVoN6TGRpjLkOMhb+kLir/LXOIeb7HYnB7xb6 nhYkHXsaZhZFMIU63pt+J8ALoqgnht36er8APhCQAyh+0slogvBcXMDa1bU0X7aDSGPfqIyhH bwwnARIiu7SGKCpAjtOhYNg31qDzZDm2pKxS7DGO/KolIUNKlpl4G7aPOSVsl925Z8MvMSMql OFfgm5+GzmxWd9PsyJnxQk0OlZ9Qy73VAEo8jH+w3NO9BAqMtTycWPjGTQVAjgg44D9l2oLJl oY5VtNRIg+RDXBxOLj8FVYl1kDcpWqPyDQRZJZs7PYKhef4BzjzMV4PAe0bX7OGB66/TsVheC BSQeq+v8mWQdk76d/KHRwkYXdoKG76K1cmVnb+aMcgpuxF5Zb+jn73CJbK3FEFD/BKT5OIkGP n3aE98Gj68goGUmdKgQUyLbX8URiTlB1hoDtGUiBIXkB6kgjtXI8T+8AuYxVZnnsnAxyGtKI8 6tOi9yLiKQl1FADwfc78SCEMRUSot4ao5aaZx4a/qqa8ToDGXUzH1WiPt6DZCiix9Tea3T6/A rttbihdh3TuZe8kA7MUkAaTVgZ/UtUi/yBNtELjRnysQqOkJCEdXKc1khazNnOCPrZ8jZ6BBo DS9RxW15Ishhxbz/azlCMVLuCJVigNJzWo/GEvSbj+Q9xBr6lrKoK1Dhk2H+7Verwpruq6fdY wfcTXw== X-Patchwork-Delegate: kuba@kernel.org From: Markus Elfring Date: Wed, 27 Dec 2023 16:30:20 +0100 The kfree() function was called in one case by the mei_nfc_send() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software. Thus return directly after a call of the function “kzalloc” failed at the beginning. Signed-off-by: Markus Elfring --- drivers/nfc/mei_phy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.43.0 diff --git a/drivers/nfc/mei_phy.c b/drivers/nfc/mei_phy.c index f9cca885beec..937f229f4646 100644 --- a/drivers/nfc/mei_phy.c +++ b/drivers/nfc/mei_phy.c @@ -208,10 +208,9 @@ static int mei_nfc_send(struct nfc_mei_phy *phy, const u8 *buf, size_t length) u8 *mei_buf; int err; - err = -ENOMEM; mei_buf = kzalloc(length + MEI_NFC_HEADER_SIZE, GFP_KERNEL); if (!mei_buf) - goto out; + return -ENOMEM; hdr = (struct mei_nfc_hdr *)mei_buf; hdr->cmd = MEI_NFC_CMD_HCI_SEND; From patchwork Wed Dec 27 16:04:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 13505353 X-Patchwork-Delegate: kuba@kernel.org Received: from mout.web.de (mout.web.de [212.227.15.4]) (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 0FFA145BE1; Wed, 27 Dec 2023 16:04:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="Lc7DXIYX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1703693048; x=1704297848; i=markus.elfring@web.de; bh=pl0j2jlBOHpdYumEB//84LCnmc+A204WKvvK9JoNUAE=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References: In-Reply-To; b=Lc7DXIYXmosy75uibtNwU2cS73VVZK/cSY03ClKiUfkc3xCBdEUSUhUXcM/eGCuf A1UIWN9B3ov2GXqI0XIudj3W5EBW9Z9gJ1fS2y6hMbedWD6vfQe4PkP/BHjGmUwrt BV8S1Sxtr2OMJd6m2ScU2zt6gfArVTew+s7tFcTz8VBc2coa4xv9YMSqaaYsRrXcQ zeHkfXjEb7GNuEyGITi/A/jgI7YZRRIweLFtE7qEyUUvAn2j4PSwxbIIJeR3JEhxO nXQY6uNdJYdjqGEIC2zDiFigS/klkNAI7h66Hj95lkG6bxYIc3v7wYp6HxffD+Lvn QLvkSkGoyf+g14M72Q== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.85.95]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MsaWF-1qzbcp0V5P-00tfcP; Wed, 27 Dec 2023 17:04:08 +0100 Message-ID: Date: Wed, 27 Dec 2023 17:04:07 +0100 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/2] nfc: mei_phy: Use common code in mei_nfc_connect() Content-Language: en-GB From: Markus Elfring To: netdev@vger.kernel.org, kernel-janitors@vger.kernel.org, Krzysztof Kozlowski Cc: LKML , cocci@inria.fr References: <9a683f73-c5a2-4b80-af1b-01540834a3dd@web.de> In-Reply-To: <9a683f73-c5a2-4b80-af1b-01540834a3dd@web.de> X-Provags-ID: V03:K1:LZLFy8584bM7nNvphHPs21dMyK0NX/xpt7a2sjgekqHU4DF+tEL WjRYzV4ttYUlRj83D4tFBpGhcOM+pyUOdHz/+n+XxOJR9XwmI7NIjO0jcbRPnq2irlBhPI1 k5lrKOh4gkYiiVMVFys6gf/EnPWuWSSD4VYet/9cD1aRbzIDHxqWH8wPNQho9BZeYQmoeyz sI6ttaVBn4EQG3K3p56TA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:CSPkLoRkgos=;ca8zaDvllZcwLBz4r7X8tu5athr 2swnmbXxg5vxZkB9gKnLlviRogKVGDF9nzhbue8EZb4Q+BZU/DTtLKc6h88hpx2K2OECRMgbU dbzQIp+MWaBHtLEs9+BfDfFK7qvcJofZba7MESK82h52cTvvebloPxGO+Y63Ale2OTiGiWxcW YQPCuqOhhSKeZcTSudoCje9/Uhv0HZgSm6WIzM/A/DbmNjTgpm23Zcr+5Pz6oyvfif9Xp0tex BfGmJIEHjUnruhlX2YcaRWFPfUlmcRgw5fvidF+ZElxHySRInhMvhZh2za85Q4JRL1TC7lQOQ fO9Qkfag6b8moUMWqqLVC0a+TvloxQIHL+/Ev4clZRlRu0fxCve096umXkb60T0zuVe1VQ1e3 WiutHjb/l/ByZG23vYJSY3gMizKk2l/v4xYBUS97KIsBAtZF51PuxVtUMXnkBzWyIO4LG8IoB o2uMk+khs3zM8Zxpbi7OPceEhO1kO4feu8cdULHTeF47pzm0pxuykc8RRpcnEtRJ88GBBkuik EwulqbHTlCz2xBmSe5GO+7V+s8mF3T+E5S0LwU5WFiAreyiH2y4DpJG9bW2PN8bMUTjBcoD75 74tSywDeRvIOK5aFVkQZoOf7M7yoEJO/of2WreZHJeoSswGFpUfsVKU1NigxW0+PSd0VtHloW 1fKcVONAIFPQFiIjuW5A9OsUWaILggTjAbUFHH6m5+jg2KMbuo1ySyCroRAuRA8eU3iRV6Ozk 1Z19v4Fgq3boKVUyJGci/As68vXOL/5mxf3+JjBzLh5WllGWRQKMEgtnIGa+YGcv23QT7fPDN lVMp2+pW0Vy9UVXKym1ueqEdf3gTvRvDDMlGC6FQRwXtW+UBqXS9w4CFOhTWpafvhCA+Y5kkG mqzltRDgxuhznRqYjNunl9qvC0l60YJyCdhl4l7TgMg2LbHD2fwP9kZ73br6Vo/JsTHeVi7Ka 3pO1DrocWNovKtms3CXZv7rnWu0= X-Patchwork-Delegate: kuba@kernel.org From: Markus Elfring Date: Wed, 27 Dec 2023 16:45:39 +0100 Use another label so that a kfree() call can be better reused at the end of this function. Signed-off-by: Markus Elfring --- drivers/nfc/mei_phy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.43.0 diff --git a/drivers/nfc/mei_phy.c b/drivers/nfc/mei_phy.c index 937f229f4646..9272564012b3 100644 --- a/drivers/nfc/mei_phy.c +++ b/drivers/nfc/mei_phy.c @@ -157,8 +157,8 @@ static int mei_nfc_connect(struct nfc_mei_phy *phy) reply = kzalloc(connect_resp_length, GFP_KERNEL); if (!reply) { - kfree(cmd); - return -ENOMEM; + r = -ENOMEM; + goto free_cmd; } connect_resp = (struct mei_nfc_connect_resp *)reply->data; @@ -197,6 +197,7 @@ static int mei_nfc_connect(struct nfc_mei_phy *phy) err: kfree(reply); +free_cmd: kfree(cmd); return r;