Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
Link: https://lore.kernel.org/r/20250707075752.28674-2-fourier.thomas@gmail.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Thomas Fourier and committed by
Vinod Koul
c6ee78fc 60095aca

+13
+13
drivers/dma/nbpfaxi.c
··· 711 711 list_add_tail(&ldesc->node, &lhead); 712 712 ldesc->hwdesc_dma_addr = dma_map_single(dchan->device->dev, 713 713 hwdesc, sizeof(*hwdesc), DMA_TO_DEVICE); 714 + if (dma_mapping_error(dchan->device->dev, 715 + ldesc->hwdesc_dma_addr)) 716 + goto unmap_error; 714 717 715 718 dev_dbg(dev, "%s(): mapped 0x%p to %pad\n", __func__, 716 719 hwdesc, &ldesc->hwdesc_dma_addr); ··· 740 737 spin_unlock_irq(&chan->lock); 741 738 742 739 return ARRAY_SIZE(dpage->desc); 740 + 741 + unmap_error: 742 + while (i--) { 743 + ldesc--; hwdesc--; 744 + 745 + dma_unmap_single(dchan->device->dev, ldesc->hwdesc_dma_addr, 746 + sizeof(hwdesc), DMA_TO_DEVICE); 747 + } 748 + 749 + return -ENOMEM; 743 750 } 744 751 745 752 static void nbpf_desc_put(struct nbpf_desc *desc)