Skip to contentSkip to conversation

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

net-next Applied Vladimir Oltean 3 participants 3 messages Mar 23, 2019 – Mar 26, 2019

Subsystems (3)
lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

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 aab9c4067d23 ("net: dsa: Plug in PHYLINK support")
---
 net/dsa/slave.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/dsa/slave.c +4 -4
index 093eef6f2599..6a8418dfa64f 100644
@@ -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);
 
 	ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
-	if (ret == -ENODEV) {
-		/* We could not connect to a designated PHY or SFP, so use the
-		 * switch internal MDIO bus instead
+	if (ret == -ENODEV && ds->slave_mii_bus) {
+		/* We could not connect to a designated PHY or SFP, so try to
+		 * use the switch internal MDIO bus instead
 		 */
 		ret = dsa_slave_phy_connect(slave_dev, dp->index);
 		if (ret) {
@@ -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;
Signature · 1 line
2.17.1
Reviewed-by
#1 lore raw
Quoted 10 lines · Vladimir Oltean

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 aab9c4067d23 ("net: dsa: Plug in PHYLINK support")

This goes back to before that commit, pretty much since 0d8bcdd383b8865e752a7e8edb4712c2e3902052 ("net: dsa: allow for more complex PHY setups").

Signature · 1 line
Florian
maintainer Applied
#2 lore raw
In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>
Date: Sun, 24 Mar 2019 01:24:07 +0200

Quoted 10 lines

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 aab9c4067d23 ("net: dsa: Plug in PHYLINK support")

Applied.