* [PATCH 1/3] dmaengine: stm32-dmamux: Unregister the DMA router on removal
2026-11-27 11:33 [PATCH 0/3] dmaengine: stm32: Pair DMA provider registration with cleanup Tian Xuechen
@ 2026-11-27 11:33 ` Tian Xuechen
2026-11-27 11:50 ` sashiko-bot
2026-11-27 15:15 ` Frank Li
2026-11-27 11:33 ` [PATCH 2/3] dmaengine: stm32-dma: Unregister the OF controller and DMA device Tian Xuechen
` (2 subsequent siblings)
3 siblings, 2 replies; 9+ messages in thread
From: Tian Xuechen @ 2026-11-27 11:33 UTC (permalink / raw)
To: amelie.delaunay, vkoul, mcoquelin.stm32, alexandre.torgue,
cedric.madianga, pierre-yves.mordret
Cc: Frank.Li, dmaengine, linux-stm32, linux-arm-kernel
From: Tian Xuechen <202300460064@mail.sdu.edu.cn>
The DMA router remains in the OF registry after its device-managed
data is released. Remove the routing entry when the device is
unbound.
This issue was found by our static analysis tool under development.
Fixes: df7e762db5f6 ("dmaengine: Add STM32 DMAMUX driver")
Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
---
drivers/dma/stm32/stm32-dmamux.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/dma/stm32/stm32-dmamux.c b/drivers/dma/stm32/stm32-dmamux.c
index 57318715d9f3..6f49d78bfe3d 100644
--- a/drivers/dma/stm32/stm32-dmamux.c
+++ b/drivers/dma/stm32/stm32-dmamux.c
@@ -389,8 +389,14 @@ static const struct of_device_id stm32_dmamux_match[] = {
{},
};
+static void stm32_dmamux_remove(struct platform_device *pdev)
+{
+ of_dma_router_free(pdev->dev.of_node);
+}
+
static struct platform_driver stm32_dmamux_driver = {
.probe = stm32_dmamux_probe,
+ .remove = stm32_dmamux_remove,
.driver = {
.name = "stm32-dmamux",
.of_match_table = stm32_dmamux_match,
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 1/3] dmaengine: stm32-dmamux: Unregister the DMA router on removal
2026-11-27 11:33 ` [PATCH 1/3] dmaengine: stm32-dmamux: Unregister the DMA router on removal Tian Xuechen
@ 2026-11-27 11:50 ` sashiko-bot
2026-11-27 15:15 ` Frank Li
1 sibling, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-27 11:50 UTC (permalink / raw)
To: Tian Xuechen; +Cc: dmaengine, vkoul, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dmaengine: stm32-dmamux: missing PM and clock cleanup in
stm32_dmamux_remove()
--
commit 01371409f62942bd0d2c67aaa136651d1d8545c7
Author: Tian Xuechen <202300460064@mail.sdu.edu.cn>
dmaengine: stm32-dmamux: Unregister the DMA router on removal
This commit adds a platform driver remove callback to unregister the OF
DMA router when the stm32-dmamux device is unbound.
> diff --git a/drivers/dma/stm32/stm32-dmamux.c b/drivers/dma/stm32/stm32-dmamux.c
> index 57318715d9f34..6f49d78bfe3de 100644
> --- a/drivers/dma/stm32/stm32-dmamux.c
> +++ b/drivers/dma/stm32/stm32-dmamux.c
> @@ -389,8 +389,14 @@ static const struct of_device_id stm32_dmamux_match[] = {
> {},
> };
>
> +static void stm32_dmamux_remove(struct platform_device *pdev)
> +{
> + of_dma_router_free(pdev->dev.of_node);
> +}
> +
> static struct platform_driver stm32_dmamux_driver = {
> .probe = stm32_dmamux_probe,
> + .remove = stm32_dmamux_remove,
> .driver = {
> .name = "stm32-dmamux",
> .of_match_table = stm32_dmamux_match,
[Severity: Medium]
Should stm32_dmamux_remove() also disable runtime PM and unprepare
stm32_dmamux->clk?
stm32_dmamux_probe() enables the clock and runtime PM without devm helpers
and unwinds them on error:
drivers/dma/stm32/stm32-dmamux.c:stm32_dmamux_probe() {
...
ret = clk_prepare_enable(stm32_dmamux->clk);
...
pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev);
...
pm_disable:
pm_runtime_disable(&pdev->dev);
err_clk:
clk_disable_unprepare(stm32_dmamux->clk);
}
Without matching cleanup on removal, unbinding the device leaks the clock
prepare/enable reference and leaves runtime PM enabled on pdev->dev, which
causes a subsequent rebind to hit an unbalanced pm_runtime_enable()
warning.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127113332.390552-1-202300460064@mail.sdu.edu.cn?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 1/3] dmaengine: stm32-dmamux: Unregister the DMA router on removal
2026-11-27 11:33 ` [PATCH 1/3] dmaengine: stm32-dmamux: Unregister the DMA router on removal Tian Xuechen
2026-11-27 11:50 ` sashiko-bot
@ 2026-11-27 15:15 ` Frank Li
1 sibling, 0 replies; 9+ messages in thread
From: Frank Li @ 2026-11-27 15:15 UTC (permalink / raw)
To: Tian Xuechen
Cc: amelie.delaunay, vkoul, mcoquelin.stm32, alexandre.torgue,
cedric.madianga, pierre-yves.mordret, Frank.Li, dmaengine,
linux-stm32, linux-arm-kernel
On Fri, Nov 27, 2026 at 07:33:30PM +0800, Tian Xuechen wrote:
> From: Tian Xuechen <202300460064@mail.sdu.edu.cn>
>
> The DMA router remains in the OF registry after its device-managed
> data is released. Remove the routing entry when the device is
> unbound.
>
> This issue was found by our static analysis tool under development.
>
> Fixes: df7e762db5f6 ("dmaengine: Add STM32 DMAMUX driver")
> Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
> ---
> drivers/dma/stm32/stm32-dmamux.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/dma/stm32/stm32-dmamux.c b/drivers/dma/stm32/stm32-dmamux.c
> index 57318715d9f3..6f49d78bfe3d 100644
> --- a/drivers/dma/stm32/stm32-dmamux.c
> +++ b/drivers/dma/stm32/stm32-dmamux.c
> @@ -389,8 +389,14 @@ static const struct of_device_id stm32_dmamux_match[] = {
> {},
> };
>
> +static void stm32_dmamux_remove(struct platform_device *pdev)
> +{
> + of_dma_router_free(pdev->dev.of_node);
> +}
> +
Add dev manage API for router_register()
Frank
> static struct platform_driver stm32_dmamux_driver = {
> .probe = stm32_dmamux_probe,
> + .remove = stm32_dmamux_remove,
> .driver = {
> .name = "stm32-dmamux",
> .of_match_table = stm32_dmamux_match,
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/3] dmaengine: stm32-dma: Unregister the OF controller and DMA device
2026-11-27 11:33 [PATCH 0/3] dmaengine: stm32: Pair DMA provider registration with cleanup Tian Xuechen
2026-11-27 11:33 ` [PATCH 1/3] dmaengine: stm32-dmamux: Unregister the DMA router on removal Tian Xuechen
@ 2026-11-27 11:33 ` Tian Xuechen
2026-11-27 11:45 ` sashiko-bot
2026-11-27 15:14 ` Frank Li
2026-11-27 11:33 ` [PATCH 3/3] dmaengine: stm32-mdma: Use managed OF DMA controller registration Tian Xuechen
2026-11-27 14:48 ` [PATCH 0/3] dmaengine: stm32: Pair DMA provider registration with cleanup Amelie Delaunay
3 siblings, 2 replies; 9+ messages in thread
From: Tian Xuechen @ 2026-11-27 11:33 UTC (permalink / raw)
To: amelie.delaunay, vkoul, mcoquelin.stm32, alexandre.torgue,
cedric.madianga, pierre-yves.mordret
Cc: Frank.Li, dmaengine, linux-stm32, linux-arm-kernel
From: Tian Xuechen <202300460064@mail.sdu.edu.cn>
The OF controller and DMA engine remain registered after the driver
releases its channel data. Unregister both in reverse order when the
device is removed.
This issue was found by our static analysis tool under development.
Fixes: d8b468394fb7 ("dmaengine: Add STM32 DMA driver")
Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
---
drivers/dma/stm32/stm32-dma.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/dma/stm32/stm32-dma.c b/drivers/dma/stm32/stm32-dma.c
index ba8121d37f51..6392c15b4317 100644
--- a/drivers/dma/stm32/stm32-dma.c
+++ b/drivers/dma/stm32/stm32-dma.c
@@ -1761,6 +1761,14 @@ static const struct dev_pm_ops stm32_dma_pm_ops = {
stm32_dma_runtime_resume, NULL)
};
+static void stm32_dma_remove(struct platform_device *pdev)
+{
+ struct stm32_dma_device *dmadev = platform_get_drvdata(pdev);
+
+ of_dma_controller_free(pdev->dev.of_node);
+ dma_async_device_unregister(&dmadev->ddev);
+}
+
static struct platform_driver stm32_dma_driver = {
.driver = {
.name = "stm32-dma",
@@ -1768,6 +1776,7 @@ static struct platform_driver stm32_dma_driver = {
.pm = &stm32_dma_pm_ops,
},
.probe = stm32_dma_probe,
+ .remove = stm32_dma_remove,
};
static int __init stm32_dma_init(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 2/3] dmaengine: stm32-dma: Unregister the OF controller and DMA device
2026-11-27 11:33 ` [PATCH 2/3] dmaengine: stm32-dma: Unregister the OF controller and DMA device Tian Xuechen
@ 2026-11-27 11:45 ` sashiko-bot
2026-11-27 15:14 ` Frank Li
1 sibling, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-27 11:45 UTC (permalink / raw)
To: Tian Xuechen; +Cc: dmaengine, vkoul, Frank.Li
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] dmaengine: stm32-dma: UAF on chan_dev and active tasklets in
stm32_dma_remove()
- [Medium] dmaengine: stm32-dma: missing runtime PM and clk cleanup in
stm32_dma_remove()
--
commit 30243559befe605128a60fd875a8d108b7d34bc8
Author: Tian Xuechen <202300460064@mail.sdu.edu.cn>
dmaengine: stm32-dma: Unregister the OF controller and DMA device
This commit adds a platform driver remove callback to unregister the OF
DMA controller and the DMA engine device upon driver removal.
> diff --git a/drivers/dma/stm32/stm32-dma.c b/drivers/dma/stm32/stm32-dma.c
> index ba8121d37f51d..6392c15b43175 100644
> --- a/drivers/dma/stm32/stm32-dma.c
> +++ b/drivers/dma/stm32/stm32-dma.c
> @@ -1761,6 +1761,14 @@ static const struct dev_pm_ops stm32_dma_pm_ops = {
> stm32_dma_runtime_resume, NULL)
> };
>
> +static void stm32_dma_remove(struct platform_device *pdev)
> +{
> + struct stm32_dma_device *dmadev = platform_get_drvdata(pdev);
> +
> + of_dma_controller_free(pdev->dev.of_node);
> + dma_async_device_unregister(&dmadev->ddev);
[Severity: High]
Does unregistering dmadev->ddev here cause a use-after-free on each
channel's chan_dev while the devm-managed channel IRQs and vchan tasklets
are still active?
In stm32_dma_probe(), dma_async_device_register() allocates each channel's
chan_dev and its kobject name, and devm_request_irq() then passes
vchan_chan_name(&chan->vchan) directly as the IRQ action name without
copying it:
drivers/dma/stm32/stm32-dma.c:stm32_dma_probe() {
...
vchan_init(&chan->vchan, dd);
...
ret = dma_async_device_register(dd);
if (ret)
goto clk_free;
for (i = 0; i < STM32_DMA_MAX_CHANNELS; i++) {
...
ret = devm_request_irq(&pdev->dev, chan->irq,
stm32_dma_chan_irq, 0,
vchan_chan_name(&chan->vchan), chan);
...
}
When stm32_dma_remove() calls dma_async_device_unregister(),
__dma_async_device_channel_unregister() unregisters and frees each
chan_dev and its kobj.name before devres_release_all() frees the IRQs.
Until devres tears down the IRQs, every channel's irqaction->name is a
dangling pointer (exposed via /proc/interrupts), and any interrupt firing
in stm32_dma_chan_irq() dereferences freed chan_dev memory via
vchan_chan_dev(&chan->vchan). In addition, nothing stops active channels
or kills chan->vchan.task before devres frees dmadev.
> +}
[Severity: Medium]
Should stm32_dma_remove() also disable runtime PM and balance the clock
prepared and enabled in stm32_dma_probe()?
stm32_dma_probe() enables dmadev->clk with unmanaged clk_prepare_enable()
and enables runtime PM with unmanaged pm_runtime_enable(), relying on
stm32_dma_runtime_suspend() to disable the clock. Without
pm_runtime_disable() and clk_disable_unprepare() in stm32_dma_remove(),
unbinding the driver when the device is runtime-active (or when CONFIG_PM
is disabled) leaks the clock prepare and enable references. Leaving
runtime PM enabled also skips the runtime PM barrier during unbind, so
pending asynchronous runtime suspend work can race with devres freeing
dmadev and cause a subsequent re-probe to fail pm_runtime_set_active()
and trigger an unbalanced pm_runtime_enable() warning.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127113332.390552-1-202300460064@mail.sdu.edu.cn?part=2
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 2/3] dmaengine: stm32-dma: Unregister the OF controller and DMA device
2026-11-27 11:33 ` [PATCH 2/3] dmaengine: stm32-dma: Unregister the OF controller and DMA device Tian Xuechen
2026-11-27 11:45 ` sashiko-bot
@ 2026-11-27 15:14 ` Frank Li
1 sibling, 0 replies; 9+ messages in thread
From: Frank Li @ 2026-11-27 15:14 UTC (permalink / raw)
To: Tian Xuechen
Cc: amelie.delaunay, vkoul, mcoquelin.stm32, alexandre.torgue,
cedric.madianga, pierre-yves.mordret, Frank.Li, dmaengine,
linux-stm32, linux-arm-kernel
On Fri, Nov 27, 2026 at 07:33:31PM +0800, Tian Xuechen wrote:
> From: Tian Xuechen <202300460064@mail.sdu.edu.cn>
>
> The OF controller and DMA engine remain registered after the driver
> releases its channel data. Unregister both in reverse order when the
> device is removed.
>
> This issue was found by our static analysis tool under development.
>
> Fixes: d8b468394fb7 ("dmaengine: Add STM32 DMA driver")
> Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
> ---
> drivers/dma/stm32/stm32-dma.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/dma/stm32/stm32-dma.c b/drivers/dma/stm32/stm32-dma.c
> index ba8121d37f51..6392c15b4317 100644
> --- a/drivers/dma/stm32/stm32-dma.c
> +++ b/drivers/dma/stm32/stm32-dma.c
> @@ -1761,6 +1761,14 @@ static const struct dev_pm_ops stm32_dma_pm_ops = {
> stm32_dma_runtime_resume, NULL)
> };
>
> +static void stm32_dma_remove(struct platform_device *pdev)
> +{
> + struct stm32_dma_device *dmadev = platform_get_drvdata(pdev);
> +
> + of_dma_controller_free(pdev->dev.of_node);
> + dma_async_device_unregister(&dmadev->ddev);
> +}
> +
Please use manange APIs to fix this problem
Frank
> static struct platform_driver stm32_dma_driver = {
> .driver = {
> .name = "stm32-dma",
> @@ -1768,6 +1776,7 @@ static struct platform_driver stm32_dma_driver = {
> .pm = &stm32_dma_pm_ops,
> },
> .probe = stm32_dma_probe,
> + .remove = stm32_dma_remove,
> };
>
> static int __init stm32_dma_init(void)
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/3] dmaengine: stm32-mdma: Use managed OF DMA controller registration
2026-11-27 11:33 [PATCH 0/3] dmaengine: stm32: Pair DMA provider registration with cleanup Tian Xuechen
2026-11-27 11:33 ` [PATCH 1/3] dmaengine: stm32-dmamux: Unregister the DMA router on removal Tian Xuechen
2026-11-27 11:33 ` [PATCH 2/3] dmaengine: stm32-dma: Unregister the OF controller and DMA device Tian Xuechen
@ 2026-11-27 11:33 ` Tian Xuechen
2026-11-27 14:48 ` [PATCH 0/3] dmaengine: stm32: Pair DMA provider registration with cleanup Amelie Delaunay
3 siblings, 0 replies; 9+ messages in thread
From: Tian Xuechen @ 2026-11-27 11:33 UTC (permalink / raw)
To: amelie.delaunay, vkoul, mcoquelin.stm32, alexandre.torgue,
cedric.madianga, pierre-yves.mordret
Cc: Frank.Li, dmaengine, linux-stm32, linux-arm-kernel
From: Tian Xuechen <202300460064@mail.sdu.edu.cn>
The OF controller outlives the managed DMA engine and its channel
data on removal. Use the managed registration helper to withdraw the
OF controller first.
This issue was found by our static analysis tool under development.
Fixes: a4ffb13c8946 ("dmaengine: Add STM32 MDMA driver")
Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
---
drivers/dma/stm32/stm32-mdma.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/stm32/stm32-mdma.c b/drivers/dma/stm32/stm32-mdma.c
index 4851c1c7ce0c..c95a9bb1171b 100644
--- a/drivers/dma/stm32/stm32-mdma.c
+++ b/drivers/dma/stm32/stm32-mdma.c
@@ -1714,7 +1714,8 @@ static int stm32_mdma_probe(struct platform_device *pdev)
if (ret)
goto err_clk;
- ret = of_dma_controller_register(of_node, stm32_mdma_of_xlate, dmadev);
+ ret = devm_of_dma_controller_register(&pdev->dev, of_node,
+ stm32_mdma_of_xlate, dmadev);
if (ret < 0) {
dev_err(&pdev->dev,
"STM32 MDMA DMA OF registration failed %d\n", ret);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 0/3] dmaengine: stm32: Pair DMA provider registration with cleanup
2026-11-27 11:33 [PATCH 0/3] dmaengine: stm32: Pair DMA provider registration with cleanup Tian Xuechen
` (2 preceding siblings ...)
2026-11-27 11:33 ` [PATCH 3/3] dmaengine: stm32-mdma: Use managed OF DMA controller registration Tian Xuechen
@ 2026-11-27 14:48 ` Amelie Delaunay
3 siblings, 0 replies; 9+ messages in thread
From: Amelie Delaunay @ 2026-11-27 14:48 UTC (permalink / raw)
To: Tian Xuechen, vkoul, mcoquelin.stm32, alexandre.torgue,
cedric.madianga, pierre-yves.mordret
Cc: Frank.Li, dmaengine, linux-stm32, linux-arm-kernel
Hi,
On 11/27/26 12:33, Tian Xuechen wrote:
> From: Tian Xuechen <202300460064@mail.sdu.edu.cn>
>
> Unregister the STM32 DMA mux, DMA and MDMA providers when their devices
> are removed.
>
> Tian Xuechen (3):
> dmaengine: stm32-dmamux: Unregister the DMA router on removal
> dmaengine: stm32-dma: Unregister the OF controller and DMA device
> dmaengine: stm32-mdma: Use managed OF DMA controller registration
>
> base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
These built-in drivers are not intended to be unbound at runtime.
STM32 DMAMUX routes peripherals DMA requests to STM32 DMA, and STM32 DMA
and MDMA channels may also be chained.
Rather than adding partial removal support, I think we should set
".suppress_bind_attrs = true" for stm32_dmamux_driver, stm32_dma_driver
and stm32_mdma_driver to prevent manual bind/unbind through sysfs.
Regards,
Amelie
^ permalink raw reply [flat|nested] 9+ messages in thread