* [PATCH 0/2] dmaengine: Kill channel tasklets in remove again
@ 2026-11-23 0:53 Suyuan Wang via B4 Relay
2026-11-23 0:53 ` [PATCH 1/2] dmaengine: at_xdmac: Kill the " Suyuan Wang via B4 Relay
2026-11-23 0:53 ` [PATCH 2/2] dmaengine: idma64: " Suyuan Wang via B4 Relay
0 siblings, 2 replies; 4+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-23 0:53 UTC (permalink / raw)
To: vkoul, ludovic.desroches
Cc: linux-arm-kernel, linux-kernel, Frank.Li, allen.lkml, dave.jiang,
dmaengine, andriy.shevchenko
at_xdmac and idma64 kill their channel tasklets in remove() with a loop
over dma.chancnt after dma_async_device_unregister(). Since commit
e81274cd6b52, dma_async_device_unregister() unregisters each channel
and decrements dma.chancnt for it, so chancnt is 0 when the loops run,
they do nothing, and a tasklet scheduled by an interrupt can run after
the devm-allocated driver data is gone. Both patches read the count
before unregistering.
These loops are also touched by Allen's "dmaengine: migrate channel
tasklets to WQ_BH" series (v4, 01/33 and 04/33), which keeps the
chancnt bound. The two fixes don't depend on that series; they make the
current tasklet cleanup work again. Whichever goes in second needs a
trivial rebase.
Found with a static analysis tool and checked by hand. Compile tested
on x86_64 with COMPILE_TEST (W=1); I don't have the hardware.
---
Suyuan Wang (2):
dmaengine: at_xdmac: Kill the channel tasklets in remove again
dmaengine: idma64: Kill the channel tasklets in remove again
drivers/dma/at_xdmac.c | 4 +++-
drivers/dma/idma64.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] dmaengine: at_xdmac: Kill the channel tasklets in remove again
2026-11-23 0:53 [PATCH 0/2] dmaengine: Kill channel tasklets in remove again Suyuan Wang via B4 Relay
@ 2026-11-23 0:53 ` Suyuan Wang via B4 Relay
2026-11-23 0:53 ` [PATCH 2/2] dmaengine: idma64: " Suyuan Wang via B4 Relay
1 sibling, 0 replies; 4+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-23 0:53 UTC (permalink / raw)
To: vkoul, ludovic.desroches
Cc: linux-arm-kernel, linux-kernel, Frank.Li, allen.lkml, dave.jiang,
dmaengine, andriy.shevchenko
From: Suyuan Wang <stevewong@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@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 | 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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] dmaengine: idma64: Kill the channel tasklets in remove again
2026-11-23 0:53 [PATCH 0/2] dmaengine: Kill channel tasklets in remove again Suyuan Wang via B4 Relay
2026-11-23 0:53 ` [PATCH 1/2] dmaengine: at_xdmac: Kill the " Suyuan Wang via B4 Relay
@ 2026-11-23 0:53 ` Suyuan Wang via B4 Relay
2026-11-23 9:47 ` Andy Shevchenko
1 sibling, 1 reply; 4+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-23 0:53 UTC (permalink / raw)
To: vkoul, ludovic.desroches
Cc: linux-arm-kernel, linux-kernel, Frank.Li, allen.lkml, dave.jiang,
dmaengine, andriy.shevchenko
From: Suyuan Wang <stevewong@hust.edu.cn>
idma64_remove() frees the IRQ and then kills the channel tasklets, as
the comment there says, so that no tasklet scheduled by the interrupt
runs after removal:
for (i = 0; i < idma64->dma.chancnt; i++) {
...
tasklet_kill(&idma64c->vchan.task);
}
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 when this loop runs and no tasklet is killed. A tasklet
scheduled by an interrupt can then run after the devm-allocated idma64
and its channels have 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@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/idma64.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/idma64.c b/drivers/dma/idma64.c
index e3db213e564b..5d0df1defb14 100644
--- a/drivers/dma/idma64.c
+++ b/drivers/dma/idma64.c
@@ -604,6 +604,8 @@ static int idma64_probe(struct idma64_chip *chip)
static void idma64_remove(struct idma64_chip *chip)
{
struct idma64 *idma64 = chip->idma64;
+ /* dma_async_device_unregister() decrements dma.chancnt to 0 */
+ unsigned short nr_chan = idma64->dma.chancnt;
unsigned short i;
dma_async_device_unregister(&idma64->dma);
@@ -614,7 +616,7 @@ static void idma64_remove(struct idma64_chip *chip)
*/
devm_free_irq(chip->dev, chip->irq, idma64);
- for (i = 0; i < idma64->dma.chancnt; i++) {
+ for (i = 0; i < nr_chan; i++) {
struct idma64_chan *idma64c = &idma64->chan[i];
tasklet_kill(&idma64c->vchan.task);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] dmaengine: idma64: Kill the channel tasklets in remove again
2026-11-23 0:53 ` [PATCH 2/2] dmaengine: idma64: " Suyuan Wang via B4 Relay
@ 2026-11-23 9:47 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-11-23 9:47 UTC (permalink / raw)
To: shyckless
Cc: vkoul, ludovic.desroches, linux-arm-kernel, linux-kernel,
Frank.Li, allen.lkml, dave.jiang, dmaengine
On Mon, Nov 23, 2026 at 12:53:07AM +0000, Suyuan Wang via B4 Relay wrote:
>
> idma64_remove() frees the IRQ and then kills the channel tasklets, as
> the comment there says, so that no tasklet scheduled by the interrupt
> runs after removal:
>
> for (i = 0; i < idma64->dma.chancnt; i++) {
> ...
> tasklet_kill(&idma64c->vchan.task);
> }
>
> 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 when this loop runs and no tasklet is killed. A tasklet
> scheduled by an interrupt can then run after the devm-allocated idma64
> and its channels have been freed.
>
> Read the channel count before unregistering the device.
>
> Found with a static analysis tool and checked by hand.
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
...
> + /* dma_async_device_unregister() decrements dma.chancnt to 0 */
> + unsigned short nr_chan = idma64->dma.chancnt;
Which makes me think that we need to draw a line between private and
non-private members in the respective DMA data types. With this field
it's probably better to mark it with __private, or add another one
with that annotation and use it internally in DMAengine core.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-23 9:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 0:53 [PATCH 0/2] dmaengine: Kill channel tasklets in remove again Suyuan Wang via B4 Relay
2026-11-23 0:53 ` [PATCH 1/2] dmaengine: at_xdmac: Kill the " Suyuan Wang via B4 Relay
2026-11-23 0:53 ` [PATCH 2/2] dmaengine: idma64: " Suyuan Wang via B4 Relay
2026-11-23 9:47 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox