Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 953345b8 authored by Miaoqian Lin's avatar Miaoqian Lin Committed by Greg Kroah-Hartman
Browse files

mtd: rawnand: Fix return value check of wait_for_completion_timeout



[ Upstream commit 084c16ab423a8890121b902b405823bfec5b4365 ]

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: 83738d87 ("mtd: sh_flctl: Add DMA capabilty")
Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220412083435.29254-1-linmq006@gmail.com


Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 5872a75a
Loading
Loading
Loading
Loading
+8 −6
Original line number Original line Diff line number Diff line
@@ -399,7 +399,8 @@ static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf,
	dma_addr_t dma_addr;
	dma_addr_t dma_addr;
	dma_cookie_t cookie;
	dma_cookie_t cookie;
	uint32_t reg;
	uint32_t reg;
	int ret;
	int ret = 0;
	unsigned long time_left;


	if (dir == DMA_FROM_DEVICE) {
	if (dir == DMA_FROM_DEVICE) {
		chan = flctl->chan_fifo0_rx;
		chan = flctl->chan_fifo0_rx;
@@ -440,13 +441,14 @@ static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf,
		goto out;
		goto out;
	}
	}


	ret =
	time_left =
	wait_for_completion_timeout(&flctl->dma_complete,
	wait_for_completion_timeout(&flctl->dma_complete,
				msecs_to_jiffies(3000));
				msecs_to_jiffies(3000));


	if (ret <= 0) {
	if (time_left == 0) {
		dmaengine_terminate_all(chan);
		dmaengine_terminate_all(chan);
		dev_err(&flctl->pdev->dev, "wait_for_completion_timeout\n");
		dev_err(&flctl->pdev->dev, "wait_for_completion_timeout\n");
		ret = -ETIMEDOUT;
	}
	}


out:
out:
@@ -456,7 +458,7 @@ static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf,


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


	/* ret > 0 is success */
	/* ret == 0 is success */
	return ret;
	return ret;
}
}


@@ -480,7 +482,7 @@ static void read_fiforeg(struct sh_flctl *flctl, int rlen, int offset)


	/* initiate DMA transfer */
	/* initiate DMA transfer */
	if (flctl->chan_fifo0_rx && rlen >= 32 &&
	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 */
			goto convert;	/* DMA success */


	/* do polling transfer */
	/* do polling transfer */
@@ -539,7 +541,7 @@ static void write_ec_fiforeg(struct sh_flctl *flctl, int rlen,


	/* initiate DMA transfer */
	/* initiate DMA transfer */
	if (flctl->chan_fifo0_tx && rlen >= 32 &&
	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 */
			return;	/* DMA success */


	/* do polling transfer */
	/* do polling transfer */