net: dsa: Unregister slave_dev in error path
authorFlorian Fainelli <f.fainelli@gmail.com>
Thu, 18 Feb 2016 02:43:22 +0000 (18:43 -0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 18 Feb 2016 03:05:16 +0000 (22:05 -0500)
With commit 0071f56e46da ("dsa: Register netdev before phy"), we are now trying
to free a network device that has been previously registered, and in case of
errors, this will make us hit the BUG_ON(dev->reg_state != NETREG_UNREGISTERED)
condition.

Fix this by adding a missing unregister_netdev() before free_netdev().

Fixes: 0071f56e46da ("dsa: Register netdev before phy")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/slave.c

index 91e3b2ff364ab16ee55c5ebf8180aae498a32856..ab24521beb4d52ceb4bf09e846983954d54a67f0 100644 (file)
@@ -1204,6 +1204,7 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
        ret = dsa_slave_phy_setup(p, slave_dev);
        if (ret) {
                netdev_err(master, "error %d setting up slave phy\n", ret);
+               unregister_netdev(slave_dev);
                free_netdev(slave_dev);
                return ret;
        }