* [PATCH] dmaengine: mediatek: mtk-uart-apdma: Fix runtime PM usage count
@ 2026-11-30 22:55 Arina Kharlamova via B4 Relay
2026-12-01 20:10 ` Frank Li
0 siblings, 1 reply; 2+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-11-30 22:55 UTC (permalink / raw)
To: Sean Wang, Vinod Koul, Frank Li, Matthias Brugger,
AngeloGioacchino Del Regno, zhangqilong
Cc: dmaengine, linux-arm-kernel, linux-mediatek, linux-kernel,
Arina Kharlamova
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
Commit 545b2baac89b ("dmaengine: mediatek:Fix PM usage reference leak
of mtk_uart_apdma_alloc_chan_resources") switched
mtk_uart_apdma_alloc_chan_resources() to pm_runtime_resume_and_get()
and added an err_pm label. It left two problems behind.
The pm_runtime_put_noidle() on the resume error path was kept, but
pm_runtime_resume_and_get() already drops the usage count when it
fails, so the count is dropped twice.
The success path falls through into err_pm, so the function drops the
reference it has just taken. mtk_uart_apdma_free_chan_resources() then
calls pm_runtime_put_sync() on a count that is already zero.
Return the error directly when the resume fails, and return 0 before
err_pm on success.
Fixes: 545b2baac89b ("dmaengine: mediatek:Fix PM usage reference leak of mtk_uart_apdma_alloc_chan_resources")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
Found by checks derived from the spec2patch kernel API specifications,
with the help of an AI coding assistant (Claude); I reviewed the
analysis and the fix.
---
drivers/dma/mediatek/mtk-uart-apdma.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c
index bf242c4c262f..d59a07ab1aae 100644
--- a/drivers/dma/mediatek/mtk-uart-apdma.c
+++ b/drivers/dma/mediatek/mtk-uart-apdma.c
@@ -274,10 +274,8 @@ static int mtk_uart_apdma_alloc_chan_resources(struct dma_chan *chan)
int ret;
ret = pm_runtime_resume_and_get(mtkd->ddev.dev);
- if (ret < 0) {
- pm_runtime_put_noidle(chan->device->dev);
+ if (ret < 0)
return ret;
- }
mtk_uart_apdma_write(c, VFF_ADDR, 0);
mtk_uart_apdma_write(c, VFF_THRE, 0);
@@ -300,6 +298,8 @@ static int mtk_uart_apdma_alloc_chan_resources(struct dma_chan *chan)
if (mtkd->support_ext_addr)
mtk_uart_apdma_write(c, VFF_ADDR2, VFF_ADDR2_CLR_B);
+ return 0;
+
err_pm:
pm_runtime_put_noidle(mtkd->ddev.dev);
return ret;
---
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
change-id: 20261129-s2p-c03-aa7e4bb16aa9
Best regards,
--
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] dmaengine: mediatek: mtk-uart-apdma: Fix runtime PM usage count
2026-11-30 22:55 [PATCH] dmaengine: mediatek: mtk-uart-apdma: Fix runtime PM usage count Arina Kharlamova via B4 Relay
@ 2026-12-01 20:10 ` Frank Li
0 siblings, 0 replies; 2+ messages in thread
From: Frank Li @ 2026-12-01 20:10 UTC (permalink / raw)
To: arina.kharlamova
Cc: Sean Wang, Vinod Koul, Frank Li, Matthias Brugger,
AngeloGioacchino Del Regno, zhangqilong, dmaengine,
linux-arm-kernel, linux-mediatek, linux-kernel
On Tue, Dec 01, 2026 at 02:55:28AM +0400, Arina Kharlamova via B4 Relay wrote:
> [You don't often get email from devnull+arina.kharlamova.mbzuai.ac.ae@kernel.org. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
>
> Commit 545b2baac89b ("dmaengine: mediatek:Fix PM usage reference leak
> of mtk_uart_apdma_alloc_chan_resources") switched
> mtk_uart_apdma_alloc_chan_resources() to pm_runtime_resume_and_get()
> and added an err_pm label. It left two problems behind.
>
> The pm_runtime_put_noidle() on the resume error path was kept, but
> pm_runtime_resume_and_get() already drops the usage count when it
> fails, so the count is dropped twice.
>
> The success path falls through into err_pm, so the function drops the
> reference it has just taken. mtk_uart_apdma_free_chan_resources() then
> calls pm_runtime_put_sync() on a count that is already zero.
>
> Return the error directly when the resume fails, and return 0 before
> err_pm on success.
>
> Fixes: 545b2baac89b ("dmaengine: mediatek:Fix PM usage reference leak of mtk_uart_apdma_alloc_chan_resources")
> Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> Found by checks derived from the spec2patch kernel API specifications,
> with the help of an AI coding assistant (Claude); I reviewed the
> analysis and the fix.
> ---
> drivers/dma/mediatek/mtk-uart-apdma.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c
> index bf242c4c262f..d59a07ab1aae 100644
> --- a/drivers/dma/mediatek/mtk-uart-apdma.c
> +++ b/drivers/dma/mediatek/mtk-uart-apdma.c
> @@ -274,10 +274,8 @@ static int mtk_uart_apdma_alloc_chan_resources(struct dma_chan *chan)
> int ret;
>
> ret = pm_runtime_resume_and_get(mtkd->ddev.dev);
> - if (ret < 0) {
> - pm_runtime_put_noidle(chan->device->dev);
> + if (ret < 0)
> return ret;
> - }
>
> mtk_uart_apdma_write(c, VFF_ADDR, 0);
> mtk_uart_apdma_write(c, VFF_THRE, 0);
> @@ -300,6 +298,8 @@ static int mtk_uart_apdma_alloc_chan_resources(struct dma_chan *chan)
> if (mtkd->support_ext_addr)
> mtk_uart_apdma_write(c, VFF_ADDR2, VFF_ADDR2_CLR_B);
>
> + return 0;
> +
> err_pm:
> pm_runtime_put_noidle(mtkd->ddev.dev);
> return ret;
>
> ---
> base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
> change-id: 20261129-s2p-c03-aa7e4bb16aa9
>
> Best regards,
> --
> Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 20:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 22:55 [PATCH] dmaengine: mediatek: mtk-uart-apdma: Fix runtime PM usage count Arina Kharlamova via B4 Relay
2026-12-01 20:10 ` Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox