Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

'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>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Fabio Estevam and committed by
Jonathan Cameron
b136faff 01e537f7

+6 -7
+6 -7
drivers/iio/accel/hid-sensor-accel-3d.c
··· 299 299 struct iio_dev *indio_dev; 300 300 struct accel_3d_state *accel_state; 301 301 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 302 - struct iio_chan_spec *channels; 303 302 304 303 indio_dev = devm_iio_device_alloc(&pdev->dev, 305 304 sizeof(struct accel_3d_state)); ··· 319 320 return ret; 320 321 } 321 322 322 - channels = kmemdup(accel_3d_channels, sizeof(accel_3d_channels), 323 - GFP_KERNEL); 324 - if (!channels) { 323 + indio_dev->channels = kmemdup(accel_3d_channels, 324 + sizeof(accel_3d_channels), GFP_KERNEL); 325 + if (!indio_dev->channels) { 325 326 dev_err(&pdev->dev, "failed to duplicate channels\n"); 326 327 return -ENOMEM; 327 328 } 328 329 329 - ret = accel_3d_parse_report(pdev, hsdev, channels, 330 - HID_USAGE_SENSOR_ACCEL_3D, accel_state); 330 + ret = accel_3d_parse_report(pdev, hsdev, 331 + (struct iio_chan_spec *)indio_dev->channels, 332 + HID_USAGE_SENSOR_ACCEL_3D, accel_state); 331 333 if (ret) { 332 334 dev_err(&pdev->dev, "failed to setup attributes\n"); 333 335 goto error_free_dev_mem; 334 336 } 335 337 336 - indio_dev->channels = channels; 337 338 indio_dev->num_channels = ARRAY_SIZE(accel_3d_channels); 338 339 indio_dev->dev.parent = &pdev->dev; 339 340 indio_dev->info = &accel_3d_info;