Skip to content

Commit c6ee78f

Browse files
Thomas-fouriervinodkoul
authored andcommitted
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: b45b262 ("dmaengine: add a driver for AMBA AXI NBPF DMAC IP cores") Signed-off-by: Thomas Fourier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 60095ac commit c6ee78f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/dma/nbpfaxi.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ static int nbpf_desc_page_alloc(struct nbpf_channel *chan)
711711
list_add_tail(&ldesc->node, &lhead);
712712
ldesc->hwdesc_dma_addr = dma_map_single(dchan->device->dev,
713713
hwdesc, sizeof(*hwdesc), DMA_TO_DEVICE);
714+
if (dma_mapping_error(dchan->device->dev,
715+
ldesc->hwdesc_dma_addr))
716+
goto unmap_error;
714717

715718
dev_dbg(dev, "%s(): mapped 0x%p to %pad\n", __func__,
716719
hwdesc, &ldesc->hwdesc_dma_addr);
@@ -737,6 +740,16 @@ static int nbpf_desc_page_alloc(struct nbpf_channel *chan)
737740
spin_unlock_irq(&chan->lock);
738741

739742
return ARRAY_SIZE(dpage->desc);
743+
744+
unmap_error:
745+
while (i--) {
746+
ldesc--; hwdesc--;
747+
748+
dma_unmap_single(dchan->device->dev, ldesc->hwdesc_dma_addr,
749+
sizeof(hwdesc), DMA_TO_DEVICE);
750+
}
751+
752+
return -ENOMEM;
740753
}
741754

742755
static void nbpf_desc_put(struct nbpf_desc *desc)

0 commit comments

Comments
 (0)