]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: buffer-dmaengine: fix releasing dma channel on error
authorDavid Lechner <dlechner@baylibre.com>
Tue, 23 Jul 2024 16:32:21 +0000 (11:32 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Sep 2024 09:11:40 +0000 (11:11 +0200)
commit 84c65d8008764a8fb4e627ff02de01ec4245f2c4 upstream.

If dma_get_slave_caps() fails, we need to release the dma channel before
returning an error to avoid leaking the channel.

Fixes: 2d6ca60f3284 ("iio: Add a DMAengine framework based buffer")
Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20240723-iio-fix-dmaengine-free-on-error-v1-1-2c7cbc9b92ff@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>
drivers/iio/buffer/industrialio-buffer-dmaengine.c

index 0d53c0a07b0d6f82785bf0f0c6c98818221fcc83..db5dbd60cf6759551f0382bb01596d3ac569d171 100644 (file)
@@ -180,7 +180,7 @@ struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev,
 
        ret = dma_get_slave_caps(chan, &caps);
        if (ret < 0)
-               goto err_free;
+               goto err_release;
 
        /* Needs to be aligned to the maximum of the minimums */
        if (caps.src_addr_widths)
@@ -206,6 +206,8 @@ struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev,
 
        return &dmaengine_buffer->queue.buffer;
 
+err_release:
+       dma_release_channel(chan);
 err_free:
        kfree(dmaengine_buffer);
        return ERR_PTR(ret);