* [PATCH] dmaengine: nbpfaxi: Add missing check after DMA map
@ 2025-07-07 7:57 Thomas Fourier
2025-07-23 12:06 ` Vinod Koul
2025-07-23 12:29 ` Vinod Koul
0 siblings, 2 replies; 4+ messages in thread
From: Thomas Fourier @ 2025-07-07 7:57 UTC (permalink / raw)
Cc: Thomas Fourier, Vinod Koul, Guennadi Liakhovetski, dmaengine,
linux-kernel
The DMA map functions can fail and should be tested for errors.
If the mapping fails, unmap and return an error.
Fixes: b45b262cefd5 ("dmaengine: add a driver for AMBA AXI NBPF DMAC IP cores")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
drivers/dma/nbpfaxi.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/dma/nbpfaxi.c b/drivers/dma/nbpfaxi.c
index 0d6324c4e2be..0b75bb122898 100644
--- a/drivers/dma/nbpfaxi.c
+++ b/drivers/dma/nbpfaxi.c
@@ -711,6 +711,9 @@ static int nbpf_desc_page_alloc(struct nbpf_channel *chan)
list_add_tail(&ldesc->node, &lhead);
ldesc->hwdesc_dma_addr = dma_map_single(dchan->device->dev,
hwdesc, sizeof(*hwdesc), DMA_TO_DEVICE);
+ if (dma_mapping_error(dchan->device->dev,
+ ldesc->hwdesc_dma_addr))
+ goto unmap_error;
dev_dbg(dev, "%s(): mapped 0x%p to %pad\n", __func__,
hwdesc, &ldesc->hwdesc_dma_addr);
@@ -737,6 +740,16 @@ static int nbpf_desc_page_alloc(struct nbpf_channel *chan)
spin_unlock_irq(&chan->lock);
return ARRAY_SIZE(dpage->desc);
+
+unmap_error:
+ while (i--) {
+ ldesc--; hwdesc--;
+
+ dma_unmap_single(dchan->device->dev, ldesc->hwdesc_dma_addr,
+ sizeof(hwdesc), DMA_TO_DEVICE);
+ }
+
+ return -ENOMEM;
}
static void nbpf_desc_put(struct nbpf_desc *desc)
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] dmaengine: nbpfaxi: Add missing check after DMA map
2025-07-07 7:57 [PATCH] dmaengine: nbpfaxi: Add missing check after DMA map Thomas Fourier
@ 2025-07-23 12:06 ` Vinod Koul
2025-07-23 12:10 ` Vinod Koul
2025-07-23 12:29 ` Vinod Koul
1 sibling, 1 reply; 4+ messages in thread
From: Vinod Koul @ 2025-07-23 12:06 UTC (permalink / raw)
To: Thomas Fourier; +Cc: Guennadi Liakhovetski, dmaengine, linux-kernel
On 07-07-25, 09:57, Thomas Fourier wrote:
> The DMA map functions can fail and should be tested for errors.
> If the mapping fails, unmap and return an error.
Pls change this to dmaengine: xxx that is the subsystem name as show in
the Fixes tag that you picked up below
Meanwhile this does not apply for me, pls rebase
>
> Fixes: b45b262cefd5 ("dmaengine: add a driver for AMBA AXI NBPF DMAC IP cores")
> Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
> ---
> drivers/dma/nbpfaxi.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/dma/nbpfaxi.c b/drivers/dma/nbpfaxi.c
> index 0d6324c4e2be..0b75bb122898 100644
> --- a/drivers/dma/nbpfaxi.c
> +++ b/drivers/dma/nbpfaxi.c
> @@ -711,6 +711,9 @@ static int nbpf_desc_page_alloc(struct nbpf_channel *chan)
> list_add_tail(&ldesc->node, &lhead);
> ldesc->hwdesc_dma_addr = dma_map_single(dchan->device->dev,
> hwdesc, sizeof(*hwdesc), DMA_TO_DEVICE);
> + if (dma_mapping_error(dchan->device->dev,
> + ldesc->hwdesc_dma_addr))
> + goto unmap_error;
>
> dev_dbg(dev, "%s(): mapped 0x%p to %pad\n", __func__,
> hwdesc, &ldesc->hwdesc_dma_addr);
> @@ -737,6 +740,16 @@ static int nbpf_desc_page_alloc(struct nbpf_channel *chan)
> spin_unlock_irq(&chan->lock);
>
> return ARRAY_SIZE(dpage->desc);
> +
> +unmap_error:
> + while (i--) {
> + ldesc--; hwdesc--;
> +
> + dma_unmap_single(dchan->device->dev, ldesc->hwdesc_dma_addr,
> + sizeof(hwdesc), DMA_TO_DEVICE);
> + }
> +
> + return -ENOMEM;
> }
>
> static void nbpf_desc_put(struct nbpf_desc *desc)
> --
> 2.43.0
--
~Vinod
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] dmaengine: nbpfaxi: Add missing check after DMA map
2025-07-23 12:06 ` Vinod Koul
@ 2025-07-23 12:10 ` Vinod Koul
0 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2025-07-23 12:10 UTC (permalink / raw)
To: Thomas Fourier; +Cc: Guennadi Liakhovetski, dmaengine, linux-kernel
On 23-07-25, 17:36, Vinod Koul wrote:
> On 07-07-25, 09:57, Thomas Fourier wrote:
> > The DMA map functions can fail and should be tested for errors.
> > If the mapping fails, unmap and return an error.
>
> Pls change this to dmaengine: xxx that is the subsystem name as show in
> the Fixes tag that you picked up below
Ignore this one pls, that was for another patch of your which I fixed up
while applying
--
~Vinod
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dmaengine: nbpfaxi: Add missing check after DMA map
2025-07-07 7:57 [PATCH] dmaengine: nbpfaxi: Add missing check after DMA map Thomas Fourier
2025-07-23 12:06 ` Vinod Koul
@ 2025-07-23 12:29 ` Vinod Koul
1 sibling, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2025-07-23 12:29 UTC (permalink / raw)
To: Thomas Fourier; +Cc: Guennadi Liakhovetski, dmaengine, linux-kernel
On Mon, 07 Jul 2025 09:57:16 +0200, Thomas Fourier wrote:
> The DMA map functions can fail and should be tested for errors.
> If the mapping fails, unmap and return an error.
>
>
Applied, thanks!
[1/1] dmaengine: nbpfaxi: Add missing check after DMA map
commit: c6ee78fc8f3e653bec427cfd06fec7877ee782bd
Best regards,
--
~Vinod
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-23 12:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-07 7:57 [PATCH] dmaengine: nbpfaxi: Add missing check after DMA map Thomas Fourier
2025-07-23 12:06 ` Vinod Koul
2025-07-23 12:10 ` Vinod Koul
2025-07-23 12:29 ` Vinod Koul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox