Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: qcom/emac: only disable the clocks that probe enabled
@ 2026-11-29  7:28 Arina Kharlamova via B4 Relay
  2026-11-29  7:34 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-11-29  7:28 UTC (permalink / raw)
  To: Timur Tabi, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Timur Tabi, netdev, Arina Kharlamova

From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

emac_probe() enables three clocks in emac_clks_phase1_init() and the
other four in emac_clks_phase2_init(), but every error path after
phase 1 runs emac_clks_teardown(), which disables and unprepares all
seven. When emac_phy_config(), emac_sgmii_config() or phase 2 itself
fails, the clock core warns about clocks that are already disabled
and unprepared, and a clock shared with another consumer loses that
consumer's reference.

Let phase 2 undo its own clocks on failure. In probe, disable the phase
2 clocks only on the path taken after phase 2 succeeded, and only the
phase 1 clocks on the earlier ones.

Fixes: b9b17debc69d ("net: emac: emac gigabit ethernet controller driver")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
Found by the spec2patch formal prover, with the help of an AI coding
assistant (Claude); I reviewed the analysis and the fix.
---
 drivers/net/ethernet/qualcomm/emac/emac.c | 43 ++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/emac/emac.c b/drivers/net/ethernet/qualcomm/emac/emac.c
index 699a8afc214a..8b70412d8cef 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac.c
@@ -513,21 +513,51 @@ static int emac_clks_phase2_init(struct platform_device *pdev,
 
 	ret = clk_set_rate(adpt->clk[EMAC_CLK_HIGH_SPEED], 125000000);
 	if (ret)
-		return ret;
+		goto disable_clk_tx;
 
 	ret = clk_set_rate(adpt->clk[EMAC_CLK_MDIO], 25000000);
 	if (ret)
-		return ret;
+		goto disable_clk_tx;
 
 	ret = clk_prepare_enable(adpt->clk[EMAC_CLK_MDIO]);
 	if (ret)
-		return ret;
+		goto disable_clk_tx;
 
 	ret = clk_prepare_enable(adpt->clk[EMAC_CLK_RX]);
 	if (ret)
-		return ret;
+		goto disable_clk_mdio;
+
+	ret = clk_prepare_enable(adpt->clk[EMAC_CLK_SYS]);
+	if (ret)
+		goto disable_clk_rx;
+
+	return 0;
 
-	return clk_prepare_enable(adpt->clk[EMAC_CLK_SYS]);
+disable_clk_rx:
+	clk_disable_unprepare(adpt->clk[EMAC_CLK_RX]);
+disable_clk_mdio:
+	clk_disable_unprepare(adpt->clk[EMAC_CLK_MDIO]);
+disable_clk_tx:
+	clk_disable_unprepare(adpt->clk[EMAC_CLK_TX]);
+
+	return ret;
+}
+
+/* Disable the clocks emac_clks_phase1_init enabled */
+static void emac_clks_phase1_teardown(struct emac_adapter *adpt)
+{
+	clk_disable_unprepare(adpt->clk[EMAC_CLK_HIGH_SPEED]);
+	clk_disable_unprepare(adpt->clk[EMAC_CLK_CFG_AHB]);
+	clk_disable_unprepare(adpt->clk[EMAC_CLK_AXI]);
+}
+
+/* Disable the clocks emac_clks_phase2_init enabled */
+static void emac_clks_phase2_teardown(struct emac_adapter *adpt)
+{
+	clk_disable_unprepare(adpt->clk[EMAC_CLK_SYS]);
+	clk_disable_unprepare(adpt->clk[EMAC_CLK_RX]);
+	clk_disable_unprepare(adpt->clk[EMAC_CLK_MDIO]);
+	clk_disable_unprepare(adpt->clk[EMAC_CLK_TX]);
 }
 
 static void emac_clks_teardown(struct emac_adapter *adpt)
@@ -707,11 +737,12 @@ static int emac_probe(struct platform_device *pdev)
 
 err_undo_napi:
 	netif_napi_del(&adpt->rx_q.napi);
+	emac_clks_phase2_teardown(adpt);
 err_undo_mdiobus:
 	put_device(&adpt->phydev->mdio.dev);
 	mdiobus_unregister(adpt->mii_bus);
 err_undo_clocks:
-	emac_clks_teardown(adpt);
+	emac_clks_phase1_teardown(adpt);
 err_undo_netdev:
 	free_netdev(netdev);
 

---
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
change-id: 20261129-s2p-v09-fe31d39cdd4f

Best regards,
--  
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29  7:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  7:28 [PATCH net] net: qcom/emac: only disable the clocks that probe enabled Arina Kharlamova via B4 Relay
2026-11-29  7:34 ` netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox