Linux-HyperV List
 help / color / mirror / Atom feed
* [PATCH] Drivers: hv: vmbus: One function call less in create_gpadl_header() after error detection
@ 2023-12-26 19:09 Markus Elfring
  2024-01-10  5:41 ` Michael Kelley
  0 siblings, 1 reply; 11+ messages in thread
From: Markus Elfring @ 2023-12-26 19:09 UTC (permalink / raw)
  To: linux-hyperv, kernel-janitors, Dexuan Cui, Haiyang Zhang,
	K. Y. Srinivasan, Wei Liu
  Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 26 Dec 2023 20:00:24 +0100

The kfree() function was called in two cases by
the create_gpadl_header() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

Thus use another label.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/hv/channel.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index 56f7e06c673e..4d1bbda895d8 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -336,7 +336,7 @@ static int create_gpadl_header(enum hv_gpadl_type type, void *kbuffer,
 			  sizeof(struct gpa_range) + pfncount * sizeof(u64);
 		msgheader =  kzalloc(msgsize, GFP_KERNEL);
 		if (!msgheader)
-			goto nomem;
+			goto free_body;

 		INIT_LIST_HEAD(&msgheader->submsglist);
 		msgheader->msgsize = msgsize;
@@ -417,7 +417,7 @@ static int create_gpadl_header(enum hv_gpadl_type type, void *kbuffer,
 			  sizeof(struct gpa_range) + pagecount * sizeof(u64);
 		msgheader = kzalloc(msgsize, GFP_KERNEL);
 		if (msgheader == NULL)
-			goto nomem;
+			goto free_body;

 		INIT_LIST_HEAD(&msgheader->submsglist);
 		msgheader->msgsize = msgsize;
@@ -439,6 +439,7 @@ static int create_gpadl_header(enum hv_gpadl_type type, void *kbuffer,
 	return 0;
 nomem:
 	kfree(msgheader);
+free_body:
 	kfree(msgbody);
 	return -ENOMEM;
 }
--
2.43.0


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

end of thread, other threads:[~2024-01-11 14:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-26 19:09 [PATCH] Drivers: hv: vmbus: One function call less in create_gpadl_header() after error detection Markus Elfring
2024-01-10  5:41 ` Michael Kelley
2024-01-10 10:58   ` Markus Elfring
2024-01-10 16:15     ` Michael Kelley
2024-01-10 17:08       ` Markus Elfring
2024-01-10 17:53         ` Michael Kelley
2024-01-10 18:37       ` Dan Carpenter
2024-01-10 22:17         ` Michael Kelley
2024-01-11  7:04           ` Dan Carpenter
2024-01-11 14:35             ` Michael Kelley
2024-01-10 11:29   ` [PATCH] " Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox