Skip to contentSkip to conversation

fsl/fman: Fix clk reference leak in read_dts_node()

PATCH Applied Wentao Liang 3 participants 3 messages Sep 17 – Sep 22

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

PATCH 1/1 fsl/fman: Fix clk reference leak in read_dts_node()

of_clk_get() returns a clock with its reference count incremented, but read_dts_node() only uses it to read the rate and never calls clk_put(). The clock is not stored anywhere, so the reference cannot be released later either.

Release the clock once its rate has been read, which also covers the error path taken when the rate is zero.

Fixes 414fd46e7762 ("fsl/fman: Add FMan support")
---
 drivers/net/ethernet/freescale/fman/fman.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/fman/fman.c +1 -0
index 013273a2de32..0f342b1a845b 100644
@@ -2732,6 +2732,7 @@ static struct fman *read_dts_node(struct platform_device *of_dev)
 	}
 
 	clk_rate = clk_get_rate(clk);
+	clk_put(clk);
 	if (!clk_rate) {
 		err = -EINVAL;
 		dev_err(&of_dev->dev, "%s: Failed to determine FM%d clock rate\n",
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Wentao Liang

of_clk_get() returns a clock with its reference count incremented, but read_dts_node() only uses it to read the rate and never calls clk_put(). The clock is not stored anywhere, so the reference cannot be released later either.

Release the clock once its rate has been read, which also covers the error path taken when the rate is zero.

Fixes 414fd46e7762 ("fsl/fman: Add FMan support")

As noted by Andrew Lunn elsewhere, fixes for bugs are present in net should be target at net like this:

Subject: [PATCH net] ...

Also, perhaps someone else has mentioned this, but please slow down a bit with your patches. I see 19 in Patchwork as of writing. But we encourage a maximum of 15, and I really would like to stress that is a maximum to be used sparingly, not a buffer to be refilled.

I don't think there is any need to repost because of this feedback, but please keep them in mind for the future.

As for this code change, it looks good to me.

#2 lore raw
In reply to Wentao Liang
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Thu, 17 Sep 2026 11:01:35 +0000 you wrote:

of_clk_get() returns a clock with its reference count incremented, but read_dts_node() only uses it to read the rate and never calls clk_put(). The clock is not stored anywhere, so the reference cannot be released later either.

Release the clock once its rate has been read, which also covers the error path taken when the rate is zero.

[...]

Here is the summary with links:
- fsl/fman: Fix clk reference leak in read_dts_node()

    https://git.kernel.org/netdev/net/c/a644f09b2090

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html