Skip to content

Commit d005a09

Browse files
marckleinebuddedavem330
authored andcommitted
phylib: phy_attach_direct: phy_init_hw can fail, add cleanup
The function phy_attach_direct attaches the phy and calls phy_init_hw. phy_init_hw can fail, but the phy is still marked as attached. Successive calls to phy_attach_direct will fail because the phy is busy. [ 1.020000] eth0: Freescale FEC PHY driver [Generic PHY] (mii_bus:phy_addr=1:00, irq=-1) [ 1.030000] eth1: Freescale FEC PHY driver [Generic PHY] (mii_bus:phy_addr=1:01, irq=-1) [ 2.050000] Sending DHCP requests . [ 3.020000] PHY: 1:00 - Link is Up - 100/Full [ 5.110000] ..... timed out! [ 87.660000] IP-Config: Reopening network devices... [ 88.190000] FEC: MDIO read timeout [ 88.190000] eth0: could not attach to PHY [ 88.190000] IP-Config: Failed to open eth0 [ 88.210000] FEC: MDIO read timeout [ 88.210000] eth1: could not attach to PHY [ 88.210000] IP-Config: Failed to open eth1 [ 88.220000] IP-Config: No network devices available. [ 88.220000] Freeing init memory: 6968K [...] starting network interfaces... ip: RTNETLINK answers: File exists [ 94.000000] net eth0: PHY already attached [ 94.010000] eth0: could not attach to PHY ip: SIOCSIFFLAGS: Device or resource busy This patch adds phy_detach to clean up if phy_init_hw fails. Signed-off-by: Marc Kleine-Budde <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ff9a57a commit d005a09

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/net/phy/phy_device.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,11 @@ static int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
442442
u32 flags, phy_interface_t interface)
443443
{
444444
struct device *d = &phydev->dev;
445+
int err;
445446

446447
/* Assume that if there is no driver, that it doesn't
447448
* exist, and we should use the genphy driver. */
448449
if (NULL == d->driver) {
449-
int err;
450450
d->driver = &genphy_driver.driver;
451451

452452
err = d->driver->probe(d);
@@ -474,7 +474,11 @@ static int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
474474
/* Do initial configuration here, now that
475475
* we have certain key parameters
476476
* (dev_flags and interface) */
477-
return phy_init_hw(phydev);
477+
err = phy_init_hw(phydev);
478+
if (err)
479+
phy_detach(phydev);
480+
481+
return err;
478482
}
479483

480484
/**

0 commit comments

Comments
 (0)