🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Arina Kharlamova via B4 Relay Sun, 29 Nov 2026 07:28
[PATCH net] net: qcom/emac: only disable the clocks that probe enabled
#24071
Author: Arina Kharlamova via B4 Relay
Date: Sun, 29 Nov 2026 07:28
107 lines
13966 bytes
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>
Re: [PATCH net] net: qcom/emac: only disable the clocks that probe enabled
#24073
Author: netdev-bot+sinfo
Date: Sun, 29 Nov 2026 07:34
23 lines
8730 bytes
Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

 - What hardware the change was tested on. For driver fixes please
   mention the device (and if relevant firmware version) used for
   testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
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