* [PATCH] dmaengine: sprd: Fix channel unregistration on remove
@ 2026-12-03 6:28 Yige Jiang
0 siblings, 0 replies; only message in thread
From: Yige Jiang @ 2026-12-03 6:28 UTC (permalink / raw)
To: Vinod Koul, Orson Zhai
Cc: Yige Jiang, Frank Li, Baolin Wang, Chunyan Zhang, dmaengine,
linux-kernel, stable
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@vger.kernel.org
Link: https://lore.kernel.org/all/20260727210723.200551F000E9@smtp.kernel.org/
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-03 6:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 6:28 [PATCH] dmaengine: sprd: Fix channel unregistration on remove Yige Jiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox