public inbox for linux-edac@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] EDAC: Fix some refcount leaks
@ 2022-05-11  8:14 Miaoqian Lin
  2022-05-11 14:33 ` kernel test robot
  2022-05-11 17:59 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Miaoqian Lin @ 2022-05-11  8:14 UTC (permalink / raw)
  To: Borislav Petkov, Mauro Carvalho Chehab, Tony Luck, James Morse,
	Robert Richter, Greg Kroah-Hartman, Doug Thompson, linux-edac,
	linux-kernel
  Cc: linmq006

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 this by calling kobject_put() when kobject_init_and_add() fails.

Fixes: b2ed215a3338 ("Kobject: change drivers/edac to use kobject_init_and_add")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/edac/edac_device_sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
index 9a61d92bdf42..08cba532ad48 100644
--- a/drivers/edac/edac_device_sysfs.c
+++ b/drivers/edac/edac_device_sysfs.c
@@ -542,7 +542,7 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,
 		edac_dbg(1, "Failed to register instance '%s'\n", block->name);
 		kobject_put(main_kobj);
 		err = -ENODEV;
-		goto err_out;
+		goto err_on_attrib;
 	}
 
 	/* If there are driver level block attributes, then added them
@@ -640,7 +640,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
 		edac_dbg(2, "Failed to register instance '%s'\n",
 			 instance->name);
 		kobject_put(main_kobj);
-		goto err_out;
+		goto edac_device_create_instance;
 	}
 
 	edac_dbg(4, "now register '%d' blocks for instance %d\n",
-- 
2.25.1


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

end of thread, other threads:[~2022-05-11 18:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-11  8:14 [PATCH] EDAC: Fix some refcount leaks Miaoqian Lin
2022-05-11 14:33 ` kernel test robot
2022-05-11 17:59 ` kernel test robot

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