Re: [PATCH] dmaengine: mediatek: mtk-uart-apdma: Fix runtime PM usage count
From: Frank Li
Date: Tue Dec 01 2026 - 15:10:57 EST
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@xxxxxxxxxx. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> From: Arina Kharlamova <arina.kharlamova@xxxxxxxxxxxx>
>
> 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@xxxxxxxxxxxx>
> ---
Reviewed-by: Frank Li <Frank.Li@xxxxxxx>
> 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@xxxxxxxxxxxx>
>
>