Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 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

authored by

Qiushi Wu and committed by
Borislav Petkov
17ed808a 8807e155

+2 -1
+1
drivers/edac/edac_device_sysfs.c
··· 275 275 276 276 /* Error exit stack */ 277 277 err_kobj_reg: 278 + kobject_put(&edac_dev->kobj); 278 279 module_put(edac_dev->owner); 279 280 280 281 err_out:
+1 -1
drivers/edac/edac_pci_sysfs.c
··· 386 386 387 387 /* Error unwind statck */ 388 388 kobject_init_and_add_fail: 389 - kfree(edac_pci_top_main_kobj); 389 + kobject_put(edac_pci_top_main_kobj); 390 390 391 391 kzalloc_fail: 392 392 module_put(THIS_MODULE);