linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio/adjd_s311: Fix potential memory leak in adjd_s311_update_scan_mode()
@ 2012-08-08  6:36 Alexey Khoroshilov
  2012-08-08  7:17 ` Peter Meerwald
  0 siblings, 1 reply; 6+ messages in thread
From: Alexey Khoroshilov @ 2012-08-08  6:36 UTC (permalink / raw)
  To: Peter Meerwald
  Cc: Alexey Khoroshilov, Jonathan Cameron, linux-iio, linux-kernel,
	ldv-project

Do not leak memory by updating pointer with potentially
NULL realloc return value.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/iio/light/adjd_s311.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/light/adjd_s311.c b/drivers/iio/light/adjd_s311.c
index 1cbb449..0adda5b 100644
--- a/drivers/iio/light/adjd_s311.c
+++ b/drivers/iio/light/adjd_s311.c
@@ -271,12 +271,18 @@ static int adjd_s311_update_scan_mode(struct iio_dev *indio_dev,
 	const unsigned long *scan_mask)
 {
 	struct adjd_s311_data *data = iio_priv(indio_dev);
-	data->buffer = krealloc(data->buffer, indio_dev->scan_bytes,
+	u16 *new_buffer;
+	int ret = 0;
+
+	new_buffer = krealloc(data->buffer, indio_dev->scan_bytes,
 				GFP_KERNEL);
-	if (!data->buffer)
-		return -ENOMEM;
+	if (new_buffer == NULL) {
+		kfree(data->buffer);
+		ret = -ENOMEM;
+	}
+	data->buffer = new_buffer;
 
-	return 0;
+	return ret;
 }
 
 static const struct iio_info adjd_s311_info = {
-- 
1.7.9.5

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

end of thread, other threads:[~2012-08-08 11:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-08  6:36 [PATCH] iio/adjd_s311: Fix potential memory leak in adjd_s311_update_scan_mode() Alexey Khoroshilov
2012-08-08  7:17 ` Peter Meerwald
2012-08-08  7:37   ` Lars-Peter Clausen
2012-08-08  9:01   ` Alexey Khoroshilov
2012-08-08  9:58   ` [PATCH v2] " Alexey Khoroshilov
2012-08-08 11:05     ` Peter Meerwald

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).