Skip to content

Commit e804441

Browse files
ffainellidavem330
authored andcommitted
net: dsa: Fix network device registration order
We cannot be registering the network device first, then setting its carrier off and finally connecting it to a PHY, doing that leaves a window during which the carrier is at best inconsistent, and at worse the device is not usable without a down/up sequence since the network device is visible to user space with possibly no PHY device attached. Re-order steps so that they make logical sense. This fixes some devices where the port was not usable after e.g: an unbind then bind of the driver. Fixes: 0071f56 ("dsa: Register netdev before phy") Fixes: 91da11f ("net: Distributed Switch Architecture protocol support") Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent db06ae4 commit e804441

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

net/dsa/slave.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,28 +1301,33 @@ int dsa_slave_create(struct dsa_port *port, const char *name)
13011301
p->old_duplex = -1;
13021302

13031303
port->netdev = slave_dev;
1304-
ret = register_netdev(slave_dev);
1305-
if (ret) {
1306-
netdev_err(master, "error %d registering interface %s\n",
1307-
ret, slave_dev->name);
1308-
port->netdev = NULL;
1309-
free_percpu(p->stats64);
1310-
free_netdev(slave_dev);
1311-
return ret;
1312-
}
13131304

13141305
netif_carrier_off(slave_dev);
13151306

13161307
ret = dsa_slave_phy_setup(p, slave_dev);
13171308
if (ret) {
13181309
netdev_err(master, "error %d setting up slave phy\n", ret);
1319-
unregister_netdev(slave_dev);
1320-
free_percpu(p->stats64);
1321-
free_netdev(slave_dev);
1322-
return ret;
1310+
goto out_free;
1311+
}
1312+
1313+
ret = register_netdev(slave_dev);
1314+
if (ret) {
1315+
netdev_err(master, "error %d registering interface %s\n",
1316+
ret, slave_dev->name);
1317+
goto out_phy;
13231318
}
13241319

13251320
return 0;
1321+
1322+
out_phy:
1323+
phy_disconnect(p->phy);
1324+
if (of_phy_is_fixed_link(p->dp->dn))
1325+
of_phy_deregister_fixed_link(p->dp->dn);
1326+
out_free:
1327+
free_percpu(p->stats64);
1328+
free_netdev(slave_dev);
1329+
port->netdev = NULL;
1330+
return ret;
13261331
}
13271332

13281333
void dsa_slave_destroy(struct net_device *slave_dev)

0 commit comments

Comments
 (0)