diff options
author | Fabio Estevam <fabio.estevam@freescale.com> | 2015-05-07 19:32:04 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2015-05-12 15:01:13 -0400 |
commit | f0828ba96d02d4d4b197c531b34c662ee3c928df (patch) | |
tree | d722023606d70fd61f4af731d8069d30affcdc8b /drivers/iio | |
parent | f29b212edb9e253cafcb4a2ab7842a890989f1a5 (diff) |
iio: light: hid-sensor-prox: Fix memory leak in probe()
'channels' is allocated via kmemdup and it is never freed.
Use 'indio_dev->channels' directly instead, so that we avoid such
memory leak problem.
Reported-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/light/hid-sensor-prox.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c index 88f21bbe947c..36a2de35e525 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c | |||
@@ -250,7 +250,6 @@ static int hid_prox_probe(struct platform_device *pdev) | |||
250 | struct iio_dev *indio_dev; | 250 | struct iio_dev *indio_dev; |
251 | struct prox_state *prox_state; | 251 | struct prox_state *prox_state; |
252 | struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; | 252 | struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; |
253 | struct iio_chan_spec *channels; | ||
254 | 253 | ||
255 | indio_dev = devm_iio_device_alloc(&pdev->dev, | 254 | indio_dev = devm_iio_device_alloc(&pdev->dev, |
256 | sizeof(struct prox_state)); | 255 | sizeof(struct prox_state)); |
@@ -269,20 +268,21 @@ static int hid_prox_probe(struct platform_device *pdev) | |||
269 | return ret; | 268 | return ret; |
270 | } | 269 | } |
271 | 270 | ||
272 | channels = kmemdup(prox_channels, sizeof(prox_channels), GFP_KERNEL); | 271 | indio_dev->channels = kmemdup(prox_channels, sizeof(prox_channels), |
273 | if (!channels) { | 272 | GFP_KERNEL); |
273 | if (!indio_dev->channels) { | ||
274 | dev_err(&pdev->dev, "failed to duplicate channels\n"); | 274 | dev_err(&pdev->dev, "failed to duplicate channels\n"); |
275 | return -ENOMEM; | 275 | return -ENOMEM; |
276 | } | 276 | } |
277 | 277 | ||
278 | ret = prox_parse_report(pdev, hsdev, channels, | 278 | ret = prox_parse_report(pdev, hsdev, |
279 | (struct iio_chan_spec *)indio_dev->channels, | ||
279 | HID_USAGE_SENSOR_PROX, prox_state); | 280 | HID_USAGE_SENSOR_PROX, prox_state); |
280 | if (ret) { | 281 | if (ret) { |
281 | dev_err(&pdev->dev, "failed to setup attributes\n"); | 282 | dev_err(&pdev->dev, "failed to setup attributes\n"); |
282 | goto error_free_dev_mem; | 283 | goto error_free_dev_mem; |
283 | } | 284 | } |
284 | 285 | ||
285 | indio_dev->channels = channels; | ||
286 | indio_dev->num_channels = | 286 | indio_dev->num_channels = |
287 | ARRAY_SIZE(prox_channels); | 287 | ARRAY_SIZE(prox_channels); |
288 | indio_dev->dev.parent = &pdev->dev; | 288 | indio_dev->dev.parent = &pdev->dev; |