Commit a3995460 authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller

net: phy: Relax error checking on sysfs_create_link()

Some Ethernet drivers will attach/connect to a PHY device before calling
register_netdevice() which is responsible for calling netdev_register_kobject()
which would do the network device's kobject initialization. In such a case,
sysfs_create_link() would return -ENOENT because the network device's kobject
is not ready yet, and we would fail to connect to the PHY device.

In order to keep things simple and symetrical, we just take the success path as
indicative of the ability to access the network device's kobject, and create
the second link if that's the case.

Fixes: 5568363f ("net: phy: Create sysfs reciprocal links for attached_dev/phydev")
Reported-by: default avatarWoojung Hung <Woojung.Huh@microchip.com>
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 523a8904
...@@ -960,15 +960,27 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, ...@@ -960,15 +960,27 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
phydev->attached_dev = dev; phydev->attached_dev = dev;
dev->phydev = phydev; dev->phydev = phydev;
/* Some Ethernet drivers try to connect to a PHY device before
* calling register_netdevice() -> netdev_register_kobject() and
* does the dev->dev.kobj initialization. Here we only check for
* success which indicates that the network device kobject is
* ready. Once we do that we still need to keep track of whether
* links were successfully set up or not for phy_detach() to
* remove them accordingly.
*/
phydev->sysfs_links = false;
err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj, err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj,
"attached_dev"); "attached_dev");
if (err) if (!err) {
goto error; err = sysfs_create_link(&dev->dev.kobj, &phydev->mdio.dev.kobj,
"phydev");
if (err)
goto error;
err = sysfs_create_link(&dev->dev.kobj, &phydev->mdio.dev.kobj, phydev->sysfs_links = true;
"phydev"); }
if (err)
goto error;
phydev->dev_flags = flags; phydev->dev_flags = flags;
...@@ -1059,8 +1071,10 @@ void phy_detach(struct phy_device *phydev) ...@@ -1059,8 +1071,10 @@ void phy_detach(struct phy_device *phydev)
struct mii_bus *bus; struct mii_bus *bus;
int i; int i;
sysfs_remove_link(&dev->dev.kobj, "phydev"); if (phydev->sysfs_links) {
sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev"); sysfs_remove_link(&dev->dev.kobj, "phydev");
sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev");
}
phydev->attached_dev->phydev = NULL; phydev->attached_dev->phydev = NULL;
phydev->attached_dev = NULL; phydev->attached_dev = NULL;
phy_suspend(phydev); phy_suspend(phydev);
......
...@@ -363,6 +363,7 @@ struct phy_c45_device_ids { ...@@ -363,6 +363,7 @@ struct phy_c45_device_ids {
* is_pseudo_fixed_link: Set to true if this phy is an Ethernet switch, etc. * is_pseudo_fixed_link: Set to true if this phy is an Ethernet switch, etc.
* has_fixups: Set to true if this phy has fixups/quirks. * has_fixups: Set to true if this phy has fixups/quirks.
* suspended: Set to true if this phy has been suspended successfully. * suspended: Set to true if this phy has been suspended successfully.
* sysfs_links: Internal boolean tracking sysfs symbolic links setup/removal.
* state: state of the PHY for management purposes * state: state of the PHY for management purposes
* dev_flags: Device-specific flags used by the PHY driver. * dev_flags: Device-specific flags used by the PHY driver.
* link_timeout: The number of timer firings to wait before the * link_timeout: The number of timer firings to wait before the
...@@ -399,6 +400,7 @@ struct phy_device { ...@@ -399,6 +400,7 @@ struct phy_device {
bool is_pseudo_fixed_link; bool is_pseudo_fixed_link;
bool has_fixups; bool has_fixups;
bool suspended; bool suspended;
bool sysfs_links;
enum phy_state state; enum phy_state state;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment