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

iio: orientation: hid-sensor-incl-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
32ee56e3 9ecdbed7

+7 -7
+7 -7
drivers/iio/orientation/hid-sensor-incl-3d.c
··· 315 315 struct iio_dev *indio_dev; 316 316 struct incl_3d_state *incl_state; 317 317 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 318 - struct iio_chan_spec *channels; 319 318 320 319 indio_dev = devm_iio_device_alloc(&pdev->dev, 321 320 sizeof(struct incl_3d_state)); ··· 335 336 return ret; 336 337 } 337 338 338 - channels = kmemdup(incl_3d_channels, sizeof(incl_3d_channels), 339 - GFP_KERNEL); 340 - if (!channels) { 339 + indio_dev->channels = kmemdup(incl_3d_channels, 340 + sizeof(incl_3d_channels), GFP_KERNEL); 341 + if (!indio_dev->channels) { 341 342 dev_err(&pdev->dev, "failed to duplicate channels\n"); 342 343 return -ENOMEM; 343 344 } 344 345 345 - ret = incl_3d_parse_report(pdev, hsdev, channels, 346 - HID_USAGE_SENSOR_INCLINOMETER_3D, incl_state); 346 + ret = incl_3d_parse_report(pdev, hsdev, 347 + (struct iio_chan_spec *)indio_dev->channels, 348 + HID_USAGE_SENSOR_INCLINOMETER_3D, 349 + incl_state); 347 350 if (ret) { 348 351 dev_err(&pdev->dev, "failed to setup attributes\n"); 349 352 goto error_free_dev_mem; 350 353 } 351 354 352 - indio_dev->channels = channels; 353 355 indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels); 354 356 indio_dev->dev.parent = &pdev->dev; 355 357 indio_dev->info = &incl_3d_info;