netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: usb: lan78xx: Connect PHY before registering MAC
@ 2019-10-17 19:29 Andrew Lunn
  2019-10-18  7:06 ` Daniel Wagner
  2019-10-18 17:22 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Lunn @ 2019-10-17 19:29 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, dwagner, wahrenst, Andrew Lunn

As soon as the netdev is registers, the kernel can start using the
interface. If the driver connects the MAC to the PHY after the netdev
is registered, there is a race condition where the interface can be
opened without having the PHY connected.

Change the order to close this race condition.

Fixes: 92571a1aae40 ("lan78xx: Connect phy early")
Reported-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/usb/lan78xx.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 58f5a219fb65..62948098191f 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -3782,10 +3782,14 @@ static int lan78xx_probe(struct usb_interface *intf,
 	/* driver requires remote-wakeup capability during autosuspend. */
 	intf->needs_remote_wakeup = 1;
 
+	ret = lan78xx_phy_init(dev);
+	if (ret < 0)
+		goto out4;
+
 	ret = register_netdev(netdev);
 	if (ret != 0) {
 		netif_err(dev, probe, netdev, "couldn't register the device\n");
-		goto out4;
+		goto out5;
 	}
 
 	usb_set_intfdata(intf, dev);
@@ -3798,14 +3802,10 @@ static int lan78xx_probe(struct usb_interface *intf,
 	pm_runtime_set_autosuspend_delay(&udev->dev,
 					 DEFAULT_AUTOSUSPEND_DELAY);
 
-	ret = lan78xx_phy_init(dev);
-	if (ret < 0)
-		goto out5;
-
 	return 0;
 
 out5:
-	unregister_netdev(netdev);
+	phy_disconnect(netdev->phydev);
 out4:
 	usb_free_urb(dev->urb_intr);
 out3:
-- 
2.23.0


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

* Re: [PATCH net] net: usb: lan78xx: Connect PHY before registering MAC
  2019-10-17 19:29 [PATCH net] net: usb: lan78xx: Connect PHY before registering MAC Andrew Lunn
@ 2019-10-18  7:06 ` Daniel Wagner
  2019-10-18 17:22 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Wagner @ 2019-10-18  7:06 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: David Miller, netdev, wahrenst

On Thu, Oct 17, 2019 at 09:29:26PM +0200, Andrew Lunn wrote:
> As soon as the netdev is registers, the kernel can start using the
> interface. If the driver connects the MAC to the PHY after the netdev
> is registered, there is a race condition where the interface can be
> opened without having the PHY connected.
> 
> Change the order to close this race condition.
> 
> Fixes: 92571a1aae40 ("lan78xx: Connect phy early")
> Reported-by: Daniel Wagner <dwagner@suse.de>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Tested-by: Daniel Wagner <dwagner@suse.de>

Thanks for the fix!
Daniel

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

* Re: [PATCH net] net: usb: lan78xx: Connect PHY before registering MAC
  2019-10-17 19:29 [PATCH net] net: usb: lan78xx: Connect PHY before registering MAC Andrew Lunn
  2019-10-18  7:06 ` Daniel Wagner
@ 2019-10-18 17:22 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-10-18 17:22 UTC (permalink / raw)
  To: andrew; +Cc: netdev, dwagner, wahrenst

From: Andrew Lunn <andrew@lunn.ch>
Date: Thu, 17 Oct 2019 21:29:26 +0200

> As soon as the netdev is registers, the kernel can start using the
> interface. If the driver connects the MAC to the PHY after the netdev
> is registered, there is a race condition where the interface can be
> opened without having the PHY connected.
> 
> Change the order to close this race condition.
> 
> Fixes: 92571a1aae40 ("lan78xx: Connect phy early")
> Reported-by: Daniel Wagner <dwagner@suse.de>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Applied and queued up for -stable, thanks.

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

end of thread, other threads:[~2019-10-18 17:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-17 19:29 [PATCH net] net: usb: lan78xx: Connect PHY before registering MAC Andrew Lunn
2019-10-18  7:06 ` Daniel Wagner
2019-10-18 17:22 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).