Skip to contentSkip to conversation

net: dsa: two small bug fixes

PATCH In review Florian Fainelli 3 participants 5 messages Dec 11, 2014 – Dec 16, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover net: dsa: two small bug fixes

Hi David,

Here are two small fixes for the DSA slave interface creation code:

- first patch fixes a null pointer de-reference with an invalid PHY device pointer while calling phy_connect_direct()

- second path propagates the dsa_slave_phy_setup() error code down to its caller: dsa_slave_create

Thanks!

Florian Fainelli (2):
net: dsa: handle non-existing PHYs on switch internal bus
net: dsa: propagate error code from dsa_slave_phy_setup

 net/dsa/slave.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/2 net: dsa: handle non-existing PHYs on switch internal bus

In case there is no PHY at the designated address on the internal switch, we would basically de-reference a null pointer here:

dsa_slave_phy_setup(...)

{
	p->phy = ds->slave_mii_bus->phy_map[p->port];
	phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
				      ^------

This can be triggered when the platform configuration (platform_data or Device Tree) indicates there should be a PHY device at this address, but the HW is non-responsive, such that we cannot attach a PHY device at this specific location.

Fix this by checking the return value prior to calling phy_connect_direct().

CC Andrew Lunn <[email protected]>
Fixes b31f65fb4383 ("net: dsa: slave: Fix autoneg for phys on switch MDIO bus")
---
 net/dsa/slave.c | 3 +++
 1 file changed, 3 insertions(+)
net/dsa/slave.c +3 -0
index ab03e00ffe8f..0efaab1e408b 100644
@@ -491,6 +491,9 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
 	 */
 	if (!p->phy) {
 		p->phy = ds->slave_mii_bus->phy_map[p->port];
+		if (!p->phy)
+			return;
+
 		phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
 				   p->phy_interface);
 	} else {
Signature · 1 line
2.1.0
#3 lore raw

PATCH 2/2 net: dsa: propagate error code from dsa_slave_phy_setup

In reply to Florian Fainelli

In case we cannot attach to our slave netdevice PHY, error out and propagate that error up to the caller: dsa_slave_create().

Fixes 0d8bcdd383b8 ("net: dsa: allow for more complex PHY setups")
---
 net/dsa/slave.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
net/dsa/slave.c +11 -4
index 0efaab1e408b..646c24ce4501 100644
@@ -448,7 +448,7 @@ static int dsa_slave_fixed_link_update(struct net_device *dev,
 }
 
 /* slave device setup *******************************************************/
-static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
+static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
 				struct net_device *slave_dev)
 {
 	struct dsa_switch *ds = p->parent;
@@ -469,7 +469,7 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
 		ret = of_phy_register_fixed_link(port_dn);
 		if (ret) {
 			pr_err("failed to register fixed PHY\n");
-			return;
+			return ret;
 		}
 		phy_is_fixed = true;
 		phy_dn = port_dn;
@@ -492,7 +492,7 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
 	if (!p->phy) {
 		p->phy = ds->slave_mii_bus->phy_map[p->port];
 		if (!p->phy)
-			return;
+			return -ENODEV;
 
 		phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
 				   p->phy_interface);
@@ -500,6 +500,8 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
 		pr_info("attached PHY at address %d [%s]\n",
 			p->phy->addr, p->phy->drv->name);
 	}
+
+	return 0;
 }
 
 int dsa_slave_suspend(struct net_device *slave_dev)
@@ -592,12 +594,17 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,
 	p->old_link = -1;
 	p->old_duplex = -1;
 
-	dsa_slave_phy_setup(p, slave_dev);
+	ret = dsa_slave_phy_setup(p, slave_dev);
+	if (ret) {
+		free_netdev(slave_dev);
+		return NULL;
+	}
 
 	ret = register_netdev(slave_dev);
 	if (ret) {
 		printk(KERN_ERR "%s: error %d registering interface %s\n",
 				master->name, ret, slave_dev->name);
+		phy_disconnect(p->phy);
 		free_netdev(slave_dev);
 		return NULL;
 	}
Signature · 1 line
2.1.0
maintainer
#4 lore raw
In reply to Florian Fainelli

From: Florian Fainelli <[email protected]>
Date: Thu, 11 Dec 2014 12:49:14 -0800

Quoted 7 lines

Here are two small fixes for the DSA slave interface creation code:

- first patch fixes a null pointer de-reference with an invalid PHY device pointer while calling phy_connect_direct()

- second path propagates the dsa_slave_phy_setup() error code down to its caller: dsa_slave_create

Series applied.

Please give me some feedback on the FIXED_PHY Kconfig issue I asked you about earlier today.

Thanks.

maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH net 1/2] net: dsa: handle non-existing PHYs on switch internal bus

In reply to Florian Fainelli
Quoted 14 lines · Florian Fainelli

In case there is no PHY at the designated address on the internal switch, we would basically de-reference a null pointer here:

dsa_slave_phy_setup(...)

{
	p->phy = ds->slave_mii_bus->phy_map[p->port];
	phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
				      ^------

This can be triggered when the platform configuration (platform_data or Device Tree) indicates there should be a PHY device at this address, but the HW is non-responsive, such that we cannot attach a PHY device at this specific location.

Quoted 8 lines

Fix this by checking the return value prior to calling phy_connect_direct().

CC Andrew Lunn <[email protected]>
Fixes b31f65fb4383 ("net: dsa: slave: Fix autoneg for phys on switch MDIO bus")

Andrew

Quoted 21 lines
---
 net/dsa/slave.c | 3 +++
 1 file changed, 3 insertions(+)
net/dsa/slave.c +3 -0
index ab03e00ffe8f..0efaab1e408b 100644
@@ -491,6 +491,9 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
 	 */
 	if (!p->phy) {
 		p->phy = ds->slave_mii_bus->phy_map[p->port];
+		if (!p->phy)
+			return;
+
 		phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
 				   p->phy_interface);
 	} else {
Signature · 1 line
2.1.0