From: Wentao Liang <vulab@iscas.ac.cn>
To: angelogioacchino.delregno@collabora.com
Cc: jason-jh.lin@mediatek.com, jassisinghbrar@gmail.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
matthias.bgg@gmail.com, Wentao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] mailbox: mtk-cmdq: Fix GCE clock reference leak in cmdq_get_clocks()
Date: Thu, 17 Sep 2026 09:37:45 +0000 [thread overview]
Message-ID: <20260917093745.2144930-1-vulab@iscas.ac.cn> (raw)
of_clk_get() returns the clock with an elevated reference count, but
the references taken for the other GCE clocks are never dropped: those
clocks outlive probe and the driver calls neither clk_put() nor
clk_bulk_put(), so probing a GCE with multiple instances leaks one
reference per other GCE clock.
Let devres drop the references when the device goes away, which also
covers the probe failure paths after cmdq_get_clocks() has returned.
Fixes: 85dfdbfc13ea ("mailbox: cmdq: add multi-gce clocks support for mt8195")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/mailbox/mtk-cmdq-mailbox.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c
index e523c84b4808..eadd340f8fee 100644
--- a/drivers/mailbox/mtk-cmdq-mailbox.c
+++ b/drivers/mailbox/mtk-cmdq-mailbox.c
@@ -633,11 +633,22 @@ static struct mbox_chan *cmdq_xlate(struct mbox_controller *mbox,
return &mbox->chans[ind];
}
+static void cmdq_put_clocks(void *data)
+{
+ struct cmdq *cmdq = data;
+ u32 i;
+
+ for (i = 0; i < cmdq->pdata->gce_num; i++)
+ if (!IS_ERR_OR_NULL(cmdq->clocks[i].clk))
+ clk_put(cmdq->clocks[i].clk);
+}
+
static int cmdq_get_clocks(struct device *dev, struct cmdq *cmdq)
{
static const char * const gce_name = "gce";
struct device_node *parent = dev->of_node->parent;
struct clk_bulk_data *clks;
+ int ret;
cmdq->clocks = devm_kcalloc(dev, cmdq->pdata->gce_num,
sizeof(*cmdq->clocks), GFP_KERNEL);
@@ -660,7 +671,14 @@ static int cmdq_get_clocks(struct device *dev, struct cmdq *cmdq)
* If there is more than one GCE, get the clocks for the others too,
* as the clock of the main GCE must be enabled for additional IPs
* to be reachable.
+ *
+ * Those clocks are not devm-managed, so keep track of their
+ * references and drop them when this device goes away.
*/
+ ret = devm_add_action_or_reset(dev, cmdq_put_clocks, cmdq);
+ if (ret)
+ return ret;
+
for_each_child_of_node_scoped(parent, node) {
int alias_id = of_alias_get_id(node, gce_name);
--
2.34.1
next reply other threads:[~2026-09-17 9:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 9:37 Wentao Liang [this message]
2026-09-17 11:57 ` [PATCH] mailbox: mtk-cmdq: Fix GCE clock reference leak in cmdq_get_clocks() Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260917093745.2144930-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=angelogioacchino.delregno@collabora.com \
--cc=jason-jh.lin@mediatek.com \
--cc=jassisinghbrar@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox