mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] net: usb: lan78xx: only stop phylink if the interface is running
@ 2026-10-29 16:02 YuanZhe Liu
  2026-10-30 17:38 ` YuanZhe Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: YuanZhe Liu @ 2026-10-29 16:02 UTC (permalink / raw)
  To: Thangaraj Samynathan, UNGLinuxDriver
  Cc: netdev, linux-usb, linux-kernel, Andrew Lunn, Russell King,
	Oleksij Rempel, stable, Bin Yu, Cheng Wen

lan78xx_disconnect() unconditionally calls phylink_stop(), but
phylink_start() is only called from lan78xx_open(). When the device is
unplugged before the interface has been brought up, the attached PHY is
still in PHY_READY and phy_stop() reports:

  called from state READY
  WARNING: drivers/net/phy/phy.c:1670 at phy_stop+0xad/0x380

The same warning is emitted after an ifup/ifdown cycle, where the PHY is
already in PHY_HALTED. Call phylink_stop() only when the network device is
running, which is when phylink_start() has been called.

Fixes: e110bc825897 ("net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
 drivers/net/usb/lan78xx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 5655941f1478..68e61004b3d7 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -4581,7 +4581,8 @@ static void lan78xx_disconnect(struct usb_interface *intf)
 	net = dev->net;
 
 	rtnl_lock();
-	phylink_stop(dev->phylink);
+	if (netif_running(net))
+		phylink_stop(dev->phylink);
 	phylink_disconnect_phy(dev->phylink);
 	rtnl_unlock();
 
-- 
2.34.1


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

* Re: [PATCH net] net: usb: lan78xx: only stop phylink if the interface is running
  2026-10-29 16:02 [PATCH net] net: usb: lan78xx: only stop phylink if the interface is running YuanZhe Liu
@ 2026-10-30 17:38 ` YuanZhe Liu
  2026-10-30 19:23   ` Andrew Lunn
  2026-10-30 20:02 ` Andrew Lunn
       [not found] ` <sashiko-outbox-191206@kernel.org>
  2 siblings, 1 reply; 5+ messages in thread
From: YuanZhe Liu @ 2026-10-30 17:38 UTC (permalink / raw)
  To: Thangaraj Samynathan, UNGLinuxDriver
  Cc: netdev, linux-usb, linux-kernel, Andrew Lunn, Russell King,
	Oleksij Rempel, stable, Bin Yu, Cheng Wen, Andrew Lunn

Hi Andrew,

Could you please review this patch?

  [PATCH net] net: usb: lan78xx: only stop phylink if the interface is
  running

It calls phylink_stop() during lan78xx disconnect only when the network
interface is running.

The patch is unchanged. I am copying this address for visibility.

Original submission:
https://lore.kernel.org/r/20261029160204.2567-1-25031212351@stu.xidian.edu.cn

Thanks,
YuanZhe


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

* Re: [PATCH net] net: usb: lan78xx: only stop phylink if the interface is running
  2026-10-30 17:38 ` YuanZhe Liu
@ 2026-10-30 19:23   ` Andrew Lunn
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2026-10-30 19:23 UTC (permalink / raw)
  To: YuanZhe Liu
  Cc: Thangaraj Samynathan, UNGLinuxDriver, netdev, linux-usb,
	linux-kernel, Andrew Lunn, Russell King, Oleksij Rempel, stable,
	Bin Yu, Cheng Wen

On Sat, Oct 31, 2026 at 01:38:41AM +0800, YuanZhe Liu wrote:
> Hi Andrew,
> 
> Could you please review this patch?

You should respond to what the sashiko-bot@kernel.org has said.

    Andrew

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

* Re: [PATCH net] net: usb: lan78xx: only stop phylink if the interface is running
  2026-10-29 16:02 [PATCH net] net: usb: lan78xx: only stop phylink if the interface is running YuanZhe Liu
  2026-10-30 17:38 ` YuanZhe Liu
@ 2026-10-30 20:02 ` Andrew Lunn
       [not found] ` <sashiko-outbox-191206@kernel.org>
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2026-10-30 20:02 UTC (permalink / raw)
  To: YuanZhe Liu
  Cc: Thangaraj Samynathan, UNGLinuxDriver, netdev, linux-usb,
	linux-kernel, Andrew Lunn, Russell King, Oleksij Rempel, stable,
	Bin Yu, Cheng Wen

On Fri, Oct 30, 2026 at 12:02:04AM +0800, YuanZhe Liu wrote:
> lan78xx_disconnect() unconditionally calls phylink_stop(), but
> phylink_start() is only called from lan78xx_open(). When the device is
> unplugged before the interface has been brought up, the attached PHY is
> still in PHY_READY and phy_stop() reports:
> 
>   called from state READY
>   WARNING: drivers/net/phy/phy.c:1670 at phy_stop+0xad/0x380
> 
> The same warning is emitted after an ifup/ifdown cycle, where the PHY is
> already in PHY_HALTED. Call phylink_stop() only when the network device is
> running, which is when phylink_start() has been called.
> 
> Fixes: e110bc825897 ("net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management")

Why did you pick this commit?

    Andrew

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

* Re: [PATCH net] net: usb: lan78xx: only stop phylink if the interface is running
       [not found] ` <sashiko-outbox-191206@kernel.org>
@ 2026-10-31 16:52   ` YuanZhe Liu
  0 siblings, 0 replies; 5+ messages in thread
From: YuanZhe Liu @ 2026-10-31 16:52 UTC (permalink / raw)
  To: sashiko-bot
  Cc: Thangaraj Samynathan, UNGLinuxDriver, netdev, linux-usb,
	linux-kernel, Andrew Lunn, Russell King, Oleksij Rempel, stable,
	Bin Yu, Cheng Wen

On Fri, Oct 30, 2026 at 04:02:36PM +0000, sashiko-bot@kernel.org wrote:
> Does calling phylink_stop() and phylink_disconnect_phy() before
> unregister_netdev(net) in drivers/net/usb/lan78xx.c:lan78xx_disconnect()
> cause out-of-order teardown, a duplicate phylink_stop() call, and a race
> window when rtnl_lock() is dropped?

Yes, the ordering is wrong. v2 drops the explicit phylink_stop() from the
disconnect path and unregisters the net device first:

	unregister_netdev(net);

	rtnl_lock();
	phylink_disconnect_phy(dev->phylink);
	rtnl_unlock();

unregister_netdev() closes a running device, so phylink_stop() is done by
lan78xx_stop() with dev->dev_mutex held and after the TX/RX URBs have been
terminated, which is the same sequence as a normal ifdown. When the
interface was never started no phylink_stop() happens at all, and that is
exactly the case phy_stop() complains about with "called from state READY".

This also removes the second phylink_stop() invocation and the window in
which the net device was still registered with no PHY attached.

On the remaining points:

- The duplicate phylink_stop() was harmless in practice, because after
  phylink_disconnect_phy() pl->phydev is NULL and PHYLINK_DISABLE_STOPPED
  is already set. It is gone now anyway.

- The PHY interrupt is not released by phylink_disconnect_phy(). The virq
  created by irq_create_mapping() is disposed in lan78xx_remove_irq_domain(),
  called from lan78xx_unbind(), which also clears dev->domain_data.phyirq;
  lan78xx_status() tests that field before generic_handle_irq_safe(). The
  intr URB is killed later in lan78xx_disconnect(), and that ordering is
  unchanged by this patch.

- Andrew also asked why the Fixes tag points at e110bc825897: that commit
  added both the phylink instance and the unconditional phylink_stop() call
  in lan78xx_disconnect(), and

    git log -S'phylink_stop(dev->phylink)' -- drivers/net/usb/lan78xx.c

  shows that the line has not been touched since.

v2 is sent as a separate thread.

Thanks,
YuanZhe


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

end of thread, other threads:[~2026-10-31 16:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29 16:02 [PATCH net] net: usb: lan78xx: only stop phylink if the interface is running YuanZhe Liu
2026-10-30 17:38 ` YuanZhe Liu
2026-10-30 19:23   ` Andrew Lunn
2026-10-30 20:02 ` Andrew Lunn
     [not found] ` <sashiko-outbox-191206@kernel.org>
2026-10-31 16:52   ` YuanZhe Liu

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®