Skip to contentSkip to conversation

iio: imu: adis16400: fix memory leak

PATCH Superseded Navid Emamdoost 3 participants 5 messages Sep 18, 2019 – Sep 21, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
index 9ac8356d9a95..1dbe25572a39 100644
@@ -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
#1 lore raw
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, 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 +0 -0
index 9ac8356d9a95..1dbe25572a39 100644

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 -0
 		return -ENOMEM;
+	}
 
 	tx = adis->buffer + burst_length;

tx[0] = ADIS_READ_REG(adis->burst->reg_cmd);

#2 lore raw

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
index 9ac8356d9a95..78fe83c1f4fe 100644
@@ -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
Reviewed-by on v2 1/1
#3 lore raw
Quoted 5 lines · Navid Emamdoost

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.

Quoted 24 lines
---
 drivers/iio/imu/adis_buffer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/imu/adis_buffer.c +4 -1
index 9ac8356d9a95..78fe83c1f4fe 100644
@@ -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);

maintainer Applied
#4 lore raw
Quoted 8 lines · Alexandru
Quoted 5 lines · Navid Emamdoost

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.

Applied to the fixes-togreg branch of iio.git.

Thanks,

Jonathan

Quoted 25 lines
Quoted 25 lines
---
 drivers/iio/imu/adis_buffer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/imu/adis_buffer.c +4 -1
index 9ac8356d9a95..78fe83c1f4fe 100644
@@ -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);