Skip to content

Commit 95a0d59

Browse files
dinghaoliujic23
authored andcommitted
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: 32f1717 ("iio: core: rework iio device group creation") Signed-off-by: Dinghao Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 6613476 commit 95a0d59

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/iio/industrialio-core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1584,10 +1584,13 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev)
15841584
ret = iio_device_register_sysfs_group(indio_dev,
15851585
&iio_dev_opaque->chan_attr_group);
15861586
if (ret)
1587-
goto error_clear_attrs;
1587+
goto error_free_chan_attrs;
15881588

15891589
return 0;
15901590

1591+
error_free_chan_attrs:
1592+
kfree(iio_dev_opaque->chan_attr_group.attrs);
1593+
iio_dev_opaque->chan_attr_group.attrs = NULL;
15911594
error_clear_attrs:
15921595
iio_free_chan_devattr_list(&iio_dev_opaque->channel_attr_list);
15931596

0 commit comments

Comments
 (0)