mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] bus: fsl-mc:  Fix the double free in fsl_mc_device_add()
@ 2024-11-14  8:27 Su Hui
  2024-11-14  8:41 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Su Hui @ 2024-11-14  8:27 UTC (permalink / raw)
  To: stuyoder, laurentiu.tudor, nathan, ndesaulniers, morbo, justinstitt
  Cc: Su Hui, gregkh, linux-kernel, llvm, kernel-janitors

Clang static checker(scan-build) warning:
drivers/bus/fsl-mc/fsl-mc-bus.c: line 909, column 2
Attempt to free released memory.

When 'obj_desc->type' == "dprc" and begin to free 'mc_bus' and 'mc_dev',
there is a double free problem because of 'mc_dev = &mc_bus->mc_dev'.
Add a judgment to fix this problem.

Fixes: a042fbed0290 ("staging: fsl-mc: simplify couple of deallocations")
Signed-off-by: Su Hui <suhui@nfschina.com>
---
 drivers/bus/fsl-mc/fsl-mc-bus.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c
index 930d8a3ba722..8d2d5d3cc782 100644
--- a/drivers/bus/fsl-mc/fsl-mc-bus.c
+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
@@ -905,8 +905,10 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
 
 error_cleanup_dev:
 	kfree(mc_dev->regions);
-	kfree(mc_bus);
-	kfree(mc_dev);
+	if (strcmp(mc_dev->obj_desc.type, "dprc") == 0)
+		kfree(mc_bus);
+	else
+		kfree(mc_dev);
 
 	return error;
 }
-- 
2.30.2


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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-14  8:27 [PATCH] bus: fsl-mc: Fix the double free in fsl_mc_device_add() Su Hui
2024-11-14  8:41 ` Dan Carpenter
2024-11-14  8:57   ` Dan Carpenter
2024-11-14  9:34     ` Su Hui

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

all inboxes | Powered by JetHome®