Skip to contentSkip to conversation

iio: accel: hid-sensor-accel-3d: Fix memory leak in probe()

PATCH Applied Fabio Estevam 3 participants 18 messages May 13, 2015 – May 17, 2015

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

PATCH v3 1/6 iio: accel: hid-sensor-accel-3d: Fix memory leak in probe()

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

---
Build-tested only.

Changes since v2:
- Properly align "accel_3d_parse_report(" in multiple lines Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/accel/hid-sensor-accel-3d.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/accel/hid-sensor-accel-3d.c +6 -7
index 2b4fad6..b933957 100644
@@ -299,7 +299,6 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct accel_3d_state *accel_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct accel_3d_state));
@@ -320,21 +319,21 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(accel_3d_channels, sizeof(accel_3d_channels),
-			   GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(accel_3d_channels,
+				      sizeof(accel_3d_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = accel_3d_parse_report(pdev, hsdev, channels,
-					HID_USAGE_SENSOR_ACCEL_3D, accel_state);
+	ret = accel_3d_parse_report(pdev, hsdev,
+				    (struct iio_chan_spec *)indio_dev->channels,
+				    HID_USAGE_SENSOR_ACCEL_3D, accel_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(accel_3d_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &accel_3d_info;
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 2/6 iio: gyro: hid-sensor-gyro-3d: Fix memory leak in probe()

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/gyro/hid-sensor-gyro-3d.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/gyro/hid-sensor-gyro-3d.c +6 -7
index b5883b6..7b60b58 100644
@@ -298,7 +298,6 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct gyro_3d_state *gyro_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*gyro_state));
 	if (!indio_dev)
@@ -317,21 +316,21 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(gyro_3d_channels, sizeof(gyro_3d_channels),
-			   GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(gyro_3d_channels,
+				      sizeof(gyro_3d_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = gyro_3d_parse_report(pdev, hsdev, channels,
-					HID_USAGE_SENSOR_GYRO_3D, gyro_state);
+	ret = gyro_3d_parse_report(pdev, hsdev,
+				   (struct iio_chan_spec *)indio_dev->channels,
+				   HID_USAGE_SENSOR_GYRO_3D, gyro_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &gyro_3d_info;
Signature · 1 line
1.9.1
maintainer Reviewed-by on v3 2/6
#2 lore raw

Re: [PATCH v3 2/6] iio: gyro: hid-sensor-gyro-3d: Fix memory leak in probe()

Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Quoted 52 lines

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/gyro/hid-sensor-gyro-3d.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/gyro/hid-sensor-gyro-3d.c +6 -7
index b5883b6..7b60b58 100644
@@ -298,7 +298,6 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct gyro_3d_state *gyro_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*gyro_state));
 	if (!indio_dev)
@@ -317,21 +316,21 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(gyro_3d_channels, sizeof(gyro_3d_channels),
-			   GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(gyro_3d_channels,
+				      sizeof(gyro_3d_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = gyro_3d_parse_report(pdev, hsdev, channels,
-					HID_USAGE_SENSOR_GYRO_3D, gyro_state);
+	ret = gyro_3d_parse_report(pdev, hsdev,
+				   (struct iio_chan_spec *)indio_dev->channels,
+				   HID_USAGE_SENSOR_GYRO_3D, gyro_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &gyro_3d_info;
maintainer Applied
#3 lore raw

Re: [PATCH v3 2/6] iio: gyro: hid-sensor-gyro-3d: Fix memory leak in probe()

Quoted 11 lines · Srinivas Pandruvada
Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Applied.

Quoted 59 lines
Quoted 42 lines

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/gyro/hid-sensor-gyro-3d.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/gyro/hid-sensor-gyro-3d.c +5 -6
index b5883b6..7b60b58 100644
@@ -298,7 +298,6 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct gyro_3d_state *gyro_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*gyro_state));
 	if (!indio_dev)
@@ -317,21 +316,21 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(gyro_3d_channels, sizeof(gyro_3d_channels),
-			   GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(gyro_3d_channels,
+				      sizeof(gyro_3d_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = gyro_3d_parse_report(pdev, hsdev, channels,
-					HID_USAGE_SENSOR_GYRO_3D, gyro_state);
+	ret = gyro_3d_parse_report(pdev, hsdev,
+				   (struct iio_chan_spec *)indio_dev->channels,

drivers/iio/gyro/hid-sensor-gyro-3d.c static int hid_gyro_3d_probe(struct platform_device *pdev) · line 336

Quoted 10 lines
drivers/iio/gyro/hid-sensor-gyro-3d.c +1 -1
+				   HID_USAGE_SENSOR_GYRO_3D, gyro_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &gyro_3d_info;

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

PATCH v3 3/6 iio: light: hid-sensor-als.c: Fix memory leak in probe()

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/light/hid-sensor-als.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/light/hid-sensor-als.c +6 -6
index 1609ecd..9d74364 100644
@@ -263,7 +263,6 @@ static int hid_als_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct als_state *als_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct als_state));
 	if (!indio_dev)
@@ -281,20 +280,21 @@ static int hid_als_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(als_channels, sizeof(als_channels), GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(als_channels,
+				      sizeof(als_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = als_parse_report(pdev, hsdev, channels,
-				HID_USAGE_SENSOR_ALS, als_state);
+	ret = als_parse_report(pdev, hsdev,
+			       (struct iio_chan_spec *)indio_dev->channels,
+			       HID_USAGE_SENSOR_ALS, als_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels =
 				ARRAY_SIZE(als_channels);
 	indio_dev->dev.parent = &pdev->dev;
Signature · 1 line
1.9.1
maintainer Reviewed-by on v3 3/6
#5 lore raw

Re: [PATCH v3 3/6] iio: light: hid-sensor-als.c: Fix memory leak in probe()

Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Quoted 52 lines

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/light/hid-sensor-als.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/light/hid-sensor-als.c +6 -6
index 1609ecd..9d74364 100644
@@ -263,7 +263,6 @@ static int hid_als_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct als_state *als_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct als_state));
 	if (!indio_dev)
@@ -281,20 +280,21 @@ static int hid_als_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(als_channels, sizeof(als_channels), GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(als_channels,
+				      sizeof(als_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = als_parse_report(pdev, hsdev, channels,
-				HID_USAGE_SENSOR_ALS, als_state);
+	ret = als_parse_report(pdev, hsdev,
+			       (struct iio_chan_spec *)indio_dev->channels,
+			       HID_USAGE_SENSOR_ALS, als_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels =
 				ARRAY_SIZE(als_channels);
 	indio_dev->dev.parent = &pdev->dev;
maintainer
#6 lore raw

Re: [PATCH v3 3/6] iio: light: hid-sensor-als.c: Fix memory leak in probe()

Quoted 11 lines · Srinivas Pandruvada
Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Applied to the togreg branch of iio.git - initially pushed out as testing. Thanks.

Quoted 54 lines
Quoted 52 lines

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/light/hid-sensor-als.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/light/hid-sensor-als.c +6 -6
index 1609ecd..9d74364 100644
@@ -263,7 +263,6 @@ static int hid_als_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct als_state *als_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct als_state));
 	if (!indio_dev)
@@ -281,20 +280,21 @@ static int hid_als_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(als_channels, sizeof(als_channels), GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(als_channels,
+				      sizeof(als_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = als_parse_report(pdev, hsdev, channels,
-				HID_USAGE_SENSOR_ALS, als_state);
+	ret = als_parse_report(pdev, hsdev,
+			       (struct iio_chan_spec *)indio_dev->channels,
+			       HID_USAGE_SENSOR_ALS, als_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels =
 				ARRAY_SIZE(als_channels);
 	indio_dev->dev.parent = &pdev->dev;
#7 lore raw

PATCH v3 4/6 iio: orientation: hid-sensor-incl-3d: Fix memory leak in probe()

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/orientation/hid-sensor-incl-3d.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/iio/orientation/hid-sensor-incl-3d.c +7 -7
index 5930fa3..2eb49a8 100644
@@ -315,7 +315,6 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct incl_3d_state *incl_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct incl_3d_state));
@@ -336,21 +335,22 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(incl_3d_channels, sizeof(incl_3d_channels),
-			   GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(incl_3d_channels,
+				      sizeof(incl_3d_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = incl_3d_parse_report(pdev, hsdev, channels,
-				HID_USAGE_SENSOR_INCLINOMETER_3D, incl_state);
+	ret = incl_3d_parse_report(pdev, hsdev,
+				   (struct iio_chan_spec *)indio_dev->channels,
+				   HID_USAGE_SENSOR_INCLINOMETER_3D,
+				   incl_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &incl_3d_info;
Signature · 1 line
1.9.1
maintainer Reviewed-by on v3 4/6
#8 lore raw

Re: [PATCH v3 4/6] iio: orientation: hid-sensor-incl-3d: Fix memory leak in probe()

Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Quoted 53 lines

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/orientation/hid-sensor-incl-3d.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/iio/orientation/hid-sensor-incl-3d.c +7 -7
index 5930fa3..2eb49a8 100644
@@ -315,7 +315,6 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct incl_3d_state *incl_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct incl_3d_state));
@@ -336,21 +335,22 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(incl_3d_channels, sizeof(incl_3d_channels),
-			   GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(incl_3d_channels,
+				      sizeof(incl_3d_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = incl_3d_parse_report(pdev, hsdev, channels,
-				HID_USAGE_SENSOR_INCLINOMETER_3D, incl_state);
+	ret = incl_3d_parse_report(pdev, hsdev,
+				   (struct iio_chan_spec *)indio_dev->channels,
+				   HID_USAGE_SENSOR_INCLINOMETER_3D,
+				   incl_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &incl_3d_info;
maintainer
#9 lore raw

Re: [PATCH v3 4/6] iio: orientation: hid-sensor-incl-3d: Fix memory leak in probe()

Quoted 11 lines · Srinivas Pandruvada
Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Applied to the togreg branch of iio.git - initially pushed out as testing. Thanks.

Quoted 60 lines
Quoted 43 lines

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/orientation/hid-sensor-incl-3d.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/iio/orientation/hid-sensor-incl-3d.c +6 -6
index 5930fa3..2eb49a8 100644
@@ -315,7 +315,6 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct incl_3d_state *incl_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct incl_3d_state));
@@ -336,21 +335,22 @@ static int hid_incl_3d_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(incl_3d_channels, sizeof(incl_3d_channels),
-			   GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(incl_3d_channels,
+				      sizeof(incl_3d_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = incl_3d_parse_report(pdev, hsdev, channels,
-				HID_USAGE_SENSOR_INCLINOMETER_3D, incl_state);
+	ret = incl_3d_parse_report(pdev, hsdev,
+				   (struct iio_chan_spec *)indio_dev->channels,
+				   HID_USAGE_SENSOR_INCLINOMETER_3D,

drivers/iio/orientation/hid-sensor-incl-3d.c static int hid_incl_3d_probe(struct platform_device *pdev) · line 356

Quoted 10 lines
drivers/iio/orientation/hid-sensor-incl-3d.c +1 -1
+				   incl_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &incl_3d_info;

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

PATCH v3 5/6 iio: orientation: hid-sensor-rotation: Fix memory leak in probe()

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/orientation/hid-sensor-rotation.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/iio/orientation/hid-sensor-rotation.c +8 -7
index 4afb6c7..b6ee50f 100644
@@ -222,7 +222,6 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct dev_rot_state *rot_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct dev_rot_state));
@@ -243,21 +242,23 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = devm_kmemdup(&pdev->dev, dev_rot_channels,
-					sizeof(dev_rot_channels), GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = devm_kmemdup(&pdev->dev, dev_rot_channels,
+					   sizeof(dev_rot_channels),
+					   GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = dev_rot_parse_report(pdev, hsdev, channels,
-			HID_USAGE_SENSOR_DEVICE_ORIENTATION, rot_state);
+	ret = dev_rot_parse_report(pdev, hsdev,
+				   (struct iio_chan_spec *)indio_dev->channels,
+				   HID_USAGE_SENSOR_DEVICE_ORIENTATION,
+				   rot_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		return ret;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(dev_rot_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &dev_rot_info;
Signature · 1 line
1.9.1
maintainer Reviewed-by on v3 5/6
#11 lore raw

Re: [PATCH v3 5/6] iio: orientation: hid-sensor-rotation: Fix memory leak in probe()

Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Quoted 54 lines

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/orientation/hid-sensor-rotation.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/iio/orientation/hid-sensor-rotation.c +8 -7
index 4afb6c7..b6ee50f 100644
@@ -222,7 +222,6 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct dev_rot_state *rot_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct dev_rot_state));
@@ -243,21 +242,23 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = devm_kmemdup(&pdev->dev, dev_rot_channels,
-					sizeof(dev_rot_channels), GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = devm_kmemdup(&pdev->dev, dev_rot_channels,
+					   sizeof(dev_rot_channels),
+					   GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = dev_rot_parse_report(pdev, hsdev, channels,
-			HID_USAGE_SENSOR_DEVICE_ORIENTATION, rot_state);
+	ret = dev_rot_parse_report(pdev, hsdev,
+				   (struct iio_chan_spec *)indio_dev->channels,
+				   HID_USAGE_SENSOR_DEVICE_ORIENTATION,
+				   rot_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		return ret;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(dev_rot_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &dev_rot_info;
maintainer
#12 lore raw

Re: [PATCH v3 5/6] iio: orientation: hid-sensor-rotation: Fix memory leak in probe()

Quoted 11 lines · Srinivas Pandruvada
Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Applied to the togreg branch of iio.git - initially pushed out as testing. Thanks.

Quoted 61 lines
Quoted 44 lines

---
Build-tested only.

Changes since v2:
- None
Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/orientation/hid-sensor-rotation.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/iio/orientation/hid-sensor-rotation.c +7 -6
index 4afb6c7..b6ee50f 100644
@@ -222,7 +222,6 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct dev_rot_state *rot_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct dev_rot_state));
@@ -243,21 +242,23 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = devm_kmemdup(&pdev->dev, dev_rot_channels,
-					sizeof(dev_rot_channels), GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = devm_kmemdup(&pdev->dev, dev_rot_channels,
+					   sizeof(dev_rot_channels),
+					   GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = dev_rot_parse_report(pdev, hsdev, channels,
-			HID_USAGE_SENSOR_DEVICE_ORIENTATION, rot_state);
+	ret = dev_rot_parse_report(pdev, hsdev,
+				   (struct iio_chan_spec *)indio_dev->channels,
+				   HID_USAGE_SENSOR_DEVICE_ORIENTATION,

drivers/iio/orientation/hid-sensor-rotation.c static int hid_dev_rot_probe(struct platform_device *pdev) · line 264

Quoted 10 lines
drivers/iio/orientation/hid-sensor-rotation.c +1 -1
+				   rot_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		return ret;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(dev_rot_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &dev_rot_info;

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

PATCH v3 6/6 iio: pressure: hid-sensor-press: Fix memory leak in probe()

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

---
Build-tested only.

Changes since v2:
- Properly align "press_parse_report(" in multiple lines Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/pressure/hid-sensor-press.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/pressure/hid-sensor-press.c +6 -6
index 7bb8d4c..5a10dbc 100644
@@ -262,7 +262,6 @@ static int hid_press_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct press_state *press_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 				sizeof(struct press_state));
@@ -282,20 +281,21 @@ static int hid_press_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(press_channels, sizeof(press_channels), GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(press_channels, sizeof(press_channels),
+				      GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = press_parse_report(pdev, hsdev, channels,
-				HID_USAGE_SENSOR_PRESSURE, press_state);
+	ret = press_parse_report(pdev, hsdev,
+				 (struct iio_chan_spec *)indio_dev->channels,
+				 HID_USAGE_SENSOR_PRESSURE, press_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels =
 				ARRAY_SIZE(press_channels);
 	indio_dev->dev.parent = &pdev->dev;
Signature · 1 line
1.9.1
maintainer Reviewed-by on v3 6/6
#14 lore raw

Re: [PATCH v3 6/6] iio: pressure: hid-sensor-press: Fix memory leak in probe()

Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Quoted 50 lines

---
Build-tested only.

Changes since v2:
- Properly align "press_parse_report(" in multiple lines Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/pressure/hid-sensor-press.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/pressure/hid-sensor-press.c +6 -6
index 7bb8d4c..5a10dbc 100644
@@ -262,7 +262,6 @@ static int hid_press_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct press_state *press_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 				sizeof(struct press_state));
@@ -282,20 +281,21 @@ static int hid_press_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(press_channels, sizeof(press_channels), GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(press_channels, sizeof(press_channels),
+				      GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = press_parse_report(pdev, hsdev, channels,
-				HID_USAGE_SENSOR_PRESSURE, press_state);
+	ret = press_parse_report(pdev, hsdev,
+				 (struct iio_chan_spec *)indio_dev->channels,
+				 HID_USAGE_SENSOR_PRESSURE, press_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels =
 				ARRAY_SIZE(press_channels);
 	indio_dev->dev.parent = &pdev->dev;
maintainer
#15 lore raw

Re: [PATCH v3 6/6] iio: pressure: hid-sensor-press: Fix memory leak in probe()

Quoted 11 lines · Srinivas Pandruvada
Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Applied to the togreg branch of iio.git - initially pushed out as testing. Thanks.

Quoted 52 lines
Quoted 50 lines

---
Build-tested only.

Changes since v2:
- Properly align "press_parse_report(" in multiple lines Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/pressure/hid-sensor-press.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/pressure/hid-sensor-press.c +6 -6
index 7bb8d4c..5a10dbc 100644
@@ -262,7 +262,6 @@ static int hid_press_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct press_state *press_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 				sizeof(struct press_state));
@@ -282,20 +281,21 @@ static int hid_press_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(press_channels, sizeof(press_channels), GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(press_channels, sizeof(press_channels),
+				      GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = press_parse_report(pdev, hsdev, channels,
-				HID_USAGE_SENSOR_PRESSURE, press_state);
+	ret = press_parse_report(pdev, hsdev,
+				 (struct iio_chan_spec *)indio_dev->channels,
+				 HID_USAGE_SENSOR_PRESSURE, press_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels =
 				ARRAY_SIZE(press_channels);
 	indio_dev->dev.parent = &pdev->dev;
maintainer Reviewed-by on v3 1/6
#16 lore raw
In reply to Fabio Estevam
Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Quoted 52 lines

---
Build-tested only.

Changes since v2:
- Properly align "accel_3d_parse_report(" in multiple lines Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/accel/hid-sensor-accel-3d.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/accel/hid-sensor-accel-3d.c +6 -7
index 2b4fad6..b933957 100644
@@ -299,7 +299,6 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct accel_3d_state *accel_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct accel_3d_state));
@@ -320,21 +319,21 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(accel_3d_channels, sizeof(accel_3d_channels),
-			   GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(accel_3d_channels,
+				      sizeof(accel_3d_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = accel_3d_parse_report(pdev, hsdev, channels,
-					HID_USAGE_SENSOR_ACCEL_3D, accel_state);
+	ret = accel_3d_parse_report(pdev, hsdev,
+				    (struct iio_chan_spec *)indio_dev->channels,
+				    HID_USAGE_SENSOR_ACCEL_3D, accel_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(accel_3d_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &accel_3d_info;
maintainer Applied
#17 lore raw
Quoted 11 lines · Srinivas Pandruvada
Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

'channels' is allocated via kmemdup and it is never freed in the subsequent error paths.

Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.

Applied to the togreg branch of iio.git

Thanks,

Quoted 59 lines
Quoted 42 lines

---
Build-tested only.

Changes since v2:
- Properly align "accel_3d_parse_report(" in multiple lines Changes since v1:
- Make clear in the commit log that the proble only occurs in the error paths

 drivers/iio/accel/hid-sensor-accel-3d.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/accel/hid-sensor-accel-3d.c +5 -6
index 2b4fad6..b933957 100644
@@ -299,7 +299,6 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 	struct iio_dev *indio_dev;
 	struct accel_3d_state *accel_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
-	struct iio_chan_spec *channels;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev,
 					  sizeof(struct accel_3d_state));
@@ -320,21 +319,21 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	channels = kmemdup(accel_3d_channels, sizeof(accel_3d_channels),
-			   GFP_KERNEL);
-	if (!channels) {
+	indio_dev->channels = kmemdup(accel_3d_channels,
+				      sizeof(accel_3d_channels), GFP_KERNEL);
+	if (!indio_dev->channels) {
 		dev_err(&pdev->dev, "failed to duplicate channels\n");
 		return -ENOMEM;
 	}
 
-	ret = accel_3d_parse_report(pdev, hsdev, channels,
-					HID_USAGE_SENSOR_ACCEL_3D, accel_state);
+	ret = accel_3d_parse_report(pdev, hsdev,
+				    (struct iio_chan_spec *)indio_dev->channels,

drivers/iio/accel/hid-sensor-accel-3d.c static int hid_accel_3d_probe(struct platform_device *pdev) · line 339

Quoted 10 lines
drivers/iio/accel/hid-sensor-accel-3d.c +1 -1
+				    HID_USAGE_SENSOR_ACCEL_3D, accel_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		goto error_free_dev_mem;
 	}
 
-	indio_dev->channels = channels;
 	indio_dev->num_channels = ARRAY_SIZE(accel_3d_channels);
 	indio_dev->dev.parent = &pdev->dev;
 	indio_dev->info = &accel_3d_info;

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html