From: Ping Li <leeonion.muyu@gmail.com>
To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Ping Li <leeonion.muyu@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH v4 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start()
Date: Wed, 25 Nov 2026 19:51:07 +0800 [thread overview]
Message-ID: <20261125115108.4147741-3-leeonion.muyu@gmail.com> (raw)
In-Reply-To: <20261125115108.4147741-1-leeonion.muyu@gmail.com>
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")
Cc: stable@vger.kernel.org
Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
---
drivers/mtd/nand/raw/intel-nand-controller.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
index 1f493fb426d6..5eff8d7522d4 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,12 @@ static int ebu_dma_start(struct ebu_nand_controller *ebu_host, u32 dir,
goto err_unmap;
}
+ dma_unmap_single(dma_dev, buf_dma, len, dir);
+
return 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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-11-25 11:51 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 5:50 [PATCH 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers ping.li
2026-11-23 5:50 ` [PATCH 1/3] mtd: rawnand: fsmc: declare NAND_USES_DMA ping.li
2026-11-23 6:01 ` sashiko-bot
2026-11-23 7:04 ` Ping Li
2026-11-23 5:50 ` [PATCH 2/3] mtd: rawnand: intel: " ping.li
2026-11-23 6:01 ` sashiko-bot
2026-11-23 5:50 ` [PATCH 3/3] mtd: rawnand: r852: bounce non-linear-map buffers ping.li
2026-11-23 7:04 ` [PATCH v2 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers Ping Li
2026-11-23 7:04 ` [PATCH v2 1/3] mtd: rawnand: intel: declare NAND_USES_DMA Ping Li
2026-11-23 7:04 ` [PATCH v2 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
2026-11-23 7:04 ` [PATCH v2 3/3] mtd: rawnand: r852: bounce non-linear-map buffers Ping Li
2026-11-25 8:55 ` Miquel Raynal
2026-11-25 9:25 ` Ping Li
2026-11-25 9:25 ` [PATCH v3 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers Ping Li
2026-11-25 9:25 ` [PATCH v3 1/3] mtd: rawnand: intel: declare NAND_USES_DMA Ping Li
2026-11-25 9:25 ` [PATCH v3 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
2026-11-25 9:25 ` [PATCH v3 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
2026-11-25 9:48 ` Miquel Raynal
2026-11-25 11:50 ` Ping Li
2026-11-25 11:51 ` [PATCH v4 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers Ping Li
2026-11-25 11:51 ` [PATCH v4 1/3] mtd: rawnand: intel: declare NAND_USES_DMA Ping Li
2026-11-25 11:51 ` Ping Li [this message]
2026-11-25 11:51 ` [PATCH v4 3/3] mtd: rawnand: r852: " Ping Li
2026-11-25 12:10 ` sashiko-bot
2026-11-25 12:20 ` Miquel Raynal
2026-11-25 12:21 ` [PATCH v5 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers Ping Li
2026-11-25 12:21 ` [PATCH v5 1/3] mtd: rawnand: intel: declare NAND_USES_DMA Ping Li
2026-11-25 12:21 ` [PATCH v5 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
2026-11-25 12:21 ` [PATCH v5 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
2026-11-25 12:55 ` Miquel Raynal
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=20261125115108.4147741-3-leeonion.muyu@gmail.com \
--to=leeonion.muyu@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=stable@vger.kernel.org \
--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