Skip to content

Commit bce6147

Browse files
dlechjic23
authored andcommitted
iio: triggered-buffer: prevent possible freeing of wrong buffer
Commit ee708e6 ("iio: buffer: introduce support for attaching more IIO buffers") introduced support for multiple buffers per indio_dev but left indio_dev->buffer for a few legacy use cases. In the case of the triggered buffer, iio_triggered_buffer_cleanup() still assumes that indio_dev->buffer points to the buffer allocated by iio_triggered_buffer_setup_ext(). However, since iio_triggered_buffer_setup_ext() now calls iio_device_attach_buffer() to attach the buffer, indio_dev->buffer will only point to the buffer allocated by iio_device_attach_buffer() if it the first buffer attached. This adds a check to make sure that no other buffer has been attached yet to ensure that indio_dev->buffer will be assigned when iio_device_attach_buffer() is called. As per discussion in the review thread, we may want to deal with multiple triggers per device, but this is a fix for the issue in the meantime and any such support would be unlikely to be suitable for a backport. Fixes: ee708e6 ("iio: buffer: introduce support for attaching more IIO buffers") Signed-off-by: David Lechner <[email protected]> Acked-by: Nuno Sa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent c3df0e2 commit bce6147

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/iio/buffer/industrialio-triggered-buffer.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,
4646
struct iio_buffer *buffer;
4747
int ret;
4848

49+
/*
50+
* iio_triggered_buffer_cleanup() assumes that the buffer allocated here
51+
* is assigned to indio_dev->buffer but this is only the case if this
52+
* function is the first caller to iio_device_attach_buffer(). If
53+
* indio_dev->buffer is already set then we can't proceed otherwise the
54+
* cleanup function will try to free a buffer that was not allocated here.
55+
*/
56+
if (indio_dev->buffer)
57+
return -EADDRINUSE;
58+
4959
buffer = iio_kfifo_allocate();
5060
if (!buffer) {
5161
ret = -ENOMEM;

0 commit comments

Comments
 (0)