* [PATCH] mtd: rawnand: Fix return value check of wait_for_completion_timeout
@ 2022-04-12 2:08 Miaoqian Lin
2022-04-12 5:01 ` kernel test robot
0 siblings, 1 reply; 10+ messages in thread
From: Miaoqian Lin @ 2022-04-12 2:08 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Pratyush Yadav, Miaoqian Lin, Alexandre Belloni, Paul Cercueil,
Guennadi Liakhovetski, Artem Bityutskiy, Bastian Hecht, linux-mtd,
linux-kernel
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>
---
drivers/mtd/nand/raw/sh_flctl.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/nand/raw/sh_flctl.c b/drivers/mtd/nand/raw/sh_flctl.c
index b85b9c6fcc42..4f326a2dd170 100644
--- a/drivers/mtd/nand/raw/sh_flctl.c
+++ b/drivers/mtd/nand/raw/sh_flctl.c
@@ -385,6 +385,7 @@ static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf,
dma_cookie_t cookie;
uint32_t reg;
int ret;
+ 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:
--
2.17.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH] mtd: rawnand: Fix return value check of wait_for_completion_timeout 2022-04-12 2:08 [PATCH] mtd: rawnand: Fix return value check of wait_for_completion_timeout Miaoqian Lin @ 2022-04-12 5:01 ` kernel test robot 2022-04-12 6:36 ` [PATCH v2] " Miaoqian Lin 0 siblings, 1 reply; 10+ messages in thread From: kernel test robot @ 2022-04-12 5:01 UTC (permalink / raw) To: Miaoqian Lin, Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Pratyush Yadav, Alexandre Belloni, Paul Cercueil, Guennadi Liakhovetski, Artem Bityutskiy, Bastian Hecht, linux-mtd, linux-kernel Cc: llvm, kbuild-all Hi Miaoqian, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on mtd/nand/next] [also build test WARNING on linus/master linux/master v5.18-rc2 next-20220411] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/intel-lab-lkp/linux/commits/Miaoqian-Lin/mtd-rawnand-Fix-return-value-check-of-wait_for_completion_timeout/20220412-101006 base: https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next config: hexagon-randconfig-r045-20220411 (https://download.01.org/0day-ci/archive/20220412/202204121253.NcZifMQi-lkp@intel.com/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project fe2478d44e4f7f191c43fef629ac7a23d0251e72) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/3de25b46a3f73a3e0031e5186eb4e2afa9098b46 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Miaoqian-Lin/mtd-rawnand-Fix-return-value-check-of-wait_for_completion_timeout/20220412-101006 git checkout 3de25b46a3f73a3e0031e5186eb4e2afa9098b46 # save the config file to linux build tree mkdir build_dir COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/mtd/nand/raw/ If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): >> drivers/mtd/nand/raw/sh_flctl.c:433:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] if (time_left == 0) { ^~~~~~~~~~~~~~ drivers/mtd/nand/raw/sh_flctl.c:447:9: note: uninitialized use occurs here return ret; ^~~ drivers/mtd/nand/raw/sh_flctl.c:433:2: note: remove the 'if' if its condition is always true if (time_left == 0) { ^~~~~~~~~~~~~~~~~~~~ drivers/mtd/nand/raw/sh_flctl.c:387:9: note: initialize the variable 'ret' to silence this warning int ret; ^ = 0 1 warning generated. vim +433 drivers/mtd/nand/raw/sh_flctl.c 377 378 static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf, 379 int len, enum dma_data_direction dir) 380 { 381 struct dma_async_tx_descriptor *desc = NULL; 382 struct dma_chan *chan; 383 enum dma_transfer_direction tr_dir; 384 dma_addr_t dma_addr; 385 dma_cookie_t cookie; 386 uint32_t reg; 387 int ret; 388 unsigned long time_left; 389 390 if (dir == DMA_FROM_DEVICE) { 391 chan = flctl->chan_fifo0_rx; 392 tr_dir = DMA_DEV_TO_MEM; 393 } else { 394 chan = flctl->chan_fifo0_tx; 395 tr_dir = DMA_MEM_TO_DEV; 396 } 397 398 dma_addr = dma_map_single(chan->device->dev, buf, len, dir); 399 400 if (!dma_mapping_error(chan->device->dev, dma_addr)) 401 desc = dmaengine_prep_slave_single(chan, dma_addr, len, 402 tr_dir, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 403 404 if (desc) { 405 reg = readl(FLINTDMACR(flctl)); 406 reg |= DREQ0EN; 407 writel(reg, FLINTDMACR(flctl)); 408 409 desc->callback = flctl_dma_complete; 410 desc->callback_param = flctl; 411 cookie = dmaengine_submit(desc); 412 if (dma_submit_error(cookie)) { 413 ret = dma_submit_error(cookie); 414 dev_warn(&flctl->pdev->dev, 415 "DMA submit failed, falling back to PIO\n"); 416 goto out; 417 } 418 419 dma_async_issue_pending(chan); 420 } else { 421 /* DMA failed, fall back to PIO */ 422 flctl_release_dma(flctl); 423 dev_warn(&flctl->pdev->dev, 424 "DMA failed, falling back to PIO\n"); 425 ret = -EIO; 426 goto out; 427 } 428 429 time_left = 430 wait_for_completion_timeout(&flctl->dma_complete, 431 msecs_to_jiffies(3000)); 432 > 433 if (time_left == 0) { 434 dmaengine_terminate_all(chan); 435 dev_err(&flctl->pdev->dev, "wait_for_completion_timeout\n"); 436 ret = -ETIMEDOUT; 437 } 438 439 out: 440 reg = readl(FLINTDMACR(flctl)); 441 reg &= ~DREQ0EN; 442 writel(reg, FLINTDMACR(flctl)); 443 444 dma_unmap_single(chan->device->dev, dma_addr, len, dir); 445 446 /* ret > 0 is success */ 447 return ret; 448 } 449 -- 0-DAY CI Kernel Test Service https://01.org/lkp ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2] mtd: rawnand: Fix return value check of wait_for_completion_timeout 2022-04-12 5:01 ` kernel test robot @ 2022-04-12 6:36 ` Miaoqian Lin 2022-04-12 7:06 ` Miquel Raynal 0 siblings, 1 reply; 10+ messages in thread From: Miaoqian Lin @ 2022-04-12 6:36 UTC (permalink / raw) To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Pratyush Yadav, Miaoqian Lin, Paul Cercueil, Alexandre Belloni, Bastian Hecht, Artem Bityutskiy, Guennadi Liakhovetski, linux-mtd, linux-kernel 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; + 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: -- 2.17.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2] mtd: rawnand: Fix return value check of wait_for_completion_timeout 2022-04-12 6:36 ` [PATCH v2] " Miaoqian Lin @ 2022-04-12 7:06 ` Miquel Raynal 2022-04-12 7:42 ` Miaoqian Lin 0 siblings, 1 reply; 10+ messages in thread From: Miquel Raynal @ 2022-04-12 7:06 UTC (permalink / raw) To: Miaoqian Lin Cc: Richard Weinberger, Vignesh Raghavendra, Pratyush Yadav, Paul Cercueil, Alexandre Belloni, Bastian Hecht, Artem Bityutskiy, Guennadi Liakhovetski, linux-mtd, linux-kernel 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] mtd: rawnand: Fix return value check of wait_for_completion_timeout 2022-04-12 7:06 ` Miquel Raynal @ 2022-04-12 7:42 ` Miaoqian Lin 2022-04-12 7:48 ` Miquel Raynal 0 siblings, 1 reply; 10+ messages in thread From: Miaoqian Lin @ 2022-04-12 7:42 UTC (permalink / raw) To: Miquel Raynal Cc: Richard Weinberger, Vignesh Raghavendra, Pratyush Yadav, Paul Cercueil, Alexandre Belloni, Bastian Hecht, Artem Bityutskiy, Guennadi Liakhovetski, linux-mtd, linux-kernel Hi Miquel, Thanks for your reply. On 2022/4/12 15:06, Miquel Raynal wrote: > 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. Yes, I made a mistake, Now I realize that in v2, it will return 1 in error path when DMA submit failed. And for patch v1, it will return 0 if calls wait_for_completion_timeout succeeds. > This function is static and only called twice, please turn it into > something like: > > if (dma_fifo_transfer()) > error > else > ok So I want to keep ret>0 means success. Or could I set ret > 0 after in wait_for_completion_timeout() success path? like: if(time_left == 0) ret = -ETIMEDOUT; else ret = 1; What do you think? Thanks, >> + 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] mtd: rawnand: Fix return value check of wait_for_completion_timeout 2022-04-12 7:42 ` Miaoqian Lin @ 2022-04-12 7:48 ` Miquel Raynal 2022-04-12 8:23 ` Miaoqian Lin 0 siblings, 1 reply; 10+ messages in thread From: Miquel Raynal @ 2022-04-12 7:48 UTC (permalink / raw) To: Miaoqian Lin Cc: Richard Weinberger, Vignesh Raghavendra, Pratyush Yadav, Paul Cercueil, Alexandre Belloni, Bastian Hecht, Artem Bityutskiy, Guennadi Liakhovetski, linux-mtd, linux-kernel Hi Miaoqian, linmq006@gmail.com wrote on Tue, 12 Apr 2022 15:42:02 +0800: > Hi Miquel, > > Thanks for your reply. > > On 2022/4/12 15:06, Miquel Raynal wrote: > > 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. > > Yes, I made a mistake, Now I realize that in v2, it will return 1 in error path > > when DMA submit failed. Not 1, but a proper error code please (-ETIMEDOUT, -EINVAL, whatever) > > And for patch v1, it will return 0 if calls wait_for_completion_timeout succeeds. > > > This function is static and only called twice, please turn it into > > something like: > > > > if (dma_fifo_transfer()) > > error > > else > > ok > > So I want to keep ret>0 means success. > > Or could I set ret > 0 after in wait_for_completion_timeout() success path? > > like: > > if(time_left == 0) > > ret = -ETIMEDOUT; > > else > > ret = 1; You can initialize ret to zero at to top. So that anything != 0 is an error (like a lot of functions in the kernel). And use: if (dma_fifo_transfer()) error(); > > What do you think? > > > Thanks, > > >> + 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 Thanks, Miquèl ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] mtd: rawnand: Fix return value check of wait_for_completion_timeout 2022-04-12 7:48 ` Miquel Raynal @ 2022-04-12 8:23 ` Miaoqian Lin 2022-04-12 8:28 ` Miquel Raynal 0 siblings, 1 reply; 10+ messages in thread From: Miaoqian Lin @ 2022-04-12 8:23 UTC (permalink / raw) To: Miquel Raynal Cc: Richard Weinberger, Vignesh Raghavendra, Pratyush Yadav, Paul Cercueil, Alexandre Belloni, Bastian Hecht, Artem Bityutskiy, Guennadi Liakhovetski, linux-mtd, linux-kernel Hi Miquel, On 2022/4/12 15:48, Miquel Raynal wrote: > >>> 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. >> Yes, I made a mistake, Now I realize that in v2, it will return 1 in error path >> >> when DMA submit failed. > Not 1, but a proper error code please (-ETIMEDOUT, -EINVAL, whatever) > >> And for patch v1, it will return 0 if calls wait_for_completion_timeout succeeds. >> >>> This function is static and only called twice, please turn it into >>> something like: >>> >>> if (dma_fifo_transfer()) >>> error >>> else >>> ok >> So I want to keep ret>0 means success. >> >> Or could I set ret > 0 after in wait_for_completion_timeout() success path? >> >> like: >> >> if(time_left == 0) >> >> ret = -ETIMEDOUT; >> >> else >> >> ret = 1; > You can initialize ret to zero at to top. So that anything != 0 is an > error (like a lot of functions in the kernel). Thanks for your advice, I will do this. > And use: > > if (dma_fifo_transfer()) > error(); I think keeping the original condition structure is better, something like: if (dma_fifo_transfer()==0) succeed(); In this way, only minor changes is needed——only need to update the symbol in condition. Otherwise It needs to restructure the code and be more complicated. Thanks, >> What do you think? >> >> >> Thanks, >> >>>> + 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 > > Thanks, > Miquèl ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] mtd: rawnand: Fix return value check of wait_for_completion_timeout 2022-04-12 8:23 ` Miaoqian Lin @ 2022-04-12 8:28 ` Miquel Raynal 2022-04-12 8:34 ` [PATCH v3] " Miaoqian Lin 0 siblings, 1 reply; 10+ messages in thread From: Miquel Raynal @ 2022-04-12 8:28 UTC (permalink / raw) To: Miaoqian Lin Cc: Richard Weinberger, Vignesh Raghavendra, Pratyush Yadav, Paul Cercueil, Alexandre Belloni, Bastian Hecht, Artem Bityutskiy, Guennadi Liakhovetski, linux-mtd, linux-kernel Hi Miaoqian, linmq006@gmail.com wrote on Tue, 12 Apr 2022 16:23:24 +0800: > Hi Miquel, > > On 2022/4/12 15:48, Miquel Raynal wrote: > > > >>> 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. > >> Yes, I made a mistake, Now I realize that in v2, it will return 1 in error path > >> > >> when DMA submit failed. > > Not 1, but a proper error code please (-ETIMEDOUT, -EINVAL, whatever) > > > >> And for patch v1, it will return 0 if calls wait_for_completion_timeout succeeds. > >> > >>> This function is static and only called twice, please turn it into > >>> something like: > >>> > >>> if (dma_fifo_transfer()) > >>> error > >>> else > >>> ok > >> So I want to keep ret>0 means success. > >> > >> Or could I set ret > 0 after in wait_for_completion_timeout() success path? > >> > >> like: > >> > >> if(time_left == 0) > >> > >> ret = -ETIMEDOUT; > >> > >> else > >> > >> ret = 1; > > You can initialize ret to zero at to top. So that anything != 0 is an > > error (like a lot of functions in the kernel). > > Thanks for your advice, I will do this. > > And use: > > > > if (dma_fifo_transfer()) > > error(); > I think keeping the original condition structure is better, > something like: > > if (dma_fifo_transfer()==0) if (cond && cond && !dma_fifo_transfer()) > succeed(); > > In this way, only minor changes is needed——only need to update the symbol in condition. > Otherwise It needs to restructure the code and be more complicated. > > > Thanks, > > >> What do you think? > >> > >> > >> Thanks, > >> > >>>> + 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 > > > > Thanks, > > Miquèl Thanks, Miquèl ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3] mtd: rawnand: Fix return value check of wait_for_completion_timeout 2022-04-12 8:28 ` Miquel Raynal @ 2022-04-12 8:34 ` Miaoqian Lin 2022-04-21 7:35 ` Miquel Raynal 0 siblings, 1 reply; 10+ messages in thread From: Miaoqian Lin @ 2022-04-12 8:34 UTC (permalink / raw) To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Paul Cercueil, Miaoqian Lin, Alexandre Belloni, Pratyush Yadav, Artem Bityutskiy, Bastian Hecht, Guennadi Liakhovetski, linux-mtd, linux-kernel 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. --- changes in v3: - initialize ret to 0, now ret==0 means success. - update condition check in caller. --- drivers/mtd/nand/raw/sh_flctl.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/nand/raw/sh_flctl.c b/drivers/mtd/nand/raw/sh_flctl.c index b85b9c6fcc42..a278829469d6 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 = 0; + 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: @@ -441,7 +443,7 @@ static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf, dma_unmap_single(chan->device->dev, dma_addr, len, dir); - /* ret > 0 is success */ + /* ret == 0 is success */ return ret; } @@ -465,7 +467,7 @@ static void read_fiforeg(struct sh_flctl *flctl, int rlen, int offset) /* initiate DMA transfer */ if (flctl->chan_fifo0_rx && rlen >= 32 && - flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_FROM_DEVICE) > 0) + !flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_FROM_DEVICE)) goto convert; /* DMA success */ /* do polling transfer */ @@ -524,7 +526,7 @@ static void write_ec_fiforeg(struct sh_flctl *flctl, int rlen, /* initiate DMA transfer */ if (flctl->chan_fifo0_tx && rlen >= 32 && - flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_TO_DEVICE) > 0) + !flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_TO_DEVICE)) return; /* DMA success */ /* do polling transfer */ -- 2.17.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v3] mtd: rawnand: Fix return value check of wait_for_completion_timeout 2022-04-12 8:34 ` [PATCH v3] " Miaoqian Lin @ 2022-04-21 7:35 ` Miquel Raynal 0 siblings, 0 replies; 10+ messages in thread From: Miquel Raynal @ 2022-04-21 7:35 UTC (permalink / raw) To: Miaoqian Lin, Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Paul Cercueil, Alexandre Belloni, Pratyush Yadav, Artem Bityutskiy, Bastian Hecht, Guennadi Liakhovetski, linux-mtd, linux-kernel On Tue, 2022-04-12 at 08:34:31 UTC, Miaoqian Lin wrote: > 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> Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks. Miquel ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-04-21 7:36 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-04-12 2:08 [PATCH] mtd: rawnand: Fix return value check of wait_for_completion_timeout Miaoqian Lin 2022-04-12 5:01 ` kernel test robot 2022-04-12 6:36 ` [PATCH v2] " Miaoqian Lin 2022-04-12 7:06 ` Miquel Raynal 2022-04-12 7:42 ` Miaoqian Lin 2022-04-12 7:48 ` Miquel Raynal 2022-04-12 8:23 ` Miaoqian Lin 2022-04-12 8:28 ` Miquel Raynal 2022-04-12 8:34 ` [PATCH v3] " Miaoqian Lin 2022-04-21 7:35 ` Miquel Raynal
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox