Skip to content

Commit 17a8ce8

Browse files
neosys007miquelraynal
authored andcommitted
mtd: rawnand: lpc32xx_slc: fail DMA transfer on completion timeout
lpc32xx_xmit_dma() waits for the DMA completion callback but ignores wait_for_completion_timeout(). A timed out DMA transfer is therefore unmapped and reported as successful to the NAND read/write path. Return -ETIMEDOUT when the completion wait expires. Terminate the DMA channel before unmapping the scatterlist so the timed out transfer cannot continue to access the buffer after the error is returned. Fixes: 2944a44 ("mtd: add LPC32xx SLC NAND driver") Cc: stable@vger.kernel.org Reviewed-by: Vladimir Zapolskiy <vz@kernel.org> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent dbf590b commit 17a8ce8

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

drivers/mtd/nand/raw/lpc32xx_slc.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ static int lpc32xx_xmit_dma(struct mtd_info *mtd, dma_addr_t dma,
430430
struct dma_async_tx_descriptor *desc;
431431
int flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
432432
int res;
433+
unsigned long time_left;
433434

434435
host->dma_slave_config.direction = dir;
435436
host->dma_slave_config.src_addr = dma;
@@ -467,12 +468,19 @@ static int lpc32xx_xmit_dma(struct mtd_info *mtd, dma_addr_t dma,
467468
dmaengine_submit(desc);
468469
dma_async_issue_pending(host->dma_chan);
469470

470-
wait_for_completion_timeout(&host->comp, msecs_to_jiffies(1000));
471+
time_left = wait_for_completion_timeout(&host->comp,
472+
msecs_to_jiffies(1000));
473+
if (!time_left) {
474+
dmaengine_terminate_sync(host->dma_chan);
475+
res = -ETIMEDOUT;
476+
} else {
477+
res = 0;
478+
}
471479

472480
dma_unmap_sg(host->dma_chan->device->dev, &host->sgl, 1,
473481
DMA_BIDIRECTIONAL);
474482

475-
return 0;
483+
return res;
476484
out1:
477485
dma_unmap_sg(host->dma_chan->device->dev, &host->sgl, 1,
478486
DMA_BIDIRECTIONAL);

0 commit comments

Comments
 (0)