diff mbox

[RFC,27/28] dsa: slave: Don't reference NULL pointer during phy_disconnect

Message ID 1450875402-20740-28-git-send-email-andrew@lunn.ch
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

Andrew Lunn Dec. 23, 2015, 12:56 p.m. UTC
When the phy is disconnected, the parent pointer to the netdev it was
attached to is set to NULL. The code then tries to suspend the phy,
but dsa_slave_fixed_link_update needs the parent pointer to determine
which switch the phy is connected to. So it dereferenced a NULL
pointer. Check for this condition.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/slave.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Florian Fainelli Dec. 23, 2015, 8:45 p.m. UTC | #1
Le 23/12/2015 04:56, Andrew Lunn a écrit :
> When the phy is disconnected, the parent pointer to the netdev it was
> attached to is set to NULL. The code then tries to suspend the phy,
> but dsa_slave_fixed_link_update needs the parent pointer to determine
> which switch the phy is connected to. So it dereferenced a NULL
> pointer. Check for this condition.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Acked-by: Florian Fainelli <f.fainelli@gmail.com>
diff mbox

Patch

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 1e9e9424a33d..b7f8a40e51d4 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -981,11 +981,15 @@  static void dsa_slave_adjust_link(struct net_device *dev)
 static int dsa_slave_fixed_link_update(struct net_device *dev,
 				       struct fixed_phy_status *status)
 {
-	struct dsa_slave_priv *p = netdev_priv(dev);
-	struct dsa_switch *ds = p->parent;
+	struct dsa_slave_priv *p;
+	struct dsa_switch *ds;
 
-	if (ds->drv->fixed_link_update)
-		ds->drv->fixed_link_update(ds, p->port, status);
+	if (dev) {
+		p = netdev_priv(dev);
+		ds = p->parent;
+		if (ds->drv->fixed_link_update)
+			ds->drv->fixed_link_update(ds, p->port, status);
+	}
 
 	return 0;
 }