🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Wanhui Fu Tue, 01 Dec 2026 08:29
[PATCH net] net: stmmac: rk: Fix clock reference leak on probe failure
#25079
Author: Wanhui Fu
Date: Tue, 01 Dec 2026 08:29
48 lines
9932 bytes
rk_gmac_clk_init() acquires a clock reference using of_clk_get().
If the subsequent platform init callback fails, stmmac_dvr_probe()
returns without calling rk_gmac_exit(), leaking the clock reference.

Fix this by using devm_get_clk_from_child() and removing the
explicit clk_put() from rk_gmac_exit().

Found it by self-developed static analysis tool and compile-test
passed.

Fixes: fecd4d7eef8b ("net: stmmac: dwmac-rk: Add integrated PHY support")
Signed-off-by: Wanhui Fu <fuwh1120@163.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index a37df5767d84..82aed5df1eb5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -1168,7 +1168,8 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat)
 	}
 
 	if (plat->phy_node && bsp_priv->integrated_phy) {
-		bsp_priv->clk_phy = of_clk_get(plat->phy_node, 0);
+		bsp_priv->clk_phy = devm_get_clk_from_child(dev,
+							    plat->phy_node, NULL);
 		ret = PTR_ERR_OR_ZERO(bsp_priv->clk_phy);
 		if (ret)
 			return dev_err_probe(dev, ret, "Cannot get PHY clock\n");
@@ -1637,14 +1638,10 @@ static int rk_gmac_init(struct device *dev, void *bsp_priv)
 
 static void rk_gmac_exit(struct device *dev, void *bsp_priv_)
 {
-	struct stmmac_priv *priv = netdev_priv(dev_get_drvdata(dev));
 	struct rk_priv_data *bsp_priv = bsp_priv_;
 
 	rk_gmac_powerdown(bsp_priv);
 
-	if (priv->plat->phy_node && bsp_priv->integrated_phy)
-		clk_put(bsp_priv->clk_phy);
-
 	reset_control_put(bsp_priv->phy_reset);
 }
 
-- 
2.25.1
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads