DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tian Xuechen" <202300460064@mail.sdu.edu.cn>
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH 2/3] dmaengine: stm32-dma: Unregister the OF controller and DMA device
Date: Fri, 27 Nov 2026 11:45:44 +0000	[thread overview]
Message-ID: <sashiko-outbox-237272@kernel.org> (raw)
In-Reply-To: <20261127113332.390552-3-202300460064@mail.sdu.edu.cn>

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

  reply	other threads:[~2026-11-27 11:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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:50   ` sashiko-bot
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 [this message]
2026-11-27 11:33 ` [PATCH 3/3] dmaengine: stm32-mdma: Use managed OF DMA controller registration Tian Xuechen

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=sashiko-outbox-237272@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=202300460064@mail.sdu.edu.cn \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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