[PATCH v2 2/2] dmaengine: idma64: Kill the channel tasklets in remove again

From: Suyuan Wang via B4 Relay

Date: Sun Nov 22 2026 - 20:17:50 EST


From: Suyuan Wang <stevewong@xxxxxxxxxxx>

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@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/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