Skip to content

Commit

Permalink
EDAC/sysfs: Drop device references properly
Browse files Browse the repository at this point in the history
Do put_device() if device_add() fails.

 [ bp: do device_del() for the successfully created devices in
   edac_create_csrow_objects(), on the unwind path. ]

Signed-off-by: Greg KH <gregkh@linuxfoundation.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20190427214925.GE16338@kroah.com
  • Loading branch information
Greg KH authored and Tony Luck committed Jun 20, 2019
1 parent 585fb3d commit 7adc05d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions drivers/edac/edac_mc_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ static int edac_create_csrow_objects(struct mem_ctl_info *mci)
csrow = mci->csrows[i];
if (!nr_pages_per_csrow(csrow))
continue;
put_device(&mci->csrows[i]->dev);

device_del(&mci->csrows[i]->dev);
}

return err;
Expand Down Expand Up @@ -651,9 +652,11 @@ static int edac_create_dimm_object(struct mem_ctl_info *mci,
dev_set_drvdata(&dimm->dev, dimm);
pm_runtime_forbid(&mci->dev);

err = device_add(&dimm->dev);
err = device_add(&dimm->dev);
if (err)
put_device(&dimm->dev);

edac_dbg(0, "creating rank/dimm device %s\n", dev_name(&dimm->dev));
edac_dbg(0, "created rank/dimm device %s\n", dev_name(&dimm->dev));

return err;
}
Expand Down Expand Up @@ -934,6 +937,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci,
err = device_add(&mci->dev);
if (err < 0) {
edac_dbg(1, "failure: create device %s\n", dev_name(&mci->dev));
put_device(&mci->dev);
goto out;
}

Expand Down

0 comments on commit 7adc05d

Please sign in to comment.