Skip to contentSkip to conversation

mailbox: mtk-cmdq: Fix runtime PM leak in cmdq_mbox_flush()

PATCH Applied Wentao Liang 2 participants 2 messages Sep 17 – Oct 12

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mailbox: mtk-cmdq: Fix runtime PM leak in cmdq_mbox_flush()

pm_runtime_get_sync() leaves the runtime PM usage counter incremented even when it fails, but cmdq_mbox_flush() returns the error without dropping it. The same happens when the GCE thread does not drain in time and the function bails out with -EFAULT.

Undo the reference on both error paths.

Fixes b0524f7c9635 ("mailbox: mediatek: implement flush function")
---
 drivers/mailbox/mtk-cmdq-mailbox.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/mailbox/mtk-cmdq-mailbox.c +6 -1
index eadd340f8fee..07a8c2382c93 100644
@@ -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))
@@ -603,6 +605,9 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, unsigned long timeout)
 		dev_err(cmdq->mbox.dev, "Fail to wait GCE thread 0x%x done\n",
 			(u32)(thread->base - cmdq->base));
 
+		pm_runtime_mark_last_busy(cmdq->mbox.dev);
+		pm_runtime_put_autosuspend(cmdq->mbox.dev);
+
 		return -EFAULT;
 	}
 	pm_runtime_mark_last_busy(cmdq->mbox.dev);
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 42 lines · Wentao Liang

pm_runtime_get_sync() leaves the runtime PM usage counter incremented even when it fails, but cmdq_mbox_flush() returns the error without dropping it. The same happens when the GCE thread does not drain in time and the function bails out with -EFAULT.

Undo the reference on both error paths.

Fixes b0524f7c9635 ("mailbox: mediatek: implement flush function")
---
 drivers/mailbox/mtk-cmdq-mailbox.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/mailbox/mtk-cmdq-mailbox.c +6 -2
index eadd340f8fee..07a8c2382c93 100644
@@ -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))
@@ -603,6 +605,9 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, unsigned long timeout)
                dev_err(cmdq->mbox.dev, "Fail to wait GCE thread 0x%x done\n",
                        (u32)(thread->base - cmdq->base));
 
+               pm_runtime_mark_last_busy(cmdq->mbox.dev);
+               pm_runtime_put_autosuspend(cmdq->mbox.dev);
+
                return -EFAULT;
        }
        pm_runtime_mark_last_busy(cmdq->mbox.dev);
--
Quoted 2 lines

2.34.1

Applied to mailbox/for-next

Thanks
Jassi