[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220412090649.33bb3f8b@xps13>
Date: Tue, 12 Apr 2022 09:06:49 +0200
From: Miquel Raynal <miquel.raynal@...tlin.com>
To: Miaoqian Lin <linmq006@...il.com>
Cc: Richard Weinberger <richard@....at>,
Vignesh Raghavendra <vigneshr@...com>,
Pratyush Yadav <p.yadav@...com>,
Paul Cercueil <paul@...pouillou.net>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Bastian Hecht <hechtb@...glemail.com>,
Artem Bityutskiy <artem.bityutskiy@...ux.intel.com>,
Guennadi Liakhovetski <g.liakhovetski@....de>,
linux-mtd@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] mtd: rawnand: Fix return value check of
wait_for_completion_timeout
Hi Miaoqian,
linmq006@...il.com wrote on Tue, 12 Apr 2022 06:36:52 +0000:
> wait_for_completion_timeout() returns unsigned long not int.
> It returns 0 if timed out, and positive if completed.
> The check for <= 0 is ambiguous and should be == 0 here
> indicating timeout which is the only error case.
>
> Fixes: 83738d87e3a0 ("mtd: sh_flctl: Add DMA capabilty")
> Signed-off-by: Miaoqian Lin <linmq006@...il.com>
> ---
> change in v2:
> - initialize ret to 1.
> ---
> drivers/mtd/nand/raw/sh_flctl.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/sh_flctl.c b/drivers/mtd/nand/raw/sh_flctl.c
> index b85b9c6fcc42..2373251f585b 100644
> --- a/drivers/mtd/nand/raw/sh_flctl.c
> +++ b/drivers/mtd/nand/raw/sh_flctl.c
> @@ -384,7 +384,8 @@ static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf,
> dma_addr_t dma_addr;
> dma_cookie_t cookie;
> uint32_t reg;
> - int ret;
> + int ret = 1;
Does not look right. I know this function returns > 0 on positive
outcomes but this does not make any sense in the first place.
This function is static and only called twice, please turn it into
something like:
if (dma_fifo_transfer())
error
else
ok
> + unsigned long time_left;
>
> if (dir == DMA_FROM_DEVICE) {
> chan = flctl->chan_fifo0_rx;
> @@ -425,13 +426,14 @@ static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf,
> goto out;
> }
>
> - ret =
> + time_left =
> wait_for_completion_timeout(&flctl->dma_complete,
> msecs_to_jiffies(3000));
>
> - if (ret <= 0) {
> + if (time_left == 0) {
> dmaengine_terminate_all(chan);
> dev_err(&flctl->pdev->dev, "wait_for_completion_timeout\n");
> + ret = -ETIMEDOUT;
> }
>
> out:
Thanks,
Miquèl
Powered by blists - more mailing lists