Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Zapolskiy <vz@kernel.org>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>,
	Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Piotr Wojtaszczyk <piotr.wojtaszczyk@timesys.com>,
	linux-mtd@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: rawnand: lpc32xx_mlc: fail DMA transfers on timeout
Date: Thu, 25 Jun 2026 16:42:21 +0300	[thread overview]
Message-ID: <88e3f1a6-b07e-4442-a275-269d68aa8120@kernel.org> (raw)
In-Reply-To: <20260625003327.11060-1-pengpeng@iscas.ac.cn>

On 6/25/26 03:33, Pengpeng Hou wrote:
> lpc32xx_xmit_dma() starts a DMA transfer and waits up to one second for
> its completion, but it ignores the wait result and returns success after
> unmapping the buffer.
> 
> A timed out read can therefore return success with incomplete data, and a
> timed out write can continue the NAND operation without proof that the DMA
> payload reached the controller.
> 
> Terminate the DMA channel on timeout, unmap the scatterlist through the
> existing cleanup path, and return -ETIMEDOUT to the NAND read/write
> callers.
> 
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
> ---
>   drivers/mtd/nand/raw/lpc32xx_mlc.c | 12 ++++++++++--
>   1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/lpc32xx_mlc.c b/drivers/mtd/nand/raw/lpc32xx_mlc.c
> index 19b13ae53..8f6a89d9b 100644
> --- a/drivers/mtd/nand/raw/lpc32xx_mlc.c
> +++ b/drivers/mtd/nand/raw/lpc32xx_mlc.c
> @@ -396,6 +396,7 @@ static int lpc32xx_xmit_dma(struct mtd_info *mtd, void *mem, int len,
>   	struct lpc32xx_nand_host *host = nand_get_controller_data(chip);
>   	struct dma_async_tx_descriptor *desc;
>   	int flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
> +	unsigned long time_left;
>   	int res;
>   
>   	sg_init_one(&host->sgl, mem, len);
> @@ -410,6 +411,7 @@ static int lpc32xx_xmit_dma(struct mtd_info *mtd, void *mem, int len,
>   				       flags);
>   	if (!desc) {
>   		dev_err(mtd->dev.parent, "Failed to prepare slave sg\n");
> +		res = -ENXIO;
>   		goto out1;
>   	}
>   
> @@ -420,7 +422,13 @@ static int lpc32xx_xmit_dma(struct mtd_info *mtd, void *mem, int len,
>   	dmaengine_submit(desc);
>   	dma_async_issue_pending(host->dma_chan);
>   
> -	wait_for_completion_timeout(&host->comp_dma, msecs_to_jiffies(1000));
> +	time_left = wait_for_completion_timeout(&host->comp_dma,
> +						msecs_to_jiffies(1000));
> +	if (!time_left) {
> +		dmaengine_terminate_sync(host->dma_chan);
> +		res = -ETIMEDOUT;
> +		goto out1;
> +	}
>   
>   	dma_unmap_sg(host->dma_chan->device->dev, &host->sgl, 1,
>   		     DMA_BIDIRECTIONAL);
> @@ -428,7 +436,7 @@ static int lpc32xx_xmit_dma(struct mtd_info *mtd, void *mem, int len,
>   out1:
>   	dma_unmap_sg(host->dma_chan->device->dev, &host->sgl, 1,
>   		     DMA_BIDIRECTIONAL);
> -	return -ENXIO;
> +	return res;
>   }
>   
>   static int lpc32xx_read_page(struct nand_chip *chip, uint8_t *buf,

Thank you for the change.

Reviewed-by: Vladimir Zapolskiy <vz@kernel.org>

-- 
Best wishes,
Vladimir

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

      reply	other threads:[~2026-06-25 13:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25  0:33 [PATCH] mtd: rawnand: lpc32xx_mlc: fail DMA transfers on timeout Pengpeng Hou
2026-06-25 13:42 ` Vladimir Zapolskiy [this message]

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=88e3f1a6-b07e-4442-a275-269d68aa8120@kernel.org \
    --to=vz@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=pengpeng@iscas.ac.cn \
    --cc=piotr.wojtaszczyk@timesys.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