Commit 95a0d596 authored by Dinghao Liu's avatar Dinghao Liu Committed by Jonathan Cameron
Browse files

iio: core: fix memleak in iio_device_register_sysfs



When iio_device_register_sysfs_group() fails, we should
free iio_dev_opaque->chan_attr_group.attrs to prevent
potential memleak.

Fixes: 32f17172 ("iio: core: rework iio device group creation")
Signed-off-by: default avatarDinghao Liu <dinghao.liu@zju.edu.cn>
Link: https://lore.kernel.org/r/20231208073119.29283-1-dinghao.liu@zju.edu.cn


Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 6613476e
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1584,10 +1584,13 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
	ret = iio_device_register_sysfs_group(indio_dev,
					      &iio_dev_opaque->chan_attr_group);
	if (ret)
		goto error_clear_attrs;
		goto error_free_chan_attrs;

	return 0;

error_free_chan_attrs:
	kfree(iio_dev_opaque->chan_attr_group.attrs);
	iio_dev_opaque->chan_attr_group.attrs = NULL;
error_clear_attrs:
	iio_free_chan_devattr_list(&iio_dev_opaque->channel_attr_list);