[PATCH] dmaengine: dw-axi-dmac: Fix channel unregistration on remove

From: Yige Jiang

Date: Thu Dec 03 2026 - 01:28:19 EST


dw_remove() deletes every channel from dw->dma.channels. The managed
dma_async_device_unregister() subsequently walks that list to unregister
the channel devices. It finds none, leaving the dma<N>chan<M> devices
registered and their chan_dev->chan pointers uncleared.

Devres then frees dw->chan[], which embeds each dma_chan. Reading the
remaining channel devices' sysfs attributes can dereference freed
memory. The channel devices and their per-CPU counters also leak. The
list was already emptied too early before the conversion to managed
DMA device registration.

Keep the channels on the list and only kill their tasklets in remove.
The interrupts have already been freed, so they cannot schedule more
tasklets. The managed unregister can then clear chan_dev->chan and
unregister the channel devices before the channel array is freed.

Fixes: 1fe20f1b8454 ("dmaengine: Introduce DW AXI DMAC driver")
Cc: stable@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/all/20260727211146.D154F1F00A3A@xxxxxxxxxxxxxxx/
Signed-off-by: Yige Jiang <yigejiang86@xxxxxxxxx>
---
Based on dmaengine next as merged in next-20261201.
Compile-tested on next-20261104: arm64, GCC 14.2.0, W=1,
CONFIG_DW_AXI_DMAC=y and CONFIG_COMPILE_TEST=y.
Baseline and patched objects built without warnings.
The code changes are the same as in that build.
No hardware or runtime test was performed.

drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
index 7520c78f55ccf69294fdbc055d683469cf8c3078..cf8c4403d7ddae3bd0f3028098346e9a0a526d33 100644
--- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
+++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c
@@ -1630,7 +1630,7 @@ static void dw_remove(struct platform_device *pdev)
{
struct axi_dma_chip *chip = platform_get_drvdata(pdev);
struct dw_axi_dma *dw = chip->dw;
- struct axi_dma_chan *chan, *_chan;
+ struct axi_dma_chan *chan;
u32 i;
int ret;

@@ -1655,11 +1655,8 @@ static void dw_remove(struct platform_device *pdev)

of_dma_controller_free(chip->dev->of_node);

- list_for_each_entry_safe(chan, _chan, &dw->dma.channels,
- vc.chan.device_node) {
- list_del(&chan->vc.chan.device_node);
+ list_for_each_entry(chan, &dw->dma.channels, vc.chan.device_node)
tasklet_kill(&chan->vc.task);
- }
}

static const struct dev_pm_ops dw_axi_dma_pm_ops = {

base-commit: 2e02fb103be058cf8b2fb24112a74a2715e090f0