Skip to contentSkip to conversation

tg3: clean up PHYLIB resources on probe failure

PATCH Superseded Myeonghun Pak 2 participants 3 messages Sep 13 – Sep 14

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tg3: clean up PHYLIB resources on probe failure

tg3_get_invariants() can register an MDIO bus and connect a PHY for USE_PHYLIB devices. If tg3_init_one() later fails, its common error path releases the mappings and netdev without undoing those PHYLIB resources.

Disconnect the PHY and unregister the MDIO bus before the remaining teardown. The existing IS_CONNECTED and MDIOBUS_INITED flags make both helpers safe when initialization only completed partially.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 158d7abdae85 ("tg3: Add mdio bus registration")
Assisted-by OpenAI:GPT-5.6
---
 drivers/net/ethernet/broadcom/tg3.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/broadcom/tg3.c +5 -0
index 73a4b569b..4662e0e92 100644
@@ -18047,6 +18047,11 @@ static int tg3_init_one(struct pci_dev *pdev,
 	return 0;
 
 err_out_apeunmap:
+	if (tg3_flag(tp, USE_PHYLIB)) {
+		tg3_phy_fini(tp);
+		tg3_mdio_fini(tp);
+	}
+
 	if (tp->aperegs) {
 		iounmap(tp->aperegs);
 		tp->aperegs = NULL;
Signature · 1 line
2.47.1
#1 lore raw
Quoted 25 lines · Myeonghun Pak

tg3_get_invariants() can register an MDIO bus and connect a PHY for USE_PHYLIB devices. If tg3_init_one() later fails, its common error path releases the mappings and netdev without undoing those PHYLIB resources.

Disconnect the PHY and unregister the MDIO bus before the remaining teardown. The existing IS_CONNECTED and MDIOBUS_INITED flags make both helpers safe when initialization only completed partially.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 158d7abdae85 ("tg3: Add mdio bus registration")
Assisted-by OpenAI:GPT-5.6
---
 drivers/net/ethernet/broadcom/tg3.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/broadcom/tg3.c +0 -0
index 73a4b569b..4662e0e92 100644

drivers/net/ethernet/broadcom/tg3.c static int tg3_init_one(struct pci_dev *pdev, · line 18053

Quoted 7 lines
drivers/net/ethernet/broadcom/tg3.c +4 -0
@@ -18047,6 +18047,11 @@ static int tg3_init_one(struct pci_dev *pdev,
 	return 0;
 
 err_out_apeunmap:
+	if (tg3_flag(tp, USE_PHYLIB)) {
+		tg3_phy_fini(tp);
+		tg3_mdio_fini(tp);
+	}

Looking at tg3_get_invariants(), tg3_mdio_init() is not conditional on USE_PHYLIB.

Andrew

---
pw-bot: cr

#2 lore raw

Hi Andrew,

I'll remove the redundant USE_PHYLIB check in v2, as both cleanup helpers already check their initialization flags.

Thanks,
Myeonghun

2026년 9월 14일 (월) 오후 4:10, Andrew Lunn <[email protected]>님이 작성:

Quoted 42 lines · Myeonghun Pak
Quoted 25 lines

tg3_get_invariants() can register an MDIO bus and connect a PHY for USE_PHYLIB devices. If tg3_init_one() later fails, its common error path releases the mappings and netdev without undoing those PHYLIB resources.

Disconnect the PHY and unregister the MDIO bus before the remaining teardown. The existing IS_CONNECTED and MDIOBUS_INITED flags make both helpers safe when initialization only completed partially.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 158d7abdae85 ("tg3: Add mdio bus registration")
Assisted-by OpenAI:GPT-5.6
---
 drivers/net/ethernet/broadcom/tg3.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/broadcom/tg3.c +0 -0
index 73a4b569b..4662e0e92 100644

drivers/net/ethernet/broadcom/tg3.c static int tg3_init_one(struct pci_dev *pdev, · line 18053

Quoted 7 lines
drivers/net/ethernet/broadcom/tg3.c +4 -0
@@ -18047,6 +18047,11 @@ static int tg3_init_one(struct pci_dev *pdev,
      return 0;
 
 err_out_apeunmap:
+     if (tg3_flag(tp, USE_PHYLIB)) {
+             tg3_phy_fini(tp);
+             tg3_mdio_fini(tp);
+     }

Looking at tg3_get_invariants(), tg3_mdio_init() is not conditional on USE_PHYLIB.

Andrew

---
pw-bot: cr