Skip to contentSkip to conversation

dmaengine: nbpfaxi: Add missing check after DMA map

PATCH Applied Thomas Fourier 2 participants 4 messages Jul 7, 2025 – Jul 23, 2025 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: nbpfaxi: Add missing check after DMA map

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")
---
 drivers/dma/nbpfaxi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/dma/nbpfaxi.c +13 -0
index 0d6324c4e2be..0b75bb122898 100644
@@ -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)
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 2 lines · Thomas Fourier

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

Quoted 40 lines
Fixes b45b262cefd5 ("dmaengine: add a driver for AMBA AXI NBPF DMAC IP cores")
---
 drivers/dma/nbpfaxi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/dma/nbpfaxi.c +13 -0
index 0d6324c4e2be..0b75bb122898 100644
@@ -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)
Signature · 1 line
2.43.0
Signature · 1 line
~Vinod
maintainer
#2 lore raw
Quoted 6 lines · Vinod Koul
Quoted 2 lines · Thomas Fourier

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

Signature · 1 line
~Vinod
maintainer Applied
#3 lore raw
In reply to Thomas Fourier
Quoted 4 lines · Thomas Fourier

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,

Signature · 1 line
~Vinod