* [PATCH] dmaengine: sprd: Fix channel unregistration on remove
@ 2026-12-03 6:28 Yige Jiang
2026-12-03 17:06 ` Frank Li
0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread* Re: [PATCH] dmaengine: sprd: Fix channel unregistration on remove
2026-12-03 6:28 [PATCH] dmaengine: sprd: Fix channel unregistration on remove Yige Jiang
@ 2026-12-03 17:06 ` Frank Li
0 siblings, 0 replies; 2+ messages in thread
From: Frank Li @ 2026-12-03 17:06 UTC (permalink / raw)
To: Yige Jiang
Cc: Vinod Koul, Orson Zhai, Frank Li, Baolin Wang, Chunyan Zhang,
dmaengine, linux-kernel, stable
On Thu, Dec 03, 2026 at 02:28:09PM +0800, Yige Jiang wrote:
> 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>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.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 [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 17:07 UTC | newest]
Thread overview: 2+ messages (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
2026-12-03 17:06 ` Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox