summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDinghao Liu <dinghao.liu@zju.edu.cn>2023-12-08 10:31:19 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-02-23 11:25:06 +0300
commitb90126c86d83912688501826643ea698f0df1728 (patch)
tree50b07f1e5d2856fbb8a9192bfe6e1ebcd7b1c665
parent1d8c67e94e9e977603473a543d4f322cf2c4aa01 (diff)
downloadlinux-b90126c86d83912688501826643ea698f0df1728.tar.xz
iio: core: fix memleak in iio_device_register_sysfs
commit 95a0d596bbd0552a78e13ced43f2be1038883c81 upstream. When iio_device_register_sysfs_group() fails, we should free iio_dev_opaque->chan_attr_group.attrs to prevent potential memleak. Fixes: 32f171724e5c ("iio: core: rework iio device group creation") Signed-off-by: Dinghao 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: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/iio/industrialio-core.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index d752e9c0499b..feec93adb065 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1577,10 +1577,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);