iio: imu: adis16400: fix memory leak
diff mbox series

Message ID 20190918170306.4779-1-navid.emamdoost@gmail.com
State Superseded
Headers show
Series
  • iio: imu: adis16400: fix memory leak
Related show

Commit Message

Navid Emamdoost Sept. 18, 2019, 5:03 p.m. UTC
In adis_update_scan_mode_burst, if adis->buffer allocation fails release
the adis->xfer.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/iio/imu/adis_buffer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Alexandru Ardelean Sept. 19, 2019, 6:52 a.m. UTC | #1
On Wed, 2019-09-18 at 12:03 -0500, Navid Emamdoost wrote:
> [External]
> 

Hey,

Thanks for this patch as well.
Comments inline here as well.

> In adis_update_scan_mode_burst, if adis->buffer allocation fails release
> the adis->xfer.
> 
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>  drivers/iio/imu/adis_buffer.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/imu/adis_buffer.c
> b/drivers/iio/imu/adis_buffer.c
> index 9ac8356d9a95..1dbe25572a39 100644
> --- a/drivers/iio/imu/adis_buffer.c
> +++ b/drivers/iio/imu/adis_buffer.c
> @@ -35,8 +35,10 @@ static int adis_update_scan_mode_burst(struct iio_dev
> *indio_dev,
>  		return -ENOMEM;
>  
>  	adis->buffer = kzalloc(burst_length + sizeof(u16), GFP_KERNEL);
> -	if (!adis->buffer)
> +	if (!adis->buffer) {
> +		kfree(adis->xfer);

Same as the other patch: it would be a good idea to do "adis->xfer = NULL"
here.

>  		return -ENOMEM;
> +	}
>  
>  	tx = adis->buffer + burst_length;
>  	tx[0] = ADIS_READ_REG(adis->burst->reg_cmd);

Patch
diff mbox series

diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c
index 9ac8356d9a95..1dbe25572a39 100644
--- a/drivers/iio/imu/adis_buffer.c
+++ b/drivers/iio/imu/adis_buffer.c
@@ -35,8 +35,10 @@  static int adis_update_scan_mode_burst(struct iio_dev *indio_dev,
 		return -ENOMEM;
 
 	adis->buffer = kzalloc(burst_length + sizeof(u16), GFP_KERNEL);
-	if (!adis->buffer)
+	if (!adis->buffer) {
+		kfree(adis->xfer);
 		return -ENOMEM;
+	}
 
 	tx = adis->buffer + burst_length;
 	tx[0] = ADIS_READ_REG(adis->burst->reg_cmd);