Commit 36d04acf authored by Junjie Mao's avatar Junjie Mao Committed by Luis Henriques

EDAC: Fix the leak of mci->bus->name when bus_register fails

commit 1bf1950c upstream.

Also use goto labels for all failure paths in
edac_create_sysfs_mci_device and update meaningless labels.
Signed-off-by: default avatarJunjie Mao <junjie.mao@hotmail.com>
Link: http://lkml.kernel.org/r/BLU436-SMTP25291B6B612942A212AEBFE95300@phx.gbl
[ Boris: Use ! for 0 checks and add newlines for less crammed code. ]
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent b8b4a3a0
...@@ -987,7 +987,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -987,7 +987,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
err = bus_register(mci->bus); err = bus_register(mci->bus);
if (err < 0) if (err < 0)
return err; goto fail_free_name;
/* get the /sys/devices/system/edac subsys reference */ /* get the /sys/devices/system/edac subsys reference */
mci->dev.type = &mci_attr_type; mci->dev.type = &mci_attr_type;
...@@ -1003,9 +1003,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1003,9 +1003,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
err = device_add(&mci->dev); err = device_add(&mci->dev);
if (err < 0) { if (err < 0) {
edac_dbg(1, "failure: create device %s\n", dev_name(&mci->dev)); edac_dbg(1, "failure: create device %s\n", dev_name(&mci->dev));
bus_unregister(mci->bus); goto fail_unregister_bus;
kfree(mci->bus->name);
return err;
} }
if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) { if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
...@@ -1013,15 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1013,15 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO; dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show; dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
} }
if (mci->set_sdram_scrub_rate) { if (mci->set_sdram_scrub_rate) {
dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR; dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store; dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
} }
err = device_create_file(&mci->dev,
&dev_attr_sdram_scrub_rate); err = device_create_file(&mci->dev, &dev_attr_sdram_scrub_rate);
if (err) { if (err) {
edac_dbg(1, "failure: create sdram_scrub_rate\n"); edac_dbg(1, "failure: create sdram_scrub_rate\n");
goto fail2; goto fail_unregister_dev;
} }
} }
/* /*
...@@ -1030,8 +1029,9 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1030,8 +1029,9 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
for (i = 0; i < mci->tot_dimms; i++) { for (i = 0; i < mci->tot_dimms; i++) {
struct dimm_info *dimm = mci->dimms[i]; struct dimm_info *dimm = mci->dimms[i];
/* Only expose populated DIMMs */ /* Only expose populated DIMMs */
if (dimm->nr_pages == 0) if (!dimm->nr_pages)
continue; continue;
#ifdef CONFIG_EDAC_DEBUG #ifdef CONFIG_EDAC_DEBUG
edac_dbg(1, "creating dimm%d, located at ", i); edac_dbg(1, "creating dimm%d, located at ", i);
if (edac_debug_level >= 1) { if (edac_debug_level >= 1) {
...@@ -1046,14 +1046,14 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1046,14 +1046,14 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
err = edac_create_dimm_object(mci, dimm, i); err = edac_create_dimm_object(mci, dimm, i);
if (err) { if (err) {
edac_dbg(1, "failure: create dimm %d obj\n", i); edac_dbg(1, "failure: create dimm %d obj\n", i);
goto fail; goto fail_unregister_dimm;
} }
} }
#ifdef CONFIG_EDAC_LEGACY_SYSFS #ifdef CONFIG_EDAC_LEGACY_SYSFS
err = edac_create_csrow_objects(mci); err = edac_create_csrow_objects(mci);
if (err < 0) if (err < 0)
goto fail; goto fail_unregister_dimm;
#endif #endif
#ifdef CONFIG_EDAC_DEBUG #ifdef CONFIG_EDAC_DEBUG
...@@ -1061,16 +1061,19 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1061,16 +1061,19 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
#endif #endif
return 0; return 0;
fail: fail_unregister_dimm:
for (i--; i >= 0; i--) { for (i--; i >= 0; i--) {
struct dimm_info *dimm = mci->dimms[i]; struct dimm_info *dimm = mci->dimms[i];
if (dimm->nr_pages == 0) if (!dimm->nr_pages)
continue; continue;
device_unregister(&dimm->dev); device_unregister(&dimm->dev);
} }
fail2: fail_unregister_dev:
device_unregister(&mci->dev); device_unregister(&mci->dev);
fail_unregister_bus:
bus_unregister(mci->bus); bus_unregister(mci->bus);
fail_free_name:
kfree(mci->bus->name); kfree(mci->bus->name);
return err; return err;
} }
......
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