diff mbox series

[02/21] EDAC: Fixes to use put_device() after device_add() errors

Message ID 20190529084344.28562-3-rrichter@marvell.com
State New
Headers show
Series EDAC, mc, ghes: Fixes and updates to improve memory error reporting | expand

Commit Message

Robert Richter May 29, 2019, 8:44 a.m. UTC
Always use put_device() after device_add() failed.

Signed-off-by: Robert Richter <rrichter@marvell.com>

---
 drivers/edac/edac_mc_sysfs.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

-- 
2.20.1

Comments

Borislav Petkov June 11, 2019, 5:28 p.m. UTC | #1
On Wed, May 29, 2019 at 08:44:05AM +0000, Robert Richter wrote:
> Always use put_device() after device_add() failed.

> 

> Signed-off-by: Robert Richter <rrichter@marvell.com>

> ---

>  drivers/edac/edac_mc_sysfs.c | 36 +++++++++++++++++++-----------------

>  1 file changed, 19 insertions(+), 17 deletions(-)


I already have a partial fix for that, you can send me the rest ontop:

https://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git/commit/?h=for-next&id=f5d59da9663d115b9cf62cce75a33382c880b560

Thx.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
Robert Richter June 12, 2019, 5:17 p.m. UTC | #2
On 11.06.19 19:28:30, Borislav Petkov wrote:
> On Wed, May 29, 2019 at 08:44:05AM +0000, Robert Richter wrote:

> > Always use put_device() after device_add() failed.

> > 

> > Signed-off-by: Robert Richter <rrichter@marvell.com>

> > ---

> >  drivers/edac/edac_mc_sysfs.c | 36 +++++++++++++++++++-----------------

> >  1 file changed, 19 insertions(+), 17 deletions(-)

> 

> I already have a partial fix for that, you can send me the rest ontop:

> 

> https://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git/commit/?h=for-next&id=f5d59da9663d115b9cf62cce75a33382c880b560


Ok, I have rebased onto for-next.

Thanks,

-Robert
diff mbox series

Patch

diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 464174685589..dbef699162a8 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -404,6 +404,8 @@  static inline int nr_pages_per_csrow(struct csrow_info *csrow)
 static int edac_create_csrow_object(struct mem_ctl_info *mci,
 				    struct csrow_info *csrow, int index)
 {
+	int err;
+
 	csrow->dev.type = &csrow_attr_type;
 	csrow->dev.groups = csrow_dev_groups;
 	device_initialize(&csrow->dev);
@@ -415,7 +417,11 @@  static int edac_create_csrow_object(struct mem_ctl_info *mci,
 	edac_dbg(0, "creating (virtual) csrow node %s\n",
 		 dev_name(&csrow->dev));
 
-	return device_add(&csrow->dev);
+	err = device_add(&csrow->dev);
+	if (err)
+		put_device(&csrow->dev);
+
+	return err;
 }
 
 /* Create a CSROW object under specifed edac_mc_device */
@@ -646,8 +652,11 @@  static int edac_create_dimm_object(struct mem_ctl_info *mci,
 	pm_runtime_forbid(&mci->dev);
 
 	err =  device_add(&dimm->dev);
-
-	edac_dbg(0, "creating rank/dimm device %s\n", dev_name(&dimm->dev));
+	if (err)
+		put_device(&dimm->dev);
+	else
+		edac_dbg(0, "creating rank/dimm device %s\n",
+			dev_name(&dimm->dev));
 
 	return err;
 }
@@ -927,8 +936,9 @@  int edac_create_sysfs_mci_device(struct mem_ctl_info *mci,
 	edac_dbg(0, "creating device %s\n", dev_name(&mci->dev));
 	err = device_add(&mci->dev);
 	if (err < 0) {
+		put_device(&mci->dev);
 		edac_dbg(1, "failure: create device %s\n", dev_name(&mci->dev));
-		goto out;
+		return err;
 	}
 
 	/*
@@ -977,7 +987,6 @@  int edac_create_sysfs_mci_device(struct mem_ctl_info *mci,
 	}
 	device_unregister(&mci->dev);
 
-out:
 	return err;
 }
 
@@ -1034,10 +1043,8 @@  int __init edac_mc_sysfs_init(void)
 	int err;
 
 	mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
-	if (!mci_pdev) {
-		err = -ENOMEM;
-		goto out;
-	}
+	if (!mci_pdev)
+		return -ENOMEM;
 
 	mci_pdev->bus = edac_get_sysfs_subsys();
 	mci_pdev->type = &mc_attr_type;
@@ -1046,15 +1053,10 @@  int __init edac_mc_sysfs_init(void)
 
 	err = device_add(mci_pdev);
 	if (err < 0)
-		goto out_put_device;
-
-	edac_dbg(0, "device %s created\n", dev_name(mci_pdev));
-
-	return 0;
+		put_device(mci_pdev);
+	else
+		edac_dbg(0, "device %s created\n", dev_name(mci_pdev));
 
- out_put_device:
-	put_device(mci_pdev);
- out:
 	return err;
 }