cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [cocci] [PATCH 0/2] nfc: mei_phy: Adjustments for two function implementations
@ 2023-12-27 16:00 Markus Elfring
  2023-12-27 16:02 ` [cocci] [PATCH 1/2] nfc: mei_phy: Return directly after a failed kzalloc() in mei_nfc_send() Markus Elfring
  2023-12-27 16:04 ` [cocci] [PATCH 2/2] nfc: mei_phy: Use common code in mei_nfc_connect() Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Markus Elfring @ 2023-12-27 16:00 UTC (permalink / raw)
  To: netdev, kernel-janitors, Krzysztof Kozlowski; +Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 27 Dec 2023 16:53:21 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Return directly after a failed kzalloc() in mei_nfc_send()
  Use common code in mei_nfc_connect()

 drivers/nfc/mei_phy.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [cocci] [PATCH 1/2] nfc: mei_phy: Return directly after a failed kzalloc() in mei_nfc_send()
  2023-12-27 16:00 [cocci] [PATCH 0/2] nfc: mei_phy: Adjustments for two function implementations Markus Elfring
@ 2023-12-27 16:02 ` Markus Elfring
  2023-12-27 16:04 ` [cocci] [PATCH 2/2] nfc: mei_phy: Use common code in mei_nfc_connect() Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2023-12-27 16:02 UTC (permalink / raw)
  To: netdev, kernel-janitors, Krzysztof Kozlowski; +Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 drivers/nfc/mei_phy.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

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;
--
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [cocci] [PATCH 2/2] nfc: mei_phy: Use common code in mei_nfc_connect()
  2023-12-27 16:00 [cocci] [PATCH 0/2] nfc: mei_phy: Adjustments for two function implementations Markus Elfring
  2023-12-27 16:02 ` [cocci] [PATCH 1/2] nfc: mei_phy: Return directly after a failed kzalloc() in mei_nfc_send() Markus Elfring
@ 2023-12-27 16:04 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2023-12-27 16:04 UTC (permalink / raw)
  To: netdev, kernel-janitors, Krzysztof Kozlowski; +Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 drivers/nfc/mei_phy.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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;
--
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-27 16:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-27 16:00 [cocci] [PATCH 0/2] nfc: mei_phy: Adjustments for two function implementations Markus Elfring
2023-12-27 16:02 ` [cocci] [PATCH 1/2] nfc: mei_phy: Return directly after a failed kzalloc() in mei_nfc_send() Markus Elfring
2023-12-27 16:04 ` [cocci] [PATCH 2/2] nfc: mei_phy: Use common code in mei_nfc_connect() Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).