[PATCH v2] edac: fix kobject refcount leak in edac_device_create_instance

WenTao Liang <[email protected]>
Newsgroups org.kernel.vger.linux-edac,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
kobject_get(&edac_dev->kobj) acquires a reference on main_kobj, but it is
only released when kobject_init_and_add fails. The success path and the
block-creation error path both return without calling
kobject_put(main_kobj), leaking the edac_dev kobject reference. The
main_kobj pointer is local and lost after function return.

Suggested-by: Greg KH <[email protected]>
Fixes: bee33f22d7c3 ("clocksource/drivers/nxp-pit: Add NXP Automotive s32g2 / s32g3 support")
Cc: [email protected]
Signed-off-by: WenTao Liang <[email protected]>
---
Changes in v2:
- Fix patch format based on reviewer feedback
---
 drivers/edac/edac_device_sysfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
index b1c2717cd023..72b06d608b98 100644
--- a/drivers/edac/edac_device_sysfs.c
+++ b/drivers/edac/edac_device_sysfs.c
@@ -647,6 +647,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
 
 	/* error unwind stack */
 err_release_instance_kobj:
+	kobject_put(main_kobj);
 	kobject_put(&instance->kobj);
 
 err_out:
-- 
2.39.5 (Apple Git-154)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.