net: stmmac: dwmac-sun8i: Fix EPHY clock leak in get_ephy_nodes()
Commit Message
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.
Fixes: 634db83b8265 ("net: stmmac: dwmac-sun8i: Handle integrated/external MDIOs")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
@@ -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;