From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: ludovic.desroches@microchip.com, vkoul@kernel.org
Cc: Frank.Li@kernel.org, dave.jiang@intel.com,
linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com,
dmaengine@vger.kernel.org, allen.lkml@gmail.com,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 1/2] dmaengine: at_xdmac: Kill the channel tasklets before unregistering
Date: Mon, 23 Nov 2026 01:17:37 +0000 [thread overview]
Message-ID: <20261123-dma-chancnt-v2-1-241b1672883e@gmail.com> (raw)
In-Reply-To: <20261123-dma-chancnt-v2-0-241b1672883e@gmail.com>
From: Suyuan Wang <stevewong@hust.edu.cn>
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@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
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
next prev parent reply other threads:[~2026-11-23 1:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 1:17 [PATCH v2 0/2] dmaengine: Kill channel tasklets in remove again Suyuan Wang via B4 Relay
2026-11-23 1:17 ` Suyuan Wang via B4 Relay [this message]
2026-11-23 1:17 ` [PATCH v2 2/2] dmaengine: idma64: Kill the " Suyuan Wang via B4 Relay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123-dma-chancnt-v2-1-241b1672883e@gmail.com \
--to=devnull+shyckless.gmail.com@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=allen.lkml@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dave.jiang@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ludovic.desroches@microchip.com \
--cc=shyckless@gmail.com \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®