[PATCH 2/3] mtd: rawnand: intel: declare NAND_USES_DMA

sashiko-bot at kernel.org sashiko-bot at kernel.org
Sun Nov 22 22:01:31 PST 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mtd: rawnand: intel: Fixes tag cites mtdchar instead of driver
  commit
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] mtd: rawnand: intel: DMA mapping leak and invalid unmap in
  ebu_dma_start() [1]
--

commit 414432fa9d307fa5e3ae8ecf35d7868fc7b41467
Author: Ping Li <leeonion.muyu at gmail.com>

> mtd: rawnand: intel: declare NAND_USES_DMA
> 
> ebu_nand_read_page_hwecc()/ebu_nand_write_page_hwecc() feed the
> page buffers provided by the NAND core straight to the DMA
> engine, but the driver never declares NAND_USES_DMA.  Because of
> this, nand_base cannot know the controller DMAs these buffers and
> never bounces non-linear-map ones (see the use_bounce_buf logic
> in nand_do_read_ops()/nand_do_write_ops()).
> 
> Since the mtdchar MEMREAD/MEMWRITE ioctls allocate their buffers
> with kvmalloc(), a heavily fragmented system can already feed a
> vmalloc'd buffer into the controller's DMA engine, which is not a
> valid dma_map_single() input.
> 
> Declare NAND_USES_DMA so that nand_base bounces non-linear-map
> buffers through chip->data_buf, as the other DMA-capable
> controllers already do.
> 
> Fixes: 83208e106a8e8 ("mtdchar: use kvmalloc() for potentially large allocations")
> Signed-off-by: Ping Li <leeonion.muyu at gmail.com>

[Severity: Low]
Should the Fixes: tag point to 0b1039f016e8 ("mtd: rawnand: Add NAND
controller support on Intel LGM SoC") instead?  Upper MTD layers such as
UBI, JFFS2, and mtdblock already pass vmalloc() buffers to mtd_read() and
mtd_write(), so the missing NAND_USES_DMA flag has been an issue since the
driver was introduced.

> diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
> index cfb4b231e0672..1f493fb426d61 100644
> --- a/drivers/mtd/nand/raw/intel-nand-controller.c
> +++ b/drivers/mtd/nand/raw/intel-nand-controller.c
> @@ -688,6 +688,7 @@ static int ebu_nand_probe(struct platform_device *pdev)
>  	nand = &ebu_host->chip;
>  	nand->controller = &ebu_host->controller;
>  	nand->controller->ops = &ebu_nand_controller_ops;
> +	nand->options |= NAND_USES_DMA;
>  
>  	/* Scan to find existence of the device */
>  	ret = nand_scan(&ebu_host->chip, 1);

[Severity: Critical]
This problem wasn't introduced by this patch, but does ebu_dma_start()
leak buf_dma on the success path and unmap the wrong device on error
[1]?

drivers/mtd/nand/raw/intel-nand-controller.c:ebu_dma_start() {
	...
	dma_dev = dmaengine_get_dma_device(chan);
	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 0;

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

	return ret;
}

On the success path, buf_dma is never unmapped after the transfer
completes, leaking IOMMU mappings and skipping cache invalidations on
non-coherent architectures.  Also, when dma_map_single() fails, jumping to
err_unmap unmaps an invalid DMA address, and err_unmap passes
ebu_host->dev instead of dma_dev.

[1] https://sashiko.dev/#/bug/linux-f7fd8979-ca31-481c-b79a-253f8225990b

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123055020.1995251-1-ping.li@horizon.auto?part=2



More information about the linux-mtd mailing list