Commit 44d22e24 authored by Lans Zhang's avatar Lans Zhang Committed by Borislav Petkov

EDAC: Cleanup device deregistering path

Use device_unregister to replace put_device + device_del for
cleanup, and fix the potential use after free.
Signed-off-by: default avatarLans Zhang <jia.zhang@windriver.com>
Signed-off-by: default avatarBorislav Petkov <bp@alien8.de>
parent 54451663
...@@ -472,8 +472,7 @@ static void edac_delete_csrow_objects(struct mem_ctl_info *mci) ...@@ -472,8 +472,7 @@ static void edac_delete_csrow_objects(struct mem_ctl_info *mci)
device_remove_file(&csrow->dev, device_remove_file(&csrow->dev,
dynamic_csrow_ce_count_attr[chan]); dynamic_csrow_ce_count_attr[chan]);
} }
put_device(&mci->csrows[i]->dev); device_unregister(&mci->csrows[i]->dev);
device_del(&mci->csrows[i]->dev);
} }
} }
#endif #endif
...@@ -1055,11 +1054,9 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1055,11 +1054,9 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
struct dimm_info *dimm = mci->dimms[i]; struct dimm_info *dimm = mci->dimms[i];
if (dimm->nr_pages == 0) if (dimm->nr_pages == 0)
continue; continue;
put_device(&dimm->dev); device_unregister(&dimm->dev);
device_del(&dimm->dev);
} }
put_device(&mci->dev); device_unregister(&mci->dev);
device_del(&mci->dev);
bus_unregister(&mci->bus); bus_unregister(&mci->bus);
kfree(mci->bus.name); kfree(mci->bus.name);
return err; return err;
...@@ -1086,16 +1083,14 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1086,16 +1083,14 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
if (dimm->nr_pages == 0) if (dimm->nr_pages == 0)
continue; continue;
edac_dbg(0, "removing device %s\n", dev_name(&dimm->dev)); edac_dbg(0, "removing device %s\n", dev_name(&dimm->dev));
put_device(&dimm->dev); device_unregister(&dimm->dev);
device_del(&dimm->dev);
} }
} }
void edac_unregister_sysfs(struct mem_ctl_info *mci) void edac_unregister_sysfs(struct mem_ctl_info *mci)
{ {
edac_dbg(1, "Unregistering device %s\n", dev_name(&mci->dev)); edac_dbg(1, "Unregistering device %s\n", dev_name(&mci->dev));
put_device(&mci->dev); device_unregister(&mci->dev);
device_del(&mci->dev);
bus_unregister(&mci->bus); bus_unregister(&mci->bus);
kfree(mci->bus.name); kfree(mci->bus.name);
} }
...@@ -1159,7 +1154,6 @@ int __init edac_mc_sysfs_init(void) ...@@ -1159,7 +1154,6 @@ int __init edac_mc_sysfs_init(void)
void __exit edac_mc_sysfs_exit(void) void __exit edac_mc_sysfs_exit(void)
{ {
device_del(mci_pdev); device_unregister(mci_pdev);
put_device(mci_pdev);
edac_put_sysfs_subsys(); edac_put_sysfs_subsys();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment