Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: buffer-dmaengine: fix releasing dma channel on error
@ 2024-07-23 16:32 David Lechner
  2024-07-27 13:55 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: David Lechner @ 2024-07-23 16:32 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: David Lechner, Lars-Peter Clausen, linux-iio, linux-kernel

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>
---
 drivers/iio/buffer/industrialio-buffer-dmaengine.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
index 12aa1412dfa0..426cc614587a 100644
--- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
+++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
@@ -237,7 +237,7 @@ static 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)
@@ -263,6 +263,8 @@ static 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);

---
base-commit: 472438c7e0e2261c6737a8321f46ef176eef1c8f
change-id: 20240723-iio-fix-dmaengine-free-on-error-6e6e8b4dd058

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: buffer-dmaengine: fix releasing dma channel on error
  2024-07-23 16:32 [PATCH] iio: buffer-dmaengine: fix releasing dma channel on error David Lechner
@ 2024-07-27 13:55 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2024-07-27 13:55 UTC (permalink / raw)
  To: David Lechner; +Cc: Lars-Peter Clausen, linux-iio, linux-kernel

On Tue, 23 Jul 2024 11:32:21 -0500
David Lechner <dlechner@baylibre.com> wrote:

> 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>
Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

J
> ---
>  drivers/iio/buffer/industrialio-buffer-dmaengine.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> index 12aa1412dfa0..426cc614587a 100644
> --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> @@ -237,7 +237,7 @@ static 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)
> @@ -263,6 +263,8 @@ static 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);
> 
> ---
> base-commit: 472438c7e0e2261c6737a8321f46ef176eef1c8f
> change-id: 20240723-iio-fix-dmaengine-free-on-error-6e6e8b4dd058


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-27 13:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-23 16:32 [PATCH] iio: buffer-dmaengine: fix releasing dma channel on error David Lechner
2024-07-27 13:55 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox