Commit 84c65d80 authored by David Lechner's avatar David Lechner Committed by Jonathan Cameron

iio: buffer-dmaengine: fix releasing dma channel on error

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

Fixes: 2d6ca60f ("iio: Add a DMAengine framework based buffer")
Signed-off-by: default avatarDavid 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: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 90826e08
...@@ -237,7 +237,7 @@ static struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev, ...@@ -237,7 +237,7 @@ static struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev,
ret = dma_get_slave_caps(chan, &caps); ret = dma_get_slave_caps(chan, &caps);
if (ret < 0) if (ret < 0)
goto err_free; goto err_release;
/* Needs to be aligned to the maximum of the minimums */ /* Needs to be aligned to the maximum of the minimums */
if (caps.src_addr_widths) if (caps.src_addr_widths)
...@@ -263,6 +263,8 @@ static struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev, ...@@ -263,6 +263,8 @@ static struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev,
return &dmaengine_buffer->queue.buffer; return &dmaengine_buffer->queue.buffer;
err_release:
dma_release_channel(chan);
err_free: err_free:
kfree(dmaengine_buffer); kfree(dmaengine_buffer);
return ERR_PTR(ret); return ERR_PTR(ret);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment