[PATCH] clk: imx: Fix clock reference leak in imx_obtain_fixed_clock_hw()

Subsystems: common clk framework, nxp i.mx clock drivers, the rest

COOLING13d IN LINUX-NEXT

Queued in linux-next as 52d4d1b26a5b on 2026-10-09.

2 messages, 2 authors, 13d ago · open the first message on its own page

[PATCH] clk: imx: Fix clock reference leak in imx_obtain_fixed_clock_hw()

From: Wentao Liang <hidden>
Date: 2026-09-15 05:57:10

imx_obtain_fixed_clock_hw() obtains the clock through
imx_obtain_fixed_clock_from_dt(), which creates a consumer reference
via of_clk_get_from_provider(). The reference is discarded right after
__clk_get_hw() returns the hardware pointer, leaking it.

Keep the imx_clk_fixed() fallback unchanged and drop the DT-obtained
consumer reference with clk_put() once the hardware pointer has been
extracted.

Fixes: a4a4069f4523 ("clk: imx: Add imx_obtain_fixed_clock clk_hw based variant")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <redacted>
---
 drivers/clk/imx/clk.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/imx/clk.c b/drivers/clk/imx/clk.c
index e113e30514fa..49e51e949f71 100644
--- a/drivers/clk/imx/clk.c
+++ b/drivers/clk/imx/clk.c
@@ -95,11 +95,16 @@ struct clk_hw *imx_obtain_fixed_clock_hw(
 			const char *name, unsigned long rate)
 {
 	struct clk *clk;
+	struct clk_hw *hw;
 
 	clk = imx_obtain_fixed_clock_from_dt(name);
 	if (IS_ERR(clk))
-		clk = imx_clk_fixed(name, rate);
-	return __clk_get_hw(clk);
+		return __clk_get_hw(imx_clk_fixed(name, rate));
+
+	hw = __clk_get_hw(clk);
+	clk_put(clk);
+
+	return hw;
 }
 
 struct clk_hw *imx_obtain_fixed_of_clock(struct device_node *np,
-- 
2.34.1

Re: [PATCH] clk: imx: Fix clock reference leak in imx_obtain_fixed_clock_hw()

From: Abel Vesa <hidden>
Date: 2026-10-09 08:11:49

On Tue, 15 Sep 2026 05:56:31 +0000, Wentao Liang wrote:
imx_obtain_fixed_clock_hw() obtains the clock through
imx_obtain_fixed_clock_from_dt(), which creates a consumer reference
via of_clk_get_from_provider(). The reference is discarded right after
__clk_get_hw() returns the hardware pointer, leaking it.

Keep the imx_clk_fixed() fallback unchanged and drop the DT-obtained
consumer reference with clk_put() once the hardware pointer has been
extracted.

[...]
Applied, thanks!

[1/1] clk: imx: Fix clock reference leak in imx_obtain_fixed_clock_hw()
      commit: 52d4d1b26a5bc64de95099d0a3dd8b90dba1f3a3

Best regards,
-- 
Abel Vesa [off-list ref]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help