EDAC: Fix reference count leaks
authorQiushi Wu <wu000273@umn.edu>
Thu, 28 May 2020 20:22:37 +0000 (15:22 -0500)
committerBorislav Petkov <bp@suse.de>
Wed, 17 Jun 2020 13:38:35 +0000 (15:38 +0200)
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: b2ed215a3338 ("Kobject: change drivers/edac to use kobject_init_and_add")
Signed-off-by: Qiushi Wu <wu000273@umn.edu>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200528202238.18078-1-wu000273@umn.edu
Link: https://lkml.kernel.org/r/20200528203526.20908-1-wu000273@umn.edu
drivers/edac/edac_device_sysfs.c
drivers/edac/edac_pci_sysfs.c

index 0e7ea3591b7812987c9e2efdb63dfa2a5306aa72..5e75937537997c2a49fba9da0252909b50a11e56 100644 (file)
@@ -275,6 +275,7 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
 
        /* Error exit stack */
 err_kobj_reg:
+       kobject_put(&edac_dev->kobj);
        module_put(edac_dev->owner);
 
 err_out:
index 72c9eb9fdffbe497142d542b777997cddfb1c1b7..53042af7262e2a6aca5843c85dcd1cacbe0a658c 100644 (file)
@@ -386,7 +386,7 @@ static int edac_pci_main_kobj_setup(void)
 
        /* Error unwind statck */
 kobject_init_and_add_fail:
-       kfree(edac_pci_top_main_kobj);
+       kobject_put(edac_pci_top_main_kobj);
 
 kzalloc_fail:
        module_put(THIS_MODULE);