iio: buffer: Fix memory leak in iio_buffer_register_legacy_sysfs_groups()
authorYang Yingliang <yangyingliang@huawei.com>
Wed, 13 Oct 2021 14:42:42 +0000 (22:42 +0800)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 17 Oct 2021 14:39:59 +0000 (15:39 +0100)
commit604faf9a2ecd1addcc0c10a47e5aaef3c4d4fd6b
treeac4dec4f561dd271c1d9891fd2422f61415839de
parent09776d9374e635b1580b3736c19b95b788fbaa85
iio: buffer: Fix memory leak in iio_buffer_register_legacy_sysfs_groups()

If the second iio_device_register_sysfs_group() fails,
'legacy_buffer_group.attrs' need be freed too or it will
cause memory leak:

unreferenced object 0xffff888003618280 (size 64):
  comm "xrun", pid 357, jiffies 4294907259 (age 22.296s)
  hex dump (first 32 bytes):
    80 f6 8c 03 80 88 ff ff 80 fb 8c 03 80 88 ff ff  ................
    00 f9 8c 03 80 88 ff ff 80 fc 8c 03 80 88 ff ff  ................
  backtrace:
    [<00000000076bfd43>] __kmalloc+0x1a3/0x2f0
    [<00000000c32e4886>] iio_buffers_alloc_sysfs_and_mask+0xc31/0x1290 [industrialio]

Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: d9a625744ed0 ("iio: core: merge buffer/ & scan_elements/ attributes")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20211013144242.1685060-1-yangyingliang@huawei.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/industrialio-buffer.c