Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c795ebd authored by Alexey Khoroshilov's avatar Alexey Khoroshilov Committed by Jonathan Cameron
Browse files

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: default avatarAlexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: default avatarPeter Meerwald <pmeerw@pmeerw.net>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 8857df3a
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -271,9 +271,10 @@ static int adjd_s311_update_scan_mode(struct iio_dev *indio_dev,
	const unsigned long *scan_mask)
	const unsigned long *scan_mask)
{
{
	struct adjd_s311_data *data = iio_priv(indio_dev);
	struct adjd_s311_data *data = iio_priv(indio_dev);
	data->buffer = krealloc(data->buffer, indio_dev->scan_bytes,

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


	return 0;
	return 0;