All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] edd: Fix memory leak in edd_init
@ 2022-01-20 11:13 Miaoqian Lin
  0 siblings, 0 replies; only message in thread
From: Miaoqian Lin @ 2022-01-20 11:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Miaoqian Lin, linux-kernel

edd_init calls edd_device_register(), which calls kobject_init_and_add()
and propagates the error code to the caller.
And kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add():

   If this function returns an error, kobject_put() must be called to
   properly clean up the memory associated with the object.

Fix the error handling by adding kobject_put().
And callback function edd_release() in kobject_put()
calls kfree(dev). So remove the redundant kfree(dev);

Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/firmware/edd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index 69353dd0ea22..1135e66f92bc 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -748,8 +748,8 @@ edd_init(void)
 		}
 
 		rc = edd_device_register(edev, i);
-		if (rc) {
-			kfree(edev);
+		if (rc < 0) {
+			kobject_put(&edev->kobj);
 			goto out;
 		}
 		edd_devices[i] = edev;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-20 11:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-20 11:13 [PATCH] edd: Fix memory leak in edd_init Miaoqian Lin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.