[PATCH] dmaengine: mediatek: mtk-uart-apdma: Fix runtime PM usage count

From: Arina Kharlamova via B4 Relay

Date: Mon Nov 30 2026 - 17:55:41 EST


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>
---
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>