linux-edac.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* EDAC: Fix memory leak in creating CSROW object
@ 2019-04-18  2:27 Pan Bian
  2019-04-18  2:27 ` Pan Bian
  2019-04-18 17:25 ` Borislav Petkov
  0 siblings, 2 replies; 15+ messages in thread
From: Pan Bian @ 2019-04-18  2:27 UTC (permalink / raw)
  To: Borislav Petkov, Mauro Carvalho Chehab, James Morse
  Cc: linux-edac, linux-kernel, Pan Bian

In the function that creates a CSROW object, the object is not released
when failing to add the device to device hierarchy. This may result in a
memory leak bug.

Signed-off-by: Pan Bian <bianpan2016@163.com>
---
 drivers/edac/edac_mc_sysfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 4641746..2dafb08 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -404,6 +404,7 @@ 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 +416,10 @@ 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 */

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-05-08 18:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-18  2:27 EDAC: Fix memory leak in creating CSROW object Pan Bian
2019-04-18  2:27 ` Pan Bian
2019-04-18 17:25 ` Borislav Petkov
2019-04-18 17:25   ` Borislav Petkov
     [not found]   ` <20190419003536.GA57795@bianpan2016@163.com>
2019-04-19  0:45     ` Borislav Petkov
2019-04-19  0:45       ` Borislav Petkov
2019-04-27 21:49       ` Greg Kroah-Hartman
2019-04-27 21:49         ` Greg KH
2019-05-08 10:57         ` Borislav Petkov
2019-05-08 12:47           ` Greg KH
2019-05-08 18:50             ` Borislav Petkov
2019-05-08 11:02         ` [PATCH 1/2] EDAC/sysfs: Fix memory leak when creating a csrow object Borislav Petkov
2019-05-08 12:45           ` Greg KH
2019-05-08 11:06         ` [PATCH 2/2] EDAC/sysfs: Drop device references properly Borislav Petkov
2019-05-08 12:47           ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).