Skip to content

Commit

Permalink
iio/adjd_s311: Fix potential memory leak in adjd_s311_update_scan_mode()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Alexey Khoroshilov authored and Jonathan Cameron committed Aug 16, 2012
1 parent 8857df3 commit 1c795eb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/iio/light/adjd_s311.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,10 @@ 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,
GFP_KERNEL);
if (!data->buffer)

kfree(data->buffer);
data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data->buffer == NULL)
return -ENOMEM;

return 0;
Expand Down

0 comments on commit 1c795eb

Please sign in to comment.