* [PATCH v2 0/2] dmaengine: stm32-dma3: fix provider and clock teardown @ 2026-11-10 0:42 mhun512 2026-11-10 1:03 ` [PATCH v2 1/2] dmaengine: stm32-dma3: unregister the OF DMA provider on removal Myeonghun Pak 2026-11-10 1:05 ` [PATCH v2 2/2] dmaengine: stm32-dma3: defer clock cleanup to managed teardown Myeonghun Pak 0 siblings, 2 replies; 5+ messages in thread From: mhun512 @ 2026-11-10 0:42 UTC (permalink / raw) To: amelie.delaunay, vkoul, dmaengine Cc: Frank.Li, mcoquelin.stm32, alexandre.torgue, linux-stm32, linux-arm-kernel, linux-kernel, ae878000 Split OF provider teardown from the managed clock cleanup requested in the review of the original patch. Patch 1 unregisters the provider on removal; patch 2 returns the active clock reference after managed DMA/IRQ teardown. Keep the existing remove-time runtime PM disable barrier. Check initial PM activation failure, and let devres handle later probe failures. Remove the manual IRQ-free loop from the original submission. No hardware runtime testing. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] dmaengine: stm32-dma3: unregister the OF DMA provider on removal 2026-11-10 0:42 [PATCH v2 0/2] dmaengine: stm32-dma3: fix provider and clock teardown mhun512 @ 2026-11-10 1:03 ` Myeonghun Pak 2026-11-16 21:17 ` Frank Li 2026-11-10 1:05 ` [PATCH v2 2/2] dmaengine: stm32-dma3: defer clock cleanup to managed teardown Myeonghun Pak 1 sibling, 1 reply; 5+ messages in thread From: Myeonghun Pak @ 2026-11-10 1:03 UTC (permalink / raw) To: amelie.delaunay, vkoul, dmaengine Cc: Frank.Li, mcoquelin.stm32, alexandre.torgue, linux-stm32, linux-arm-kernel, linux-kernel, ae878000 Probe registers an OF DMA controller, but remove does not unregister it. The OF DMA helpers retain the driver's data pointer after managed cleanup frees it, leaving a stale provider entry for subsequent channel requests. Unregister the OF DMA controller before tearing down the device resources. There are no fallible operations after its registration in probe, so no matching probe error path is needed. Fixes: f561ec8b2b33 ("dmaengine: Add STM32 DMA3 support") Co-developed-by: Ijae Kim <ae878000@gmail.com> Signed-off-by: Ijae Kim <ae878000@gmail.com> Signed-off-by: Myeonghun Pak <mhun512@gmail.com> --- 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 @@ -1921,6 +1921,7 @@ static void stm32_dma3_remove(struct platform_device *pdev) { + of_dma_controller_free(pdev->dev.of_node); pm_runtime_disable(&pdev->dev); } On Tue, 10 Nov 2026 00:42:55 +0000, mhun512@gmail.com wrote: > Split OF provider teardown from the managed clock cleanup requested in the > review of the original patch. Patch 1 unregisters the provider on removal; > patch 2 returns the active clock reference after managed DMA/IRQ teardown. > > Keep the existing remove-time runtime PM disable barrier. Check initial PM > activation failure, and let devres handle later probe failures. Remove the > manual IRQ-free loop from the original submission. > > No hardware runtime testing. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] dmaengine: stm32-dma3: unregister the OF DMA provider on removal 2026-11-10 1:03 ` [PATCH v2 1/2] dmaengine: stm32-dma3: unregister the OF DMA provider on removal Myeonghun Pak @ 2026-11-16 21:17 ` Frank Li 0 siblings, 0 replies; 5+ messages in thread From: Frank Li @ 2026-11-16 21:17 UTC (permalink / raw) To: Myeonghun Pak Cc: amelie.delaunay, vkoul, dmaengine, Frank.Li, mcoquelin.stm32, alexandre.torgue, linux-stm32, linux-arm-kernel, linux-kernel, ae878000 On Mon, Nov 09, 2026 at 07:03:42PM -0600, Myeonghun Pak wrote: > Probe registers an OF DMA controller, but remove does not unregister it. > The OF DMA helpers retain the driver's data pointer after managed cleanup > frees it, leaving a stale provider entry for subsequent channel requests. > > Unregister the OF DMA controller before tearing down the device resources. > There are no fallible operations after its registration in probe, so no > matching probe error path is needed. > > Fixes: f561ec8b2b33 ("dmaengine: Add STM32 DMA3 support") > > Co-developed-by: Ijae Kim <ae878000@gmail.com> > Signed-off-by: Ijae Kim <ae878000@gmail.com> > Signed-off-by: Myeonghun Pak <mhun512@gmail.com> > --- > 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 > @@ -1921,6 +1921,7 @@ > > static void stm32_dma3_remove(struct platform_device *pdev) > { > + of_dma_controller_free(pdev->dev.of_node); devm_of_dma_controller_register() to fix this Frank > pm_runtime_disable(&pdev->dev); > } > > > > On Tue, 10 Nov 2026 00:42:55 +0000, mhun512@gmail.com wrote: > > Split OF provider teardown from the managed clock cleanup requested in the > > review of the original patch. Patch 1 unregisters the provider on removal; > > patch 2 returns the active clock reference after managed DMA/IRQ teardown. > > > > Keep the existing remove-time runtime PM disable barrier. Check initial PM > > activation failure, and let devres handle later probe failures. Remove the > > manual IRQ-free loop from the original submission. > > > > No hardware runtime testing. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] dmaengine: stm32-dma3: defer clock cleanup to managed teardown 2026-11-10 0:42 [PATCH v2 0/2] dmaengine: stm32-dma3: fix provider and clock teardown mhun512 2026-11-10 1:03 ` [PATCH v2 1/2] dmaengine: stm32-dma3: unregister the OF DMA provider on removal Myeonghun Pak @ 2026-11-10 1:05 ` Myeonghun Pak 2026-11-16 21:35 ` Frank Li 1 sibling, 1 reply; 5+ messages in thread From: Myeonghun Pak @ 2026-11-10 1:05 UTC (permalink / raw) To: amelie.delaunay, vkoul, dmaengine Cc: Frank.Li, mcoquelin.stm32, alexandre.torgue, linux-stm32, linux-arm-kernel, linux-kernel, ae878000 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@gmail.com> Signed-off-by: Ijae Kim <ae878000@gmail.com> Signed-off-by: Myeonghun Pak <mhun512@gmail.com> --- 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) ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] dmaengine: stm32-dma3: defer clock cleanup to managed teardown 2026-11-10 1:05 ` [PATCH v2 2/2] dmaengine: stm32-dma3: defer clock cleanup to managed teardown Myeonghun Pak @ 2026-11-16 21:35 ` Frank Li 0 siblings, 0 replies; 5+ messages in thread From: Frank Li @ 2026-11-16 21:35 UTC (permalink / raw) To: Myeonghun Pak Cc: amelie.delaunay, vkoul, dmaengine, Frank.Li, mcoquelin.stm32, alexandre.torgue, linux-stm32, linux-arm-kernel, linux-kernel, ae878000 On Tue, Nov 10, 2026 at 01:05:14AM +0000, Myeonghun Pak wrote: > 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@gmail.com> > Signed-off-by: Ijae Kim <ae878000@gmail.com> > Signed-off-by: Myeonghun Pak <mhun512@gmail.com> > --- > 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; devm_clk_bulk_get_enable() if (devm_pm_runtime_set_active_enabled()) { ... } At remove function { pm_runtime_get_sync(&pdev->dev); ... pm_runtime_put_noidle(&pdev->dev); //return pm count drop to 0, devm_clk*() will disable clock for you } Frank > > 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) ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-16 21:35 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-10 0:42 [PATCH v2 0/2] dmaengine: stm32-dma3: fix provider and clock teardown mhun512 2026-11-10 1:03 ` [PATCH v2 1/2] dmaengine: stm32-dma3: unregister the OF DMA provider on removal Myeonghun Pak 2026-11-16 21:17 ` Frank Li 2026-11-10 1:05 ` [PATCH v2 2/2] dmaengine: stm32-dma3: defer clock cleanup to managed teardown Myeonghun Pak 2026-11-16 21:35 ` Frank Li
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®