aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorAlexey Khoroshilov <khoroshilov@ispras.ru>2012-08-08 05:58:00 -0400
committerJonathan Cameron <jic23@kernel.org>2012-08-16 15:24:33 -0400
commit1c795ebd00042b3a5c97e049fd1c08763714a7a8 (patch)
treeb54a55288bec44e39acdd6f6282f6b4d568afb23 /drivers/iio
parent8857df3aceb7a8eb7558059b7da109e41dd1fb95 (diff)
iio/adjd_s311: Fix potential memory leak in adjd_s311_update_scan_mode()
Do not leak memory by updating pointer with potentially NULL realloc return value. There is no need to preserve data in the buffer, so replace krealloc() by kfree()-kmalloc() pair. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru> Acked-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/light/adjd_s311.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/iio/light/adjd_s311.c b/drivers/iio/light/adjd_s311.c
index 1cbb449b319a..9a99f43094f0 100644
--- a/drivers/iio/light/adjd_s311.c
+++ b/drivers/iio/light/adjd_s311.c
@@ -271,9 +271,10 @@ static int adjd_s311_update_scan_mode(struct iio_dev *indio_dev,
271 const unsigned long *scan_mask) 271 const unsigned long *scan_mask)
272{ 272{
273 struct adjd_s311_data *data = iio_priv(indio_dev); 273 struct adjd_s311_data *data = iio_priv(indio_dev);
274 data->buffer = krealloc(data->buffer, indio_dev->scan_bytes, 274
275 GFP_KERNEL); 275 kfree(data->buffer);
276 if (!data->buffer) 276 data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
277 if (data->buffer == NULL)
277 return -ENOMEM; 278 return -ENOMEM;
278 279
279 return 0; 280 return 0;