Commit 6146dd45 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: dsa: Avoid null pointer when failing to connect to PHY

When phylink_of_phy_connect fails, dsa_slave_phy_setup tries to save the
day by connecting to an alternative PHY, none other than a PHY on the
switch's internal MDIO bus, at an address equal to the port's index.

However this does not take into consideration the scenario when the
switch that failed to probe an external PHY does not have an internal
MDIO bus at all.

Fixes: aab9c406 ("net: dsa: Plug in PHYLINK support")
Signed-off-by: default avatarVladimir Oltean <olteanv@gmail.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9675db39
...@@ -1283,9 +1283,9 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) ...@@ -1283,9 +1283,9 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
phy_flags = ds->ops->get_phy_flags(ds, dp->index); phy_flags = ds->ops->get_phy_flags(ds, dp->index);
ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags); ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
if (ret == -ENODEV) { if (ret == -ENODEV && ds->slave_mii_bus) {
/* We could not connect to a designated PHY or SFP, so use the /* We could not connect to a designated PHY or SFP, so try to
* switch internal MDIO bus instead * use the switch internal MDIO bus instead
*/ */
ret = dsa_slave_phy_connect(slave_dev, dp->index); ret = dsa_slave_phy_connect(slave_dev, dp->index);
if (ret) { if (ret) {
...@@ -1297,7 +1297,7 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) ...@@ -1297,7 +1297,7 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
} }
} }
return 0; return ret;
} }
static struct lock_class_key dsa_slave_netdev_xmit_lock_key; static struct lock_class_key dsa_slave_netdev_xmit_lock_key;
......
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