Merge tag 'x86-asm-2024-01-08' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
[linux-2.6-microblaze.git] / drivers / iio / buffer / industrialio-triggered-buffer.c
index c7671b1..c065159 100644 (file)
@@ -46,6 +46,16 @@ int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,
        struct iio_buffer *buffer;
        int ret;
 
+       /*
+        * iio_triggered_buffer_cleanup() assumes that the buffer allocated here
+        * is assigned to indio_dev->buffer but this is only the case if this
+        * function is the first caller to iio_device_attach_buffer(). If
+        * indio_dev->buffer is already set then we can't proceed otherwise the
+        * cleanup function will try to free a buffer that was not allocated here.
+        */
+       if (indio_dev->buffer)
+               return -EADDRINUSE;
+
        buffer = iio_kfifo_allocate();
        if (!buffer) {
                ret = -ENOMEM;