* [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: Fix memory leak in probe()
@ 2015-05-12 15:40 Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 2/6] iio: gyro: hid-sensor-gyro-3d: " Fabio Estevam
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Fabio Estevam @ 2015-05-12 15:40 UTC (permalink / raw)
To: jic23; +Cc: srinivas.pandruvada, linux-iio, Fabio Estevam
'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.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Build-tested only.
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(-)
diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 2b4fad6..b933957 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -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;
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/6] iio: gyro: hid-sensor-gyro-3d: Fix memory leak in probe()
2015-05-12 15:40 [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: Fix memory leak in probe() Fabio Estevam
@ 2015-05-12 15:40 ` Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 3/6] iio: light: hid-sensor-als.c: " Fabio Estevam
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Fabio Estevam @ 2015-05-12 15:40 UTC (permalink / raw)
To: jic23; +Cc: srinivas.pandruvada, linux-iio, Fabio Estevam
'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.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Build-tested only.
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(-)
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index b5883b6..7b60b58 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -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;
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/6] iio: light: hid-sensor-als.c: Fix memory leak in probe()
2015-05-12 15:40 [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: Fix memory leak in probe() Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 2/6] iio: gyro: hid-sensor-gyro-3d: " Fabio Estevam
@ 2015-05-12 15:40 ` Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 4/6] iio: orientation: hid-sensor-incl-3d: " Fabio Estevam
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Fabio Estevam @ 2015-05-12 15:40 UTC (permalink / raw)
To: jic23; +Cc: srinivas.pandruvada, linux-iio, Fabio Estevam
'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.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Build-tested only.
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(-)
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 1609ecd..9d74364 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -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;
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 4/6] iio: orientation: hid-sensor-incl-3d: Fix memory leak in probe()
2015-05-12 15:40 [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: Fix memory leak in probe() Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 2/6] iio: gyro: hid-sensor-gyro-3d: " Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 3/6] iio: light: hid-sensor-als.c: " Fabio Estevam
@ 2015-05-12 15:40 ` Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 5/6] iio: orientation: hid-sensor-rotation: " Fabio Estevam
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Fabio Estevam @ 2015-05-12 15:40 UTC (permalink / raw)
To: jic23; +Cc: srinivas.pandruvada, linux-iio, Fabio Estevam
'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.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Build-tested only.
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(-)
diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c
index 5930fa3..2eb49a8 100644
--- a/drivers/iio/orientation/hid-sensor-incl-3d.c
+++ b/drivers/iio/orientation/hid-sensor-incl-3d.c
@@ -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;
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 5/6] iio: orientation: hid-sensor-rotation: Fix memory leak in probe()
2015-05-12 15:40 [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: Fix memory leak in probe() Fabio Estevam
` (2 preceding siblings ...)
2015-05-12 15:40 ` [PATCH v2 4/6] iio: orientation: hid-sensor-incl-3d: " Fabio Estevam
@ 2015-05-12 15:40 ` Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 6/6] iio: pressure: hid-sensor-press: " Fabio Estevam
2015-05-13 17:17 ` [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: " Srinivas Pandruvada
5 siblings, 0 replies; 7+ messages in thread
From: Fabio Estevam @ 2015-05-12 15:40 UTC (permalink / raw)
To: jic23; +Cc: srinivas.pandruvada, linux-iio, Fabio Estevam
'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.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Build-tested only.
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(-)
diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
index 4afb6c7..b6ee50f 100644
--- a/drivers/iio/orientation/hid-sensor-rotation.c
+++ b/drivers/iio/orientation/hid-sensor-rotation.c
@@ -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;
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 6/6] iio: pressure: hid-sensor-press: Fix memory leak in probe()
2015-05-12 15:40 [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: Fix memory leak in probe() Fabio Estevam
` (3 preceding siblings ...)
2015-05-12 15:40 ` [PATCH v2 5/6] iio: orientation: hid-sensor-rotation: " Fabio Estevam
@ 2015-05-12 15:40 ` Fabio Estevam
2015-05-13 17:17 ` [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: " Srinivas Pandruvada
5 siblings, 0 replies; 7+ messages in thread
From: Fabio Estevam @ 2015-05-12 15:40 UTC (permalink / raw)
To: jic23; +Cc: srinivas.pandruvada, linux-iio, Fabio Estevam
'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.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Build-tested only.
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 | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c
index 7bb8d4c..f1bcb89 100644
--- a/drivers/iio/pressure/hid-sensor-press.c
+++ b/drivers/iio/pressure/hid-sensor-press.c
@@ -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,
+ 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;
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: Fix memory leak in probe()
2015-05-12 15:40 [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: Fix memory leak in probe() Fabio Estevam
` (4 preceding siblings ...)
2015-05-12 15:40 ` [PATCH v2 6/6] iio: pressure: hid-sensor-press: " Fabio Estevam
@ 2015-05-13 17:17 ` Srinivas Pandruvada
5 siblings, 0 replies; 7+ messages in thread
From: Srinivas Pandruvada @ 2015-05-13 17:17 UTC (permalink / raw)
To: Fabio Estevam; +Cc: jic23, linux-iio
On Tue, 2015-05-12 at 12:40 -0300, Fabio Estevam wrote:
> '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.
>
Some minor comment
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---
> Build-tested only.
>
> 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(-)
>
> diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
> index 2b4fad6..b933957 100644
> --- a/drivers/iio/accel/hid-sensor-accel-3d.c
> +++ b/drivers/iio/accel/hid-sensor-accel-3d.c
> @@ -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);
You don't have to align HID_USAGE_SENSOR_ACCEL_3D to "struct iio..", but
to "(struct iio..)".
> 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;
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-05-13 17:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-12 15:40 [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: Fix memory leak in probe() Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 2/6] iio: gyro: hid-sensor-gyro-3d: " Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 3/6] iio: light: hid-sensor-als.c: " Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 4/6] iio: orientation: hid-sensor-incl-3d: " Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 5/6] iio: orientation: hid-sensor-rotation: " Fabio Estevam
2015-05-12 15:40 ` [PATCH v2 6/6] iio: pressure: hid-sensor-press: " Fabio Estevam
2015-05-13 17:17 ` [PATCH v2 1/6] iio: accel: hid-sensor-accel-3d: " Srinivas Pandruvada
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.