DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vladimir Zapolskiy" <vz@kernel.org>
Cc: vkoul@kernel.org, Frank.Li@kernel.org, dmaengine@vger.kernel.org
Subject: Re: [PATCH] dmaengine: mediatek: mtk-uart-apdma: Return -ENOMEM on memory allocation failure
Date: Wed, 01 Jul 2026 20:19:48 +0000	[thread overview]
Message-ID: <20260701201948.7FC101F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260701200703.117929-1-vz@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Resource leak due to incorrect cleanup order in `mtk_uart_apdma_remove`. `mtk_uart_apdma_free` empties the channel list before `dma_async_device_unregister` is called.
- [High] Unbalanced runtime PM usage count due to incorrect reference dropping in `mtk_uart_apdma_alloc_chan_resources`.
--

commit c96187ec35bc4ba2bbf2baf929c0cd8ec646f5d8
Author: Vladimir Zapolskiy <vz@kernel.org>
dmaengine: mediatek: mtk-uart-apdma: Return -ENOMEM on memory allocation failure

If dynamic memory allocation in driver's probe function execution fails, it
should be reported to the driver's framework with -ENOMEM error code.

> diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c
> index c269d84d7bd2b..f74e9a3285887 100644
> --- a/drivers/dma/mediatek/mtk-uart-apdma.c
> +++ b/drivers/dma/mediatek/mtk-uart-apdma.c
> @@ -531,7 +531,7 @@ static int mtk_uart_apdma_probe(struct platform_device *pdev)
>  	for (i = 0; i < mtkd->dma_requests; i++) {
>  		c = devm_kzalloc(mtkd->ddev.dev, sizeof(*c), GFP_KERNEL);
>  		if (!c) {
> -			rc = -ENODEV;
> +			rc = -ENOMEM;
>  			goto err_no_dma;
>  		}

[Severity: High]
This is a pre-existing issue, but does mtk_uart_apdma_remove() have a cleanup
ordering bug?

mtk_uart_apdma_remove() calls mtk_uart_apdma_free() before calling
dma_async_device_unregister():

drivers/dma/mediatek/mtk-uart-apdma.c:mtk_uart_apdma_remove() {
	...
	mtk_uart_apdma_free(mtkd);

	dma_async_device_unregister(&mtkd->ddev);
	...
}

However, mtk_uart_apdma_free() deletes the channels from the device's list:

drivers/dma/mediatek/mtk-uart-apdma.c:mtk_uart_apdma_free() {
	...
		list_del(&c->vc.chan.device_node);
	...
}

Will this cause dma_async_device_unregister() to find an empty channel list
and skip unregistering the channels, leading to a resource leak?

[Severity: High]
This is also a pre-existing issue, but does mtk_uart_apdma_alloc_chan_resources()
have an unbalanced runtime PM usage count?

If pm_runtime_resume_and_get() fails, it drops the reference it never
acquired, but the error path calls pm_runtime_put_noidle() anyway:

drivers/dma/mediatek/mtk-uart-apdma.c:mtk_uart_apdma_alloc_chan_resources() {
	...
	ret = pm_runtime_resume_and_get(mtkd->ddev.dev);
	if (ret < 0) {
		pm_runtime_put_noidle(chan->device->dev);
		return ret;
	}
	...
}

Additionally, if all initialization succeeds, the function appears to fall
through to the err_pm label, dropping the acquired PM reference while
returning success:

	...
err_pm:
	pm_runtime_put_noidle(mtkd->ddev.dev);
	return ret;
}

Later, mtk_uart_apdma_free_chan_resources() unconditionally drops the
reference again via pm_runtime_put_sync().

Could this cause the PM usage count to drop below zero?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260701200703.117929-1-vz@kernel.org?part=1

  reply	other threads:[~2026-07-01 20:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 20:07 [PATCH] dmaengine: mediatek: mtk-uart-apdma: Return -ENOMEM on memory allocation failure Vladimir Zapolskiy
2026-07-01 20:19 ` sashiko-bot [this message]
2026-07-02  3:50 ` Frank Li
2026-07-02  8:21 ` AngeloGioacchino Del Regno
2026-07-02 15:32 ` Vinod Koul

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=20260701201948.7FC101F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    --cc=vz@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