[RFC PATCH] mtd: nand: qpic_common: terminate DMA channels on transfer timeout
From: Samarth Narang
Date: Fri Oct 30 2026 - 11:07:20 EST
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@xxxxxxxxx>
---
Questions for the maintainers: BAM pipe resets may raise a fatal error
if the attached engine remains active, so it is unclear whether the NAND
controller must first be stopped or reset. The success path also assumes
that completion of the final command descriptor implies completion of
the RX data descriptor, which may require confirmation of the hardware
ordering guarantees.
This issue was identified by a research static analyzer for DMA
lifecycle ordering and has not been validated on hardware. The patch has
only been compile-tested on arm64 with W=1.
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:
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907