[PATCH] mtd: rawnand: renesas: Add missing check after DMA map

Miquel Raynal miquel.raynal at bootlin.com
Wed Jul 2 00:48:07 PDT 2025


Hi Thomas,

On 02/07/2025 at 09:17:22 +02, Thomas Fourier <fourier.thomas at gmail.com> wrote:

> The DMA map functions can fail and should be tested for errors.
>
> Fixes: d8701fe890ec ("mtd: rawnand: renesas: Add new NAND controller driver")
> Cc: stable at vger.kernel.org
> Signed-off-by: Thomas Fourier <fourier.thomas at gmail.com>
> ---
>  drivers/mtd/nand/raw/renesas-nand-controller.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/mtd/nand/raw/renesas-nand-controller.c b/drivers/mtd/nand/raw/renesas-nand-controller.c
> index 44f6603736d1..f4a775571733 100644
> --- a/drivers/mtd/nand/raw/renesas-nand-controller.c
> +++ b/drivers/mtd/nand/raw/renesas-nand-controller.c
> @@ -426,6 +426,10 @@ static int rnandc_read_page_hw_ecc(struct nand_chip *chip, u8 *buf,
>  	/* Configure DMA */
>  	dma_addr = dma_map_single(rnandc->dev, rnandc->buf, mtd->writesize,
>  				  DMA_FROM_DEVICE);
> +	if (dma_mapping_error(rnandc->dev, dma_addr)) {
> +		dev_err(rnandc->dev, "DMA mapping failed.\n");

This error message is not informative, please drop
it. dma_mapping_error() does give more information if you enable some
DMA DEBUG Kconfig symbol already.

> +		return -ENOMEM;
> +	}
>  	writel(dma_addr, rnandc->regs + DMA_ADDR_LOW_REG);
>  	writel(mtd->writesize, rnandc->regs + DMA_CNT_REG);
>  	writel(DMA_TLVL_MAX, rnandc->regs + DMA_TLVL_REG);
> @@ -606,6 +610,10 @@ static int rnandc_write_page_hw_ecc(struct nand_chip *chip, const u8 *buf,
>  	/* Configure DMA */
>  	dma_addr = dma_map_single(rnandc->dev, (void *)rnandc->buf, mtd->writesize,
>  				  DMA_TO_DEVICE);
> +	if (dma_mapping_error(rnandc->dev, dma_addr)) {
> +		dev_err(rnandc->dev, "DMA mapping failed.\n");

Ditto.

> +		return -ENOMEM;
> +	}
>  	writel(dma_addr, rnandc->regs + DMA_ADDR_LOW_REG);
>  	writel(mtd->writesize, rnandc->regs + DMA_CNT_REG);
>  	writel(DMA_TLVL_MAX, rnandc->regs + DMA_TLVL_REG);

Thanks,
Miquèl



More information about the linux-mtd mailing list