EDAC: Fix reference count leaks
authorQiushi Wu <wu000273@umn.edu>
Thu, 28 May 2020 20:22:37 +0000 (15:22 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Aug 2020 09:01:56 +0000 (11:01 +0200)
commit91a1b253ed61172d87dd8c5408897c91a8ece426
tree4762236c9321848245ab55001d0926ee85cdc23d
parentf3b1d647251a94a6968a35e3d685dc8b1b24c3ff
EDAC: Fix reference count leaks

[ Upstream commit 17ed808ad243192fb923e4e653c1338d3ba06207 ]

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
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/edac/edac_device_sysfs.c
drivers/edac/edac_pci_sysfs.c