Skip to content

Commit 084c16a

Browse files
Yuuoniymiquelraynal
authored andcommitted
mtd: rawnand: Fix return value check of wait_for_completion_timeout
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: 83738d8 ("mtd: sh_flctl: Add DMA capabilty") Signed-off-by: Miaoqian Lin <linmq006@gmail.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20220412083435.29254-1-linmq006@gmail.com
1 parent 9fe4e0d commit 084c16a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

drivers/mtd/nand/raw/sh_flctl.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf,
384384
dma_addr_t dma_addr;
385385
dma_cookie_t cookie;
386386
uint32_t reg;
387-
int ret;
387+
int ret = 0;
388+
unsigned long time_left;
388389

389390
if (dir == DMA_FROM_DEVICE) {
390391
chan = flctl->chan_fifo0_rx;
@@ -425,13 +426,14 @@ static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf,
425426
goto out;
426427
}
427428

428-
ret =
429+
time_left =
429430
wait_for_completion_timeout(&flctl->dma_complete,
430431
msecs_to_jiffies(3000));
431432

432-
if (ret <= 0) {
433+
if (time_left == 0) {
433434
dmaengine_terminate_all(chan);
434435
dev_err(&flctl->pdev->dev, "wait_for_completion_timeout\n");
436+
ret = -ETIMEDOUT;
435437
}
436438

437439
out:
@@ -441,7 +443,7 @@ static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf,
441443

442444
dma_unmap_single(chan->device->dev, dma_addr, len, dir);
443445

444-
/* ret > 0 is success */
446+
/* ret == 0 is success */
445447
return ret;
446448
}
447449

@@ -465,7 +467,7 @@ static void read_fiforeg(struct sh_flctl *flctl, int rlen, int offset)
465467

466468
/* initiate DMA transfer */
467469
if (flctl->chan_fifo0_rx && rlen >= 32 &&
468-
flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_FROM_DEVICE) > 0)
470+
!flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_FROM_DEVICE))
469471
goto convert; /* DMA success */
470472

471473
/* do polling transfer */
@@ -524,7 +526,7 @@ static void write_ec_fiforeg(struct sh_flctl *flctl, int rlen,
524526

525527
/* initiate DMA transfer */
526528
if (flctl->chan_fifo0_tx && rlen >= 32 &&
527-
flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_TO_DEVICE) > 0)
529+
!flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_TO_DEVICE))
528530
return; /* DMA success */
529531

530532
/* do polling transfer */

0 commit comments

Comments
 (0)