tg3: clean up PHYLIB resources on probe failure
Subsystems (3)
PATCH v3 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. Guard PHY cleanup with USE_PHYLIB to match tg3_phy_init(), and call tg3_mdio_fini() unconditionally to match tg3_mdio_init(). 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.
---
Changes in v3:
- Restore the USE_PHYLIB guard around tg3_phy_fini() to match tg3_phy_init(), while keeping tg3_mdio_fini() unconditional, as clarified by Andrew Lunn.
Changes in v2:
- Removed the USE_PHYLIB guard around both cleanup calls. This misinterpreted Andrew Lunn's feedback and is corrected in v3.
drivers/net/ethernet/broadcom/tg3.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/broadcom/tg3.c +4 -0
@@ -18047,6 +18047,10 @@ 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
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Thu, 17 Sep 2026 14:33:36 -0400 you wrote:
tg3_get_invariants()can register an MDIO bus and connect a PHY forUSE_PHYLIBdevices. Iftg3_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. Guard PHY cleanup with
USE_PHYLIBto matchtg3_phy_init(), and calltg3_mdio_fini()unconditionally to matchtg3_mdio_init(). The existingIS_CONNECTEDandMDIOBUS_INITEDflags make both helpers safe when initialization only completed partially.[...]
Here is the summary with links:
- [v3] tg3: clean up PHYLIB resources on probe failure
https://git.kernel.org/netdev/net/c/a92e1a412c53
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html