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

iio: light: hid-sensor-als.c: 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
9ecdbed7 d8c9d23e

+6 -6
+6 -6
drivers/iio/light/hid-sensor-als.c
··· 263 263 struct iio_dev *indio_dev; 264 264 struct als_state *als_state; 265 265 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 266 - struct iio_chan_spec *channels; 267 266 268 267 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct als_state)); 269 268 if (!indio_dev) ··· 280 281 return ret; 281 282 } 282 283 283 - channels = kmemdup(als_channels, sizeof(als_channels), GFP_KERNEL); 284 - if (!channels) { 284 + indio_dev->channels = kmemdup(als_channels, 285 + sizeof(als_channels), GFP_KERNEL); 286 + if (!indio_dev->channels) { 285 287 dev_err(&pdev->dev, "failed to duplicate channels\n"); 286 288 return -ENOMEM; 287 289 } 288 290 289 - ret = als_parse_report(pdev, hsdev, channels, 290 - HID_USAGE_SENSOR_ALS, als_state); 291 + ret = als_parse_report(pdev, hsdev, 292 + (struct iio_chan_spec *)indio_dev->channels, 293 + HID_USAGE_SENSOR_ALS, als_state); 291 294 if (ret) { 292 295 dev_err(&pdev->dev, "failed to setup attributes\n"); 293 296 goto error_free_dev_mem; 294 297 } 295 298 296 - indio_dev->channels = channels; 297 299 indio_dev->num_channels = 298 300 ARRAY_SIZE(als_channels); 299 301 indio_dev->dev.parent = &pdev->dev;