iio: imu: adis16400: fix memory leak
PATCH 1/1 iio: imu: adis16400: fix memory leak
In adis_update_scan_mode_burst, if adis->buffer allocation fails release the adis->xfer.
--- drivers/iio/imu/adis_buffer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/imu/adis_buffer.c +3 -1
@@ -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);
Signature · 1 line
2.17.1
Quoted 2 lines · Navid Emamdoost
[External]
Hey,
Thanks for this patch as well.
Comments inline here as well.
Quoted 14 lines
In
adis_update_scan_mode_burst, ifadis->bufferallocation fails release theadis->xfer.Signed-off-by Navid Emamdoost <[email protected]>--- drivers/iio/imu/adis_buffer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/imu/adis_buffer.c +0
-0
drivers/iio/imu/adis_buffer.c static int adis_update_scan_mode_burst(struct iio_dev · line 40
Quoted 7 lines
drivers/iio/imu/adis_buffer.c +2
-1@@ -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.
Quoted 5 lines
drivers/iio/imu/adis_buffer.c +1
-0return -ENOMEM ; + } tx = adis->buffer + burst_length;tx[0] =
ADIS_READ_REG(adis->burst->reg_cmd);
PATCH v2 1/1 iio: imu: adis16400: fix memory leak
In adis_update_scan_mode_burst, if adis->buffer allocation fails release the adis->xfer.
v2: set adis->xfer = NULL to avoid any potential double free.
--- drivers/iio/imu/adis_buffer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/imu/adis_buffer.c +4 -1
@@ -35,8 +35,11 @@ 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); + adis->xfer =NULL ;return -ENOMEM ; + } tx = adis->buffer + burst_length; tx[0 ] =ADIS_READ_REG (adis->burst->reg_cmd);
Signature · 1 line
2.17.1
Quoted 5 lines · Navid Emamdoost
In
adis_update_scan_mode_burst, ifadis->bufferallocation fails release theadis->xfer.v2: set
adis->xfer= NULL to avoid any potential double free.
Quoted 24 lines
Signed-off-by Navid Emamdoost <[email protected]>--- drivers/iio/imu/adis_buffer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/iio/imu/adis_buffer.c +4
-1@@ -35,8 +35,11 @@ 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); + adis->xfer =NULL ;return -ENOMEM ; + } tx = adis->buffer + burst_length;tx[0] =
ADIS_READ_REG(adis->burst->reg_cmd);
Quoted 8 lines · Alexandru
Quoted 5 lines · Navid Emamdoost
In
adis_update_scan_mode_burst, ifadis->bufferallocation fails release theadis->xfer.v2: set
adis->xfer= NULL to avoid any potential double free.Reviewed-by Alexandru Ardelean <[email protected]>
Applied to the fixes-togreg branch of iio.git.
Thanks,
Jonathan
Quoted 25 lines
Quoted 25 lines
Signed-off-by Navid Emamdoost <[email protected]>--- drivers/iio/imu/adis_buffer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/iio/imu/adis_buffer.c +4
-1@@ -35,8 +35,11 @@ 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); + adis->xfer =NULL ;return -ENOMEM ; + } tx = adis->buffer + burst_length;tx[0] =
ADIS_READ_REG(adis->burst->reg_cmd);