From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Miaoqian Lin <linmq006@gmail.com>
Cc: Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Pratyush Yadav <p.yadav@ti.com>,
Paul Cercueil <paul@crapouillou.net>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Bastian Hecht <hechtb@googlemail.com>,
Artem Bityutskiy <artem.bityutskiy@linux.intel.com>,
Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mtd: rawnand: Fix return value check of wait_for_completion_timeout
Date: Tue, 12 Apr 2022 09:06:49 +0200 [thread overview]
Message-ID: <20220412090649.33bb3f8b@xps13> (raw)
In-Reply-To: <20220412063703.8537-1-linmq006@gmail.com>
Hi Miaoqian,
linmq006@gmail.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@gmail.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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
WARNING: multiple messages have this Message-ID (diff)
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Miaoqian Lin <linmq006@gmail.com>
Cc: Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Pratyush Yadav <p.yadav@ti.com>,
Paul Cercueil <paul@crapouillou.net>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Bastian Hecht <hechtb@googlemail.com>,
Artem Bityutskiy <artem.bityutskiy@linux.intel.com>,
Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mtd: rawnand: Fix return value check of wait_for_completion_timeout
Date: Tue, 12 Apr 2022 09:06:49 +0200 [thread overview]
Message-ID: <20220412090649.33bb3f8b@xps13> (raw)
In-Reply-To: <20220412063703.8537-1-linmq006@gmail.com>
Hi Miaoqian,
linmq006@gmail.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@gmail.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
next prev parent reply other threads:[~2022-04-12 7:07 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-12 2:08 [PATCH] mtd: rawnand: Fix return value check of wait_for_completion_timeout Miaoqian Lin
2022-04-12 2:08 ` Miaoqian Lin
2022-04-12 5:01 ` kernel test robot
2022-04-12 5:01 ` kernel test robot
2022-04-12 6:36 ` [PATCH v2] " Miaoqian Lin
2022-04-12 6:36 ` Miaoqian Lin
2022-04-12 7:06 ` Miquel Raynal [this message]
2022-04-12 7:06 ` Miquel Raynal
2022-04-12 7:42 ` Miaoqian Lin
2022-04-12 7:42 ` Miaoqian Lin
2022-04-12 7:48 ` Miquel Raynal
2022-04-12 7:48 ` Miquel Raynal
2022-04-12 8:23 ` Miaoqian Lin
2022-04-12 8:23 ` Miaoqian Lin
2022-04-12 8:28 ` Miquel Raynal
2022-04-12 8:28 ` Miquel Raynal
2022-04-12 8:34 ` [PATCH v3] " Miaoqian Lin
2022-04-12 8:34 ` Miaoqian Lin
2022-04-21 7:35 ` Miquel Raynal
2022-04-21 7:35 ` 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=20220412090649.33bb3f8b@xps13 \
--to=miquel.raynal@bootlin.com \
--cc=alexandre.belloni@bootlin.com \
--cc=artem.bityutskiy@linux.intel.com \
--cc=g.liakhovetski@gmx.de \
--cc=hechtb@googlemail.com \
--cc=linmq006@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=p.yadav@ti.com \
--cc=paul@crapouillou.net \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.