mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-05 02:19:51 +00:00
EDAC: Handle error path in edac_mc_sysfs_init() properly
Make sure proper deregistration happens on all error paths in edac_mc_sysfs_init. Signed-off-by: Denis Kirjanov <kirjanov@gmail.com> [ Boris: cleanup and concretize commit message ] Signed-off-by: Borislav Petkov <bp@alien8.de>
This commit is contained in:
parent
d5c6770d4c
commit
2d56b109e3
1 changed files with 15 additions and 2 deletions
|
@ -1126,10 +1126,15 @@ int __init edac_mc_sysfs_init(void)
|
||||||
edac_subsys = edac_get_sysfs_subsys();
|
edac_subsys = edac_get_sysfs_subsys();
|
||||||
if (edac_subsys == NULL) {
|
if (edac_subsys == NULL) {
|
||||||
edac_dbg(1, "no edac_subsys\n");
|
edac_dbg(1, "no edac_subsys\n");
|
||||||
return -EINVAL;
|
err = -EINVAL;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
|
mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
|
||||||
|
if (!mci_pdev) {
|
||||||
|
err = -ENOMEM;
|
||||||
|
goto out_put_sysfs;
|
||||||
|
}
|
||||||
|
|
||||||
mci_pdev->bus = edac_subsys;
|
mci_pdev->bus = edac_subsys;
|
||||||
mci_pdev->type = &mc_attr_type;
|
mci_pdev->type = &mc_attr_type;
|
||||||
|
@ -1138,11 +1143,18 @@ int __init edac_mc_sysfs_init(void)
|
||||||
|
|
||||||
err = device_add(mci_pdev);
|
err = device_add(mci_pdev);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
goto out_dev_free;
|
||||||
|
|
||||||
edac_dbg(0, "device %s created\n", dev_name(mci_pdev));
|
edac_dbg(0, "device %s created\n", dev_name(mci_pdev));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
out_dev_free:
|
||||||
|
kfree(mci_pdev);
|
||||||
|
out_put_sysfs:
|
||||||
|
edac_put_sysfs_subsys();
|
||||||
|
out:
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __exit edac_mc_sysfs_exit(void)
|
void __exit edac_mc_sysfs_exit(void)
|
||||||
|
@ -1150,4 +1162,5 @@ void __exit edac_mc_sysfs_exit(void)
|
||||||
put_device(mci_pdev);
|
put_device(mci_pdev);
|
||||||
device_del(mci_pdev);
|
device_del(mci_pdev);
|
||||||
edac_put_sysfs_subsys();
|
edac_put_sysfs_subsys();
|
||||||
|
kfree(mci_pdev);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue