iio: imu: adis16400: release allocated memory on failure
PATCH 1/1 iio: imu: adis16400: release allocated memory on failure
In adis_update_scan_mode, if allocation for adis->buffer fails, previously allocated adis->xfer needs to be released.
--- drivers/iio/imu/adis_buffer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/imu/adis_buffer.c +3 -1
@@ -78,8 +78,10 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,return -ENOMEM ; adis->buffer =kcalloc (indio_dev->scan_bytes,2 ,GFP_KERNEL ); -if (!adis->buffer) +if (!adis->buffer) { +kfree (adis->xfer);return -ENOMEM ; + } rx = adis->buffer; tx = rx + scan_count;
Signature · 1 line
2.17.1
Quoted 2 lines · Navid Emamdoost
[External]
Hey,
Good catch.
One comment inline.
Quoted 14 lines
In
adis_update_scan_mode, if allocation foradis->bufferfails, previously allocatedadis->xferneeds to be released.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 int adis_update_scan_mode(struct iio_dev *indio_dev, · line 82
Quoted 6 lines
drivers/iio/imu/adis_buffer.c +2
-1@@ -78,8 +78,10 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,return -ENOMEM ; adis->buffer =kcalloc (indio_dev->scan_bytes,2 ,GFP_KERNEL ); -if (!adis->buffer) +if (!adis->buffer) { +kfree (adis->xfer);
Maybe also do "adis->xfer = NULL" here.
The idea is to make sure that the pointer is not double-free'd by some other function (i.e. adis_cleanup_buffer_and_trigger() or another adis_update_scan_mode() call).
Quoted 5 lines
drivers/iio/imu/adis_buffer.c +1
-0return -ENOMEM ; + } rx = adis->buffer; tx = rx + scan_count;
PATCH v2 1/1 iio: imu: adis16400: release allocated memory on failure
In adis_update_scan_mode, if allocation for adis->buffer fails, previously allocated adis->xfer needs to be released.
v2: added 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
@@ -78,8 +78,11 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,return -ENOMEM ; adis->buffer =kcalloc (indio_dev->scan_bytes,2 ,GFP_KERNEL ); -if (!adis->buffer) +if (!adis->buffer) { +kfree (adis->xfer); + adis->xfer =NULL ;return -ENOMEM ; + } rx = adis->buffer; tx = rx + scan_count;
Signature · 1 line
2.17.1
Quoted 4 lines · Navid Emamdoost
In
adis_update_scan_mode, if allocation foradis->bufferfails, previously allocatedadis->xferneeds to be released.v2: added
adis->xfer= NULL to avoid any potential double free.
Quoted 23 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@@ -78,8 +78,11 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,return -ENOMEM ; adis->buffer =kcalloc (indio_dev->scan_bytes,2 ,GFP_KERNEL ); -if (!adis->buffer) +if (!adis->buffer) { +kfree (adis->xfer); + adis->xfer =NULL ;return -ENOMEM ; + } rx = adis->buffer; tx = rx + scan_count;
Quoted 5 lines · Alexandru
Quoted 4 lines · Navid Emamdoost
In
adis_update_scan_mode, if allocation foradis->bufferfails, previously allocatedadis->xferneeds to be released.v2: added
adis->xfer= NULL to avoid any potential double free.
Version changes go below the --- so they don't get recorded in the git tree log when it's applied.
Quoted 2 lines
Reviewed-by Alexandru Ardelean <[email protected]>
Applied to the fixes-togreg branch of iio.git. Thanks,
Jonathan
Quoted 24 lines
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@@ -78,8 +78,11 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,return -ENOMEM ; adis->buffer =kcalloc (indio_dev->scan_bytes,2 ,GFP_KERNEL ); -if (!adis->buffer) +if (!adis->buffer) { +kfree (adis->xfer); + adis->xfer =NULL ;return -ENOMEM ; + } rx = adis->buffer; tx = rx + scan_count;