[PATCH v2 1/4] dmaengine: stm32-dma3: clear flags before signaling transfer completion

Amelie Delaunay amelie.delaunay at foss.st.com
Mon Nov 23 01:17:05 PST 2026


From: Jerome Audu <jerome.audu at st.com>

The interrupt handler clears channel flags after handling the captured
status. However, stm32_dma3_chan_complete() can start another transfer.
If that transfer completes before the flags are cleared, its Transfer
Complete flag is cleared without handling its completion, potentially
causing a timeout.

Clear the captured interrupt flags immediately after reading the channel
status and interrupt enables, before handling the events. This prevents
the handler from clearing a completion flag raised by a newly started
transfer.

Fixes: f561ec8b2b33 ("dmaengine: Add STM32 DMA3 support")
Cc: stable at vger.kernel.org
Signed-off-by: Jerome Audu <jerome.audu at st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay at foss.st.com>

---
Changes in v2:
- Commit message rephrased according to Frank Li's review
---
 drivers/dma/stm32/stm32-dma3.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/dma/stm32/stm32-dma3.c b/drivers/dma/stm32/stm32-dma3.c
index 4fe226541efa..a464e0cefd64 100644
--- a/drivers/dma/stm32/stm32-dma3.c
+++ b/drivers/dma/stm32/stm32-dma3.c
@@ -1008,7 +1008,7 @@ static irqreturn_t stm32_dma3_chan_irq(int irq, void *devid)
 {
 	struct stm32_dma3_chan *chan = devid;
 	struct stm32_dma3_ddata *ddata = to_stm32_dma3_ddata(chan);
-	u32 misr, csr, ccr;
+	u32 misr, csr, ccr, cfcr;
 
 	spin_lock(&chan->vchan.lock);
 
@@ -1021,6 +1021,14 @@ static irqreturn_t stm32_dma3_chan_irq(int irq, void *devid)
 	csr = readl_relaxed(ddata->base + STM32_DMA3_CSR(chan->id));
 	ccr = readl_relaxed(ddata->base + STM32_DMA3_CCR(chan->id)) & CCR_ALLIE;
 
+	/*
+	 * Half Transfer Interrupt may be disabled but Half Transfer Flag can be set,
+	 * ensure HTF flag to be cleared, with other flags.
+	 */
+	cfcr = csr & (ccr | CCR_HTIE);
+	if (cfcr)
+		writel_relaxed(cfcr, ddata->base + STM32_DMA3_CFCR(chan->id));
+
 	if (csr & CSR_TCF && ccr & CCR_TCIE) {
 		if (chan->swdesc->cyclic)
 			vchan_cyclic_callback(&chan->swdesc->vdesc);
@@ -1050,15 +1058,6 @@ static irqreturn_t stm32_dma3_chan_irq(int irq, void *devid)
 		stm32_dma3_chan_reset(chan);
 	}
 
-	/*
-	 * Half Transfer Interrupt may be disabled but Half Transfer Flag can be set,
-	 * ensure HTF flag to be cleared, with other flags.
-	 */
-	csr &= (ccr | CCR_HTIE);
-
-	if (csr)
-		writel_relaxed(csr, ddata->base + STM32_DMA3_CFCR(chan->id));
-
 	spin_unlock(&chan->vchan.lock);
 
 	return IRQ_HANDLED;

-- 
2.43.0




More information about the linux-arm-kernel mailing list