linux-stable/drivers/iio/buffer
David Lechner ae0faa924d iio: triggered-buffer: prevent possible freeing of wrong buffer
commit bce61476dc upstream.

Commit ee708e6baa ("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: ee708e6baa ("iio: buffer: introduce support for attaching more IIO buffers")
Signed-off-by: David Lechner <dlechner@baylibre.com>
Acked-by: Nuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20231031210521.1661552-1-dlechner@baylibre.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-01-01 12:42:38 +00:00
..
Kconfig iio: buffer: Kconfig: add title for IIO_TRIGGERED_BUFFER symbol 2020-09-29 17:27:08 +01:00
Makefile iio: Add hardware consumer buffer support 2018-01-10 10:30:05 +00:00
industrialio-buffer-cb.c iio: buffer: Return error if no callback is given 2020-12-03 19:32:40 +00:00
industrialio-buffer-dma.c iio: dma-buffer: Cleanup buffer.h/buffer_impl.h includes 2020-04-19 16:56:31 +01:00
industrialio-buffer-dmaengine.c iio: Don't silently expect attribute types 2022-11-23 19:44:04 +00:00
industrialio-hw-consumer.c iio: hw_consumer: Use struct_size() helper in kzalloc() 2022-01-23 18:03:37 +00:00
industrialio-triggered-buffer.c iio: triggered-buffer: prevent possible freeing of wrong buffer 2024-01-01 12:42:38 +00:00
kfifo_buf.c iio: Don't silently expect attribute types 2022-11-23 19:44:04 +00:00