From: Frank Li <Frank.li@oss.nxp.com>
To: Myeonghun Pak <mhun512@gmail.com>
Cc: amelie.delaunay@foss.st.com, vkoul@kernel.org,
dmaengine@vger.kernel.org, Frank.Li@kernel.org,
mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, ae878000@gmail.com
Subject: Re: [PATCH v2 2/2] dmaengine: stm32-dma3: defer clock cleanup to managed teardown
Date: Mon, 16 Nov 2026 15:35:23 -0600 [thread overview]
Message-ID: <avt3G8DLXbFgSfxi@SMW015318> (raw)
In-Reply-To: <CAGEsz8Hrng-rnKE8hVKUo0RZD484HuSUGc5rWWeGNa6JsdaKoA@mail.gmail.com>
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)
prev parent reply other threads:[~2026-11-16 21:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=avt3G8DLXbFgSfxi@SMW015318 \
--to=frank.li@oss.nxp.com \
--cc=Frank.Li@kernel.org \
--cc=ae878000@gmail.com \
--cc=alexandre.torgue@foss.st.com \
--cc=amelie.delaunay@foss.st.com \
--cc=dmaengine@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=mhun512@gmail.com \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox