[PATCH 1/2] dmaengine: at_xdmac: Kill the channel tasklets in remove again

Suyuan Wang via B4 Relay devnull+shyckless.gmail.com at kernel.org
Sun Nov 22 16:53:06 PST 2026


From: Suyuan Wang <stevewong at hust.edu.cn>

at_xdmac_remove() kills the channel tasklets and frees the channel
resources in a loop after free_irq():

	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
count is 0 by the time the loop runs and the loop does nothing. A
tasklet scheduled by an interrupt can then run after atxdmac, which is
devm-allocated, has been freed.

Read the channel count before unregistering the device.

Found with a static analysis tool and checked by hand.

Fixes: e81274cd6b52 ("dmaengine: add support to dynamic register/unregister of channels")
Cc: stable at vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li at ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li at ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong at hust.edu.cn>
---
 drivers/dma/at_xdmac.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c
index ef0dfe9d37ba..ef4012c22573 100644
--- a/drivers/dma/at_xdmac.c
+++ b/drivers/dma/at_xdmac.c
@@ -2436,6 +2436,8 @@ static int at_xdmac_probe(struct platform_device *pdev)
 static void at_xdmac_remove(struct platform_device *pdev)
 {
 	struct at_xdmac	*atxdmac = (struct at_xdmac *)platform_get_drvdata(pdev);
+	/* dma_async_device_unregister() decrements dma.chancnt to 0 */
+	int		nr_channels = atxdmac->dma.chancnt;
 	int		i;
 
 	at_xdmac_off(atxdmac, true);
@@ -2448,7 +2450,7 @@ static void at_xdmac_remove(struct platform_device *pdev)
 
 	free_irq(atxdmac->irq, atxdmac);
 
-	for (i = 0; i < atxdmac->dma.chancnt; i++) {
+	for (i = 0; i < nr_channels; i++) {
 		struct at_xdmac_chan *atchan = &atxdmac->chan[i];
 
 		tasklet_kill(&atchan->tasklet);

-- 
2.34.1





More information about the linux-arm-kernel mailing list