[PATCH v2 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start()

From: Ping Li

Date: Mon Nov 23 2026 - 02:05:01 EST


ebu_dma_start() maps the data buffer for every page transfer but
only unmaps it on the error path. Successful transfers thus leak
the mapping, which accumulates IOVA space on IOMMU systems and
skips any cache maintenance the unmap would perform on
non-coherent platforms. The error path has two more problems:
when the mapping itself fails it jumps to the unmap with an
invalid dma address, and the unmap is performed with
ebu_host->dev instead of the dma_dev device the buffer was
mapped with.

Return directly when the mapping fails, and unmap with dma_dev on
both the success and the error paths.

Fixes: 0b1039f016e8a ("mtd: rawnand: Add NAND controller support on Intel LGM SoC")
Signed-off-by: Ping Li <leeonion.muyu@xxxxxxxxx>
---
drivers/mtd/nand/raw/intel-nand-controller.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
index 1f493fb426d6..094cf554a7ca 100644
--- a/drivers/mtd/nand/raw/intel-nand-controller.c
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -312,8 +312,7 @@ static int ebu_dma_start(struct ebu_nand_controller *ebu_host, u32 dir,
buf_dma = dma_map_single(dma_dev, (void *)buf, len, dir);
if (dma_mapping_error(dma_dev, buf_dma)) {
dev_err(ebu_host->dev, "Failed to map DMA buffer\n");
- ret = -EIO;
- goto err_unmap;
+ return -EIO;
}

tx = dmaengine_prep_slave_single(chan, buf_dma, len, dir, flags);
@@ -346,10 +345,10 @@ static int ebu_dma_start(struct ebu_nand_controller *ebu_host, u32 dir,
goto err_unmap;
}

- return 0;
+ ret = 0;

err_unmap:
- dma_unmap_single(ebu_host->dev, buf_dma, len, dir);
+ dma_unmap_single(dma_dev, buf_dma, len, dir);

return ret;
}
--
2.34.1