Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Cong Nguyen <congnt264@gmail.com>
To: Keguang Zhang <keguang.zhang@gmail.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>
Cc: linux-mtd@lists.infradead.org, linux-mips@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] mtd: rawnand: loongson: unmap the DMA resource on probe error and remove
Date: Mon, 30 Nov 2026 11:51:57 +0700	[thread overview]
Message-ID: <20261130045157.642174-1-congnt264@gmail.com> (raw)

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


             reply	other threads:[~2026-11-30  4:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  4:51 Cong Nguyen [this message]
2026-11-30  8:06 ` [PATCH] mtd: rawnand: loongson: unmap the DMA resource on probe error and remove Keguang Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130045157.642174-1-congnt264@gmail.com \
    --to=congnt264@gmail.com \
    --cc=keguang.zhang@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox