From dfd4f6497614ccb34f822849dd2e1fd2c44de37f Mon Sep 17 00:00:00 2001 From: Pan Bian Date: Thu, 18 Apr 2019 11:02:56 +0800 Subject: [PATCH] iio: dummy_evgen: fix possible memleak in evgen init 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. Signed-off-by: Pan Bian Signed-off-by: Jonathan Cameron --- drivers/iio/dummy/iio_dummy_evgen.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/iio/dummy/iio_dummy_evgen.c b/drivers/iio/dummy/iio_dummy_evgen.c index efd0005f59b4..c6033e341963 100644 --- a/drivers/iio/dummy/iio_dummy_evgen.c +++ b/drivers/iio/dummy/iio_dummy_evgen.c @@ -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);