[PATCH v2 2/6] mtd: nand: qpic_common: terminate DMA channels on transfer timeout
Samarth Narang
samarth.colleges at gmail.com
Fri Oct 30 09:20:37 PDT 2026
When DMA completion times out in qcom_submit_descs(), the driver unmaps
the descriptors' scatterlists without stopping the BAM DMA channels.
Since the issued descriptors may still be active, the RX and TX channels
can continue accessing the caller's buffer after it has been unmapped
and returned to the NAND core. The ADM path has a similar issue when
dma_sync_wait() times out.
Terminate the affected channels with dmaengine_terminate_sync() before
unmapping, ensuring that outstanding DMA transfers are stopped before
their mappings are released. On BAM, termination resets the pipe and
discards pending descriptors.
Fixes: 381dd24539a8 ("mtd: nand: qcom: add BAM DMA descriptor handling")
Fixes: c76b78d8ec05 ("mtd: nand: Qualcomm NAND controller driver")
Assisted-by: LLM
Signed-off-by: Samarth Narang <samarth.colleges at gmail.com>
---
drivers/mtd/nand/qpic_common.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/nand/qpic_common.c b/drivers/mtd/nand/qpic_common.c
index 4f3e4dd76..250154a08 100644
--- a/drivers/mtd/nand/qpic_common.c
+++ b/drivers/mtd/nand/qpic_common.c
@@ -592,11 +592,18 @@ int qcom_submit_descs(struct qcom_nand_controller *nandc)
dma_async_issue_pending(nandc->cmd_chan);
if (!wait_for_completion_timeout(&bam_txn->txn_done,
- QPIC_NAND_COMPLETION_TIMEOUT))
+ QPIC_NAND_COMPLETION_TIMEOUT)) {
+ /* Retire every issued pipe before unmapping its buffers. */
+ dmaengine_terminate_sync(nandc->tx_chan);
+ dmaengine_terminate_sync(nandc->rx_chan);
+ dmaengine_terminate_sync(nandc->cmd_chan);
ret = -ETIMEDOUT;
+ }
} else {
- if (dma_sync_wait(nandc->chan, cookie) != DMA_COMPLETE)
+ if (dma_sync_wait(nandc->chan, cookie) != DMA_COMPLETE) {
+ dmaengine_terminate_sync(nandc->chan);
ret = -ETIMEDOUT;
+ }
}
err_unmap_free_desc:
--
2.34.1
More information about the linux-arm-kernel
mailing list