Skip to contentSkip to conversation

iio: dummy_evgen: fix possible memleak in evgen init

PATCH Pan Bian 2 participants 2 messages Apr 18, 2019 – Apr 22, 2019 IIO

lore
Share & tools
lore

Pan Bian

author
#0 lore raw

The memory allocated in the function iio_dummy_evgen_create is not released if it fails to add the evgen device to device hierarchy. This may result in a memory leak bug.

---
 drivers/iio/dummy/iio_dummy_evgen.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/dummy/iio_dummy_evgen.c +4 -1
index efd0005..f96c0a3 100644
@@ -196,7 +196,10 @@ static __init int iio_dummy_evgen_init(void)
 		return ret;
 	device_initialize(&iio_evgen_dev);
 	dev_set_name(&iio_evgen_dev, "iio_evgen");
-	return device_add(&iio_evgen_dev);
+	ret = device_add(&iio_evgen_dev);
+	if (ret)
+		put_device(&iio_evgen_dev);
+	return ret;
 }
 module_init(iio_dummy_evgen_init);
 
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 5 lines · On Thu, 18 Apr 2019 11:02:56 +0800 Pan Bian <[email protected]> wrote:

The memory allocated in the function iio_dummy_evgen_create is not released if it fails to add the evgen device to device hierarchy. This may result in a memory leak bug.

Hi. Not sure why the patch doesn't have the standard [PATCH] prefix in the title.

This issue has been there a long time, but as the driver is only a testing stub I'm not going to add a fixes tag or mark it for stable. That would just be noise I think.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 20 lines
---
 drivers/iio/dummy/iio_dummy_evgen.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/dummy/iio_dummy_evgen.c +4 -1
index efd0005..f96c0a3 100644
@@ -196,7 +196,10 @@ static __init int iio_dummy_evgen_init(void)
 		return ret;
 	device_initialize(&iio_evgen_dev);
 	dev_set_name(&iio_evgen_dev, "iio_evgen");
-	return device_add(&iio_evgen_dev);
+	ret = device_add(&iio_evgen_dev);
+	if (ret)
+		put_device(&iio_evgen_dev);
+	return ret;
 }
 module_init(iio_dummy_evgen_init);