Skip to content

Commit 86fdd15

Browse files
henryZejic23
authored andcommitted
iio: fix memory leak in iio_device_register_eventset()
When iio_device_register_sysfs_group() returns failed, iio_device_register_eventset() needs to free attrs array. Otherwise, kmemleak would scan & report memory leak as below: unreferenced object 0xffff88810a1cc3c0 (size 32): comm "100-i2c-vcnl302", pid 728, jiffies 4295052307 (age 156.027s) backtrace: __kmalloc+0x46/0x1b0 iio_device_register_eventset at drivers/iio/industrialio-event.c:541 __iio_device_register at drivers/iio/industrialio-core.c:1959 __devm_iio_device_register at drivers/iio/industrialio-core.c:2040 Fixes: 32f1717 ("iio: core: rework iio device group creation") Signed-off-by: Zeng Heng <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 398e347 commit 86fdd15

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/iio/industrialio-event.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,14 +556,16 @@ int iio_device_register_eventset(struct iio_dev *indio_dev)
556556

557557
ret = iio_device_register_sysfs_group(indio_dev, &ev_int->group);
558558
if (ret)
559-
goto error_free_setup_event_lines;
559+
goto error_free_group_attrs;
560560

561561
ev_int->ioctl_handler.ioctl = iio_event_ioctl;
562562
iio_device_ioctl_handler_register(&iio_dev_opaque->indio_dev,
563563
&ev_int->ioctl_handler);
564564

565565
return 0;
566566

567+
error_free_group_attrs:
568+
kfree(ev_int->group.attrs);
567569
error_free_setup_event_lines:
568570
iio_free_chan_devattr_list(&ev_int->dev_attr_list);
569571
kfree(ev_int);

0 commit comments

Comments
 (0)