diff options
author | Yang Yingliang <[email protected]> | 2021-10-13 12:49:22 +0300 |
---|---|---|
committer | Jonathan Cameron <[email protected]> | 2021-10-17 15:24:18 +0100 |
commit | 09776d9374e635b1580b3736c19b95b788fbaa85 (patch) | |
tree | c28b48278b00b3ce45fb7ba6fa3b914cd47b9192 | |
parent | 9a2ff8009e53296e47de72d5af0bc31cd53274ff (diff) |
iio: buffer: Fix double-free in iio_buffers_alloc_sysfs_and_mask()
When __iio_buffer_alloc_sysfs_and_mask() failed, 'unwind_idx' should be
set to 'i - 1' to prevent double-free when cleanup resources.
BUG: KASAN: double-free or invalid-free in __iio_buffer_free_sysfs_and_mask+0x32/0xb0 [industrialio]
Call Trace:
kfree+0x117/0x4c0
__iio_buffer_free_sysfs_and_mask+0x32/0xb0 [industrialio]
iio_buffers_alloc_sysfs_and_mask+0x60d/0x1570 [industrialio]
__iio_device_register+0x483/0x1a30 [industrialio]
ina2xx_probe+0x625/0x980 [ina2xx_adc]
Reported-by: Hulk Robot <[email protected]>
Fixes: ee708e6baacd ("iio: buffer: introduce support for attaching more IIO buffers")
Signed-off-by: Yang Yingliang <[email protected]>
Reviewed-by: Alexandru Ardelean <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jonathan Cameron <[email protected]>
-rw-r--r-- | drivers/iio/industrialio-buffer.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index e2587237dbf9..ae0912a14578 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -1620,7 +1620,7 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev) buffer = iio_dev_opaque->attached_buffers[i]; ret = __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev, i); if (ret) { - unwind_idx = i; + unwind_idx = i - 1; goto error_unwind_sysfs_and_mask; } } |