[PATCH v2 2/2] dmaengine: stm32-dma3: defer clock cleanup to managed teardown

From: Myeonghun Pak

Date: Mon Nov 09 2026 - 20:06:59 EST


Probe enables the controller clock, but remove only disables runtime PM.
Disabling runtime PM does not invoke runtime suspend, so removal of an
active controller leaves its clock prepare and enable references held.
Probe error paths also disable the clock before managed DMA registration
and IRQ resources have been released.

Register a clock cleanup action before acquiring those managed resources.
Keep the existing remove-time runtime PM disable barrier, and let devres
release the remaining clock reference after the DMA and IRQ resources.
Skip the clock disable if runtime suspend has already released it, then
mark the device suspended. The PM stubs also cover CONFIG_PM=n.

Set the initial runtime PM state next to clock enable so that probe unwind
can distinguish that reference from a runtime-suspended device. If setting
the state fails, release the clock immediately and return the error.
Use direct error returns once devres owns the remaining cleanup.

Fixes: f561ec8b2b33 ("dmaengine: Add STM32 DMA3 support")

Co-developed-by: Ijae Kim <ae878000@xxxxxxxxx>
Signed-off-by: Ijae Kim <ae878000@xxxxxxxxx>
Signed-off-by: Myeonghun Pak <mhun512@xxxxxxxxx>
---
No hardware runtime testing.

diff --git a/drivers/dma/stm32/stm32-dma3.c b/drivers/dma/stm32/stm32-dma3.c
--- a/drivers/dma/stm32/stm32-dma3.c
+++ b/drivers/dma/stm32/stm32-dma3.c
@@ -1721,6 +1721,16 @@
};
MODULE_DEVICE_TABLE(of, stm32_dma3_of_match);

+static void stm32_dma3_clk_disable(void *data)
+{
+ struct device *dev = data;
+ struct stm32_dma3_ddata *ddata = dev_get_drvdata(dev);
+
+ if (!pm_runtime_status_suspended(dev))
+ clk_disable_unprepare(ddata->clk);
+ pm_runtime_set_suspended(dev);
+}
+
static int stm32_dma3_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
@@ -1755,6 +1765,16 @@
ret = clk_prepare_enable(ddata->clk);
if (ret)
return dev_err_probe(&pdev->dev, ret, "Failed to enable clk\n");
+
+ ret = pm_runtime_set_active(&pdev->dev);
+ if (ret) {
+ clk_disable_unprepare(ddata->clk);
+ return ret;
+ }
+ /* Release the clock after the managed DMA device and channel IRQs. */
+ ret = devm_add_action_or_reset(&pdev->dev, stm32_dma3_clk_disable,
&pdev->dev);
+ if (ret)
+ return ret;

reset_control_reset(reset);

@@ -1831,17 +1851,15 @@

ddata->chans = devm_kcalloc(&pdev->dev, ddata->dma_channels,
sizeof(*ddata->chans),
GFP_KERNEL);
- if (!ddata->chans) {
- ret = -ENOMEM;
- goto err_clk_disable;
- }
+ if (!ddata->chans)
+ return -ENOMEM;

chan_reserved = stm32_dma3_check_rif(ddata);

if (chan_reserved == GENMASK(ddata->dma_channels - 1, 0)) {
ret = -ENODEV;
dev_err_probe(&pdev->dev, ret, "No channel available, abort registration\n");
- goto err_clk_disable;
+ return ret;
}

/* G_FIFO_SIZE x=0..7 in HWCFGR3 and G_FIFO_SIZE x=8..15 in HWCFGR4 */
@@ -1861,7 +1879,7 @@

ret = dmaenginem_async_device_register(dma_dev);
if (ret)
- goto err_clk_disable;
+ return ret;

for (i = 0; i < ddata->dma_channels; i++) {
char name[12];
@@ -1878,12 +1896,12 @@
ret = dma_async_device_channel_register(&ddata->dma_dev,
&chan->vchan.chan, name);
if (ret) {
dev_err_probe(&pdev->dev, ret, "Failed to register channel %s\n", name);
- goto err_clk_disable;
+ return ret;
}

ret = platform_get_irq(pdev, i);
if (ret < 0)
- goto err_clk_disable;
+ return ret;
chan->irq = ret;

ret = devm_request_irq(&pdev->dev, chan->irq, stm32_dma3_chan_irq, 0,
@@ -1891,19 +1909,18 @@
if (ret) {
dev_err_probe(&pdev->dev, ret, "Failed to request channel %s IRQ\n",
vchan_chan_name(&chan->vchan));
- goto err_clk_disable;
+ return ret;
}
}

ret = of_dma_controller_register(np, stm32_dma3_of_xlate, ddata);
if (ret) {
dev_err_probe(&pdev->dev, ret, "Failed to register controller\n");
- goto err_clk_disable;
+ return ret;
}

verr = readl_relaxed(ddata->base + STM32_DMA3_VERR);

- pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev);
pm_runtime_get_noresume(&pdev->dev);
pm_runtime_put(&pdev->dev);
@@ -1912,11 +1929,6 @@
FIELD_GET(VERR_MAJREV, verr), FIELD_GET(VERR_MINREV, verr));

return 0;
-
-err_clk_disable:
- clk_disable_unprepare(ddata->clk);
-
- return ret;
}

static void stm32_dma3_remove(struct platform_device *pdev)