From d9750b3c4c277b061df694f563a58c6df7b84912 Mon Sep 17 00:00:00 2001 From: Wentao Liang Date: Thu, 17 Sep 2026 11:36:54 +0000 Subject: [PATCH] net: stmmac: dwmac-sun8i: Fix EPHY clock leak in get_ephy_nodes() get_ephy_nodes() stores the clock returned by of_clk_get() directly in gmac->ephy_clk before the reset control is obtained. When the reset lookup fails, the loop continues or returns without releasing that clock, and sun8i_dwmac_probe() then jumps to dwmac_remove, which does not call clk_put(). Keep the clock in a local variable and release it on the error paths. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Signed-off-by: Wentao Liang Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260917113654.2149268-1-vulab@iscas.ac.cn Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index 48c52eb96233..38d7e71de925 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -783,18 +783,22 @@ static int get_ephy_nodes(struct stmmac_priv *priv) /* Seek for internal PHY */ for_each_child_of_node_scoped(mdio_internal, iphynode) { - gmac->ephy_clk = of_clk_get(iphynode, 0); - if (IS_ERR(gmac->ephy_clk)) + struct clk *ephy_clk; + + ephy_clk = of_clk_get(iphynode, 0); + if (IS_ERR(ephy_clk)) continue; gmac->rst_ephy = of_reset_control_get_exclusive(iphynode, NULL); if (IS_ERR(gmac->rst_ephy)) { ret = PTR_ERR(gmac->rst_ephy); + clk_put(ephy_clk); if (ret == -EPROBE_DEFER) { of_node_put(mdio_internal); return ret; } continue; } + gmac->ephy_clk = ephy_clk; dev_info(priv->device, "Found internal PHY node\n"); of_node_put(mdio_internal); return 0;