[PATCH] mailbox: mtk-cmdq: fix runtime PM usage counter leak in cmdq_mbox_flush

manushprajwal posted 1 patch 1 month ago
There is a newer version of this series
drivers/mailbox/mtk-cmdq-mailbox.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] mailbox: mtk-cmdq: fix runtime PM usage counter leak in cmdq_mbox_flush
Posted by manushprajwal 1 month ago
cmdq_mbox_flush() calls pm_runtime_get_sync() and returns its error
code directly on failure. Per Documentation/power/runtime_pm.rst,
pm_runtime_get_sync() does not drop the usage counter on error, so the
caller is expected to release the reference itself. The early return
here skips that, leaking a runtime PM usage count on cmdq->mbox.dev on
every failed resume.

Fix it by calling pm_runtime_put_noidle() before returning, matching
the pattern used by other pm_runtime_get_sync() callers in the same
subsystem (e.g. drivers/i2c/busses/i2c-tegra.c, drivers/gnss/sirf.c).

Signed-off-by: manushprajwal <manushprajwal555@gmail.com>
---
 drivers/mailbox/mtk-cmdq-mailbox.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c
index e523c84b4..2010aadbc 100644
--- a/drivers/mailbox/mtk-cmdq-mailbox.c
+++ b/drivers/mailbox/mtk-cmdq-mailbox.c
@@ -565,8 +565,10 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, unsigned long timeout)
 	int ret;
 
 	ret = pm_runtime_get_sync(cmdq->mbox.dev);
-	if (ret < 0)
+	if (ret < 0) {
+		pm_runtime_put_noidle(cmdq->mbox.dev);
 		return ret;
+	}
 
 	spin_lock_irqsave(&thread->chan->lock, flags);
 	if (list_empty(&thread->task_busy_list))
-- 
2.46.2.windows.1
Re: [PATCH] mailbox: mtk-cmdq: fix runtime PM usage counter leak in cmdq_mbox_flush
Posted by Markus Elfring 1 month ago
…
> Fix it by calling pm_runtime_put_noidle() before returning, matching
> the pattern used by other pm_runtime_get_sync() callers in the same
> subsystem (e.g. …).

How do you think about to use the function “pm_runtime_resume_and_get” instead?
https://elixir.bootlin.com/linux/v7.2/source/include/linux/pm_runtime.h#L530-L540

https://elixir.bootlin.com/linux/v7.2/source/drivers/mailbox/mtk-cmdq-mailbox.c#L557-L611

Regards,
Markus