Skip to content

Commit 17ed808

Browse files
QiushiWusuryasaimadhu
authored andcommitted
EDAC: Fix reference count leaks
When kobject_init_and_add() returns an error, it should be handled because kobject_init_and_add() takes a reference even when it fails. If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. Therefore, replace calling kfree() and call kobject_put() and add a missing kobject_put() in the edac_device_register_sysfs_main_kobj() error path. [ bp: Massage and merge into a single patch. ] Fixes: b2ed215 ("Kobject: change drivers/edac to use kobject_init_and_add") Signed-off-by: Qiushi Wu <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 8807e15 commit 17ed808

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

drivers/edac/edac_device_sysfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
275275

276276
/* Error exit stack */
277277
err_kobj_reg:
278+
kobject_put(&edac_dev->kobj);
278279
module_put(edac_dev->owner);
279280

280281
err_out:

drivers/edac/edac_pci_sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static int edac_pci_main_kobj_setup(void)
386386

387387
/* Error unwind statck */
388388
kobject_init_and_add_fail:
389-
kfree(edac_pci_top_main_kobj);
389+
kobject_put(edac_pci_top_main_kobj);
390390

391391
kzalloc_fail:
392392
module_put(THIS_MODULE);

0 commit comments

Comments
 (0)