iio: accel: hid-sensor-accel-3d: Fix memory leak in probe()
Subsystems (2)
PATCH 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.
Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.
---
Build-tested only.
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
@@ -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
PATCH 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.
Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.
---
Build-tested only.
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
@@ -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
PATCH 3/6 iio: light: hid-sensor-als.c: Fix memory leak in probe()
In reply to Fabio EstevamFrom: Fabio Estevam <[email protected]>
'channels' is allocated via kmemdup and it is never freed.
Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.
---
Build-tested only.
drivers/iio/light/hid-sensor-als.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/light/hid-sensor-als.c +6 -6
@@ -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
PATCH 4/6 iio: orientation: hid-sensor-incl-3d: Fix memory leak in probe()
In reply to Fabio EstevamFrom: Fabio Estevam <[email protected]>
'channels' is allocated via kmemdup and it is never freed.
Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.
---
Build-tested only.
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
@@ -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
PATCH 5/6 iio: orientation: hid-sensor-rotation: Fix memory leak in probe()
In reply to Fabio EstevamFrom: Fabio Estevam <[email protected]>
'channels' is allocated via kmemdup and it is never freed.
Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.
---
Build-tested only.
drivers/iio/orientation/hid-sensor-rotation.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/iio/orientation/hid-sensor-rotation.c +8 -7
@@ -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
PATCH 6/6 iio: pressure: hid-sensor-press: Fix memory leak in probe()
In reply to Fabio EstevamFrom: Fabio Estevam <[email protected]>
'channels' is allocated via kmemdup and it is never freed.
Use 'indio_dev->channels' directly instead, so that we avoid such memory leak problem.
---
Build-tested only.
drivers/iio/pressure/hid-sensor-press.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iio/pressure/hid-sensor-press.c +5 -5
@@ -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;
Signature · 1 line
1.9.1
Srinivas Pandruvada
maintainerQuoted 3 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
'channels' is allocated via kmemdup and it is never freed.
It is freed except when the parsing of hid report is failed, which is unlikely. So change the commit message.
Quoted 51 lines
Use '
indio_dev->channels' directly instead, so that we avoid such memory leak problem.Signed-off-by Fabio Estevam <[email protected]>---
Build-tested only.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@@ -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;