[PATCH] mtd: rawnand: loongson: unmap the DMA resource on probe error and remove

Cong Nguyen congnt264 at gmail.com
Sun Nov 29 20:51:57 PST 2026


loongson_nand_probe() maps the "nand-dma" resource with
dma_map_resource(), but nothing ever unmaps it. Both the probe error
path and loongson_nand_remove() go through
loongson_nand_controller_cleanup(), which only releases the DMA
channel.

Keep the mapped size in the host structure and unmap in
loongson_nand_controller_cleanup().

Fixes: d2d10ede04b1 ("mtd: rawnand: Add Loongson-1 NAND Controller Driver")
Signed-off-by: Cong Nguyen <congnt264 at gmail.com>
---
 drivers/mtd/nand/raw/loongson-nand-controller.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/nand/raw/loongson-nand-controller.c b/drivers/mtd/nand/raw/loongson-nand-controller.c
index 320d009ebf8c..74a3bd384e2f 100644
--- a/drivers/mtd/nand/raw/loongson-nand-controller.c
+++ b/drivers/mtd/nand/raw/loongson-nand-controller.c
@@ -125,6 +125,7 @@ struct loongson_nand_host {
 	struct regmap *regmap;
 	/* DMA Engine stuff */
 	dma_addr_t dma_base;
+	size_t dma_size;
 	struct dma_chan *dma_chan;
 	dma_cookie_t dma_cookie;
 	struct completion dma_complete;
@@ -766,6 +767,9 @@ static void loongson_nand_controller_cleanup(struct loongson_nand_host *host)
 {
 	if (host->dma_chan)
 		dma_release_channel(host->dma_chan);
+
+	dma_unmap_resource(host->dev, host->dma_base, host->dma_size,
+			   DMA_BIDIRECTIONAL, 0);
 }
 
 static int ls2k1000_nand_apbdma_config(struct device *dev)
@@ -907,6 +911,7 @@ static int loongson_nand_probe(struct platform_device *pdev)
 	if (dma_mapping_error(dev, host->dma_base))
 		return -ENXIO;
 
+	host->dma_size = resource_size(res);
 	host->dev = dev;
 	host->data = data;
 	host->controller.ops = &loongson_nand_controller_ops;
-- 
2.25.1




More information about the linux-mtd mailing list