[PATCH 3.16 001/328] EDAC: Fix memleak in module init error path

From: Ben Hutchings
Date: Sun Dec 09 2018 - 17:28:29 EST


3.16.62-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Johan Hovold <johan@xxxxxxxxxx>

commit 4708aa85d50cc6e962dfa8acf5ad4e0d290a21db upstream.

Make sure to use put_device() to free the initialised struct device so
that resources managed by driver core also gets released in the event of
a registration failure.

Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
Cc: Denis Kirjanov <kirjanov@xxxxxxxxx>
Cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx>
Cc: linux-edac <linux-edac@xxxxxxxxxxxxxxx>
Fixes: 2d56b109e3a5 ("EDAC: Handle error path in edac_mc_sysfs_init() properly")
Link: http://lkml.kernel.org/r/20180612124335.6420-1-johan@xxxxxxxxxx
Signed-off-by: Borislav Petkov <bp@xxxxxxx>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
---
drivers/edac/edac_mc_sysfs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -1161,14 +1161,14 @@ int __init edac_mc_sysfs_init(void)

err = device_add(mci_pdev);
if (err < 0)
- goto out_dev_free;
+ goto out_put_device;

edac_dbg(0, "device %s created\n", dev_name(mci_pdev));

return 0;

- out_dev_free:
- kfree(mci_pdev);
+ out_put_device:
+ put_device(mci_pdev);
out_put_sysfs:
edac_put_sysfs_subsys();
out: