* [PATCH] mtd: rawnand: loongson: unmap the DMA resource on probe error and remove
@ 2026-11-30 4:51 Cong Nguyen
2026-11-30 8:06 ` Keguang Zhang
0 siblings, 1 reply; 2+ messages in thread
From: Cong Nguyen @ 2026-11-30 4:51 UTC (permalink / raw)
To: Keguang Zhang, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra
Cc: linux-mtd, linux-mips, linux-kernel
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@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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: rawnand: loongson: unmap the DMA resource on probe error and remove
2026-11-30 4:51 [PATCH] mtd: rawnand: loongson: unmap the DMA resource on probe error and remove Cong Nguyen
@ 2026-11-30 8:06 ` Keguang Zhang
0 siblings, 0 replies; 2+ messages in thread
From: Keguang Zhang @ 2026-11-30 8:06 UTC (permalink / raw)
To: Cong Nguyen
Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, linux-mtd,
linux-mips, linux-kernel
On Mon, Nov 30, 2026 at 12:52 PM Cong Nguyen <congnt264@gmail.com> wrote:
>
> 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@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
>
Reviewed-by: Keguang Zhang <keguang.zhang@gmail.com>
--
Best regards,
Keguang Zhang
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 8:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 4:51 [PATCH] mtd: rawnand: loongson: unmap the DMA resource on probe error and remove Cong Nguyen
2026-11-30 8:06 ` Keguang Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox