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

iio: orientation: hid-sensor-rotation: 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
2bd04628 32ee56e3

+8 -7
+8 -7
drivers/iio/orientation/hid-sensor-rotation.c
··· 222 222 struct iio_dev *indio_dev; 223 223 struct dev_rot_state *rot_state; 224 224 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 225 - struct iio_chan_spec *channels; 226 225 227 226 indio_dev = devm_iio_device_alloc(&pdev->dev, 228 227 sizeof(struct dev_rot_state)); ··· 242 243 return ret; 243 244 } 244 245 245 - channels = devm_kmemdup(&pdev->dev, dev_rot_channels, 246 - sizeof(dev_rot_channels), GFP_KERNEL); 247 - if (!channels) { 246 + indio_dev->channels = devm_kmemdup(&pdev->dev, dev_rot_channels, 247 + sizeof(dev_rot_channels), 248 + GFP_KERNEL); 249 + if (!indio_dev->channels) { 248 250 dev_err(&pdev->dev, "failed to duplicate channels\n"); 249 251 return -ENOMEM; 250 252 } 251 253 252 - ret = dev_rot_parse_report(pdev, hsdev, channels, 253 - HID_USAGE_SENSOR_DEVICE_ORIENTATION, rot_state); 254 + ret = dev_rot_parse_report(pdev, hsdev, 255 + (struct iio_chan_spec *)indio_dev->channels, 256 + HID_USAGE_SENSOR_DEVICE_ORIENTATION, 257 + rot_state); 254 258 if (ret) { 255 259 dev_err(&pdev->dev, "failed to setup attributes\n"); 256 260 return ret; 257 261 } 258 262 259 - indio_dev->channels = channels; 260 263 indio_dev->num_channels = ARRAY_SIZE(dev_rot_channels); 261 264 indio_dev->dev.parent = &pdev->dev; 262 265 indio_dev->info = &dev_rot_info;