[PATCH v2 1/2] dmaengine: at_xdmac: Kill the channel tasklets before unregistering
From: Suyuan Wang via B4 Relay
Date: Sun Nov 22 2026 - 20:18:02 EST
From: Suyuan Wang <stevewong@xxxxxxxxxxx>
at_xdmac_remove() unregisters the DMA device and disables the clock,
and only then frees the IRQ and kills the channel tasklets in a loop
over dma.chancnt:
dma_async_device_unregister(&atxdmac->dma);
...
clk_disable_unprepare(atxdmac->clk);
free_irq(atxdmac->irq, atxdmac);
for (i = 0; i < atxdmac->dma.chancnt; i++) {
...
tasklet_kill(&atchan->tasklet);
at_xdmac_free_chan_resources(&atchan->chan);
}
Since commit e81274cd6b52 ("dmaengine: add support to dynamic
register/unregister of channels"), dma_async_device_unregister()
unregisters each channel and decrements dma.chancnt for it, so the
loop does nothing and a tasklet scheduled by an interrupt can run after
the devm-allocated atxdmac has been freed. Even when the loop ran,
tasklet_kill() let a pending tasklet run after the channel devices
were freed and the clock was disabled, and the tasklet reads the
channel registers and logs through the channel device.
Free the IRQ, kill the tasklets and free the channel resources right
after at_xdmac_off(), before the channels are unregistered and the
clock is disabled.
Found with a static analysis tool and checked by hand.
Fixes: e1f7c9eee707 ("dmaengine: at_xdmac: creation of the atmel eXtended DMA Controller driver")
Fixes: e81274cd6b52 ("dmaengine: add support to dynamic register/unregister of channels")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
---
drivers/dma/at_xdmac.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c
index ef0dfe9d37ba..d5d60f3d3543 100644
--- a/drivers/dma/at_xdmac.c
+++ b/drivers/dma/at_xdmac.c
@@ -2439,21 +2439,26 @@ static void at_xdmac_remove(struct platform_device *pdev)
int i;
at_xdmac_off(atxdmac, true);
- of_dma_controller_free(pdev->dev.of_node);
- dma_async_device_unregister(&atxdmac->dma);
- pm_runtime_disable(atxdmac->dev);
- pm_runtime_set_suspended(&pdev->dev);
- pm_runtime_dont_use_autosuspend(&pdev->dev);
- clk_disable_unprepare(atxdmac->clk);
-
free_irq(atxdmac->irq, atxdmac);
+ /*
+ * Do this before dma_async_device_unregister(): it frees the channel
+ * devices and decrements dma.chancnt, and the tasklets also need the
+ * clock.
+ */
for (i = 0; i < atxdmac->dma.chancnt; i++) {
struct at_xdmac_chan *atchan = &atxdmac->chan[i];
tasklet_kill(&atchan->tasklet);
at_xdmac_free_chan_resources(&atchan->chan);
}
+
+ of_dma_controller_free(pdev->dev.of_node);
+ dma_async_device_unregister(&atxdmac->dma);
+ pm_runtime_disable(atxdmac->dev);
+ pm_runtime_set_suspended(&pdev->dev);
+ pm_runtime_dont_use_autosuspend(&pdev->dev);
+ clk_disable_unprepare(atxdmac->clk);
}
static const struct dev_pm_ops __maybe_unused atmel_xdmac_dev_pm_ops = {
--
2.34.1