[PATCH] dmaengine: sprd: Fix channel unregistration on remove

From: Yige Jiang

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


sprd_dma_remove() deletes every channel from sdev->dma_dev.channels
before calling dma_async_device_unregister(). The latter walks that
same list to unregister the channel devices, so it finds none. The
dma<N>chan<M> devices remain registered and their chan_dev->chan
pointers are not cleared.

Devres then frees sdev, 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.

Keep the channels on the list and only kill their tasklets in remove.
The interrupt has already been freed, so it cannot schedule more
tasklets. dma_async_device_unregister() can then clear chan_dev->chan
and unregister the channel devices before sdev is freed.

Fixes: 9b3b8171f7f4 ("dmaengine: sprd: Add Spreadtrum DMA driver")
Cc: stable@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/all/20260727210723.200551F000E9@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_SPRD_DMA=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/sprd-dma.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c
index 60b3067a009945953b9f971fed34a3e2e628c250..9e485ef0b998ced3a80429ac33100b546423bd1d 100644
--- a/drivers/dma/sprd-dma.c
+++ b/drivers/dma/sprd-dma.c
@@ -1222,7 +1222,7 @@ err_register:
static void sprd_dma_remove(struct platform_device *pdev)
{
struct sprd_dma_dev *sdev = platform_get_drvdata(pdev);
- struct sprd_dma_chn *c, *cn;
+ struct sprd_dma_chn *c;

pm_runtime_get_sync(&pdev->dev);

@@ -1230,11 +1230,8 @@ static void sprd_dma_remove(struct platform_device *pdev)
if (sdev->irq > 0)
devm_free_irq(&pdev->dev, sdev->irq, sdev);

- list_for_each_entry_safe(c, cn, &sdev->dma_dev.channels,
- vc.chan.device_node) {
- list_del(&c->vc.chan.device_node);
+ list_for_each_entry(c, &sdev->dma_dev.channels, vc.chan.device_node)
tasklet_kill(&c->vc.task);
- }

of_dma_controller_free(pdev->dev.of_node);
dma_async_device_unregister(&sdev->dma_dev);

base-commit: 2e02fb103be058cf8b2fb24112a74a2715e090f0