mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tg3: clean up PHYLIB resources on probe failure
@ 2026-09-13  1:21 Myeonghun Pak
  2026-09-14 20:10 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: Myeonghun Pak @ 2026-09-13  1:21 UTC (permalink / raw)
  To: Pavan Chebbi, Michael Chan
  Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel, Myeonghun Pak, Ijae Kim

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
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
 drivers/net/ethernet/broadcom/tg3.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 73a4b569b..4662e0e92 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -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;
-- 
2.47.1


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

* Re: [PATCH] tg3: clean up PHYLIB resources on probe failure
  2026-09-13  1:21 [PATCH] tg3: clean up PHYLIB resources on probe failure Myeonghun Pak
@ 2026-09-14 20:10 ` Andrew Lunn
  2026-09-14 22:19   ` Myeonghun Pak
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2026-09-14 20:10 UTC (permalink / raw)
  To: Myeonghun Pak
  Cc: Pavan Chebbi, Michael Chan, Andrew Lunn, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	Ijae Kim

On Sat, Sep 12, 2026 at 09:21:48PM -0400, Myeonghun Pak wrote:
> 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
> Co-developed-by: Ijae Kim <ae878000@gmail.com>
> Signed-off-by: Ijae Kim <ae878000@gmail.com>
> Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
> ---
>  drivers/net/ethernet/broadcom/tg3.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
> index 73a4b569b..4662e0e92 100644
> --- a/drivers/net/ethernet/broadcom/tg3.c
> +++ b/drivers/net/ethernet/broadcom/tg3.c
> @@ -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

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

* Re: [PATCH] tg3: clean up PHYLIB resources on probe failure
  2026-09-14 20:10 ` Andrew Lunn
@ 2026-09-14 22:19   ` Myeonghun Pak
  0 siblings, 0 replies; 3+ messages in thread
From: Myeonghun Pak @ 2026-09-14 22:19 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Pavan Chebbi, Michael Chan, Andrew Lunn, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	Ijae Kim

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 <andrew@lunn.ch>님이 작성:
>
> On Sat, Sep 12, 2026 at 09:21:48PM -0400, Myeonghun Pak wrote:
> > 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
> > Co-developed-by: Ijae Kim <ae878000@gmail.com>
> > Signed-off-by: Ijae Kim <ae878000@gmail.com>
> > Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
> > ---
> >  drivers/net/ethernet/broadcom/tg3.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
> > index 73a4b569b..4662e0e92 100644
> > --- a/drivers/net/ethernet/broadcom/tg3.c
> > +++ b/drivers/net/ethernet/broadcom/tg3.c
> > @@ -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

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

end of thread, other threads:[~2026-09-14 22:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-13  1:21 [PATCH] tg3: clean up PHYLIB resources on probe failure Myeonghun Pak
2026-09-14 20:10 ` Andrew Lunn
2026-09-14 22:19   ` Myeonghun Pak

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

all inboxes | Powered by JetHome®