]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
net: call dev_alloc_name from register_netdevice
authorJiri Pirko <jpirko@redhat.com>
Sat, 30 Apr 2011 01:21:32 +0000 (01:21 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 5 May 2011 17:57:45 +0000 (10:57 -0700)
Force dev_alloc_name() to be called from register_netdevice() by
dev_get_valid_name(). That allows to remove multiple explicit
dev_alloc_name() calls.

The possibility to call dev_alloc_name in advance remains.

This also fixes veth creation regresion caused by
84c49d8c3e4abefb0a41a77b25aa37ebe8d6b743

Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
20 files changed:
drivers/ieee802154/fakehard.c
drivers/net/bonding/bond_main.c
drivers/net/dummy.c
drivers/net/hamradio/bpqether.c
drivers/net/ifb.c
drivers/net/tun.c
drivers/net/wan/dlci.c
drivers/net/wan/hdlc_fr.c
drivers/net/wan/lapbether.c
drivers/net/wireless/hostap/hostap_main.c
drivers/net/wireless/mac80211_hwsim.c
drivers/net/wireless/mwifiex/main.c
drivers/s390/net/netiucv.c
net/core/dev.c
net/core/rtnetlink.c
net/ipv4/ip_gre.c
net/ipv4/ipip.c
net/ipv6/ip6_tunnel.c
net/ipv6/sit.c
net/mac80211/iface.c

index d9d0e13efe47bc3f9610d412e7799cc67042ac1f..a5a49a1baae7227ce754a9a10806fa61e1262346 100644 (file)
@@ -393,16 +393,6 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
        priv = netdev_priv(dev);
        priv->phy = phy;
 
-       /*
-        * If the name is a format string the caller wants us to do a
-        * name allocation.
-        */
-       if (strchr(dev->name, '%')) {
-               err = dev_alloc_name(dev, dev->name);
-               if (err < 0)
-                       goto out;
-       }
-
        wpan_phy_set_dev(phy, &pdev->dev);
        SET_NETDEV_DEV(dev, &phy->dev);
 
index 22bd03bd1d3598a90b18797928fd4cf1531b3267..9a5feaf4bab9a1fb231a8b0c2471656d7760be6f 100644 (file)
@@ -4917,8 +4917,9 @@ int bond_create(struct net *net, const char *name)
 
        rtnl_lock();
 
-       bond_dev = alloc_netdev_mq(sizeof(struct bonding), name ? name : "",
-                               bond_setup, tx_queues);
+       bond_dev = alloc_netdev_mq(sizeof(struct bonding),
+                                  name ? name : "bond%d",
+                                  bond_setup, tx_queues);
        if (!bond_dev) {
                pr_err("%s: eek! can't alloc netdev!\n", name);
                rtnl_unlock();
@@ -4928,26 +4929,10 @@ int bond_create(struct net *net, const char *name)
        dev_net_set(bond_dev, net);
        bond_dev->rtnl_link_ops = &bond_link_ops;
 
-       if (!name) {
-               res = dev_alloc_name(bond_dev, "bond%d");
-               if (res < 0)
-                       goto out;
-       } else {
-               /*
-                * If we're given a name to register
-                * we need to ensure that its not already
-                * registered
-                */
-               res = -EEXIST;
-               if (__dev_get_by_name(net, name) != NULL)
-                       goto out;
-       }
-
        res = register_netdevice(bond_dev);
 
        netif_carrier_off(bond_dev);
 
-out:
        rtnl_unlock();
        if (res < 0)
                bond_destructor(bond_dev);
index ff2d29b178587eebfd22feba9e21aae496f12b17..39cf9b9bd673cdd0d46aed0c970ca58cccbedc88 100644 (file)
@@ -168,10 +168,6 @@ static int __init dummy_init_one(void)
        if (!dev_dummy)
                return -ENOMEM;
 
-       err = dev_alloc_name(dev_dummy, dev_dummy->name);
-       if (err < 0)
-               goto err;
-
        dev_dummy->rtnl_link_ops = &dummy_link_ops;
        err = register_netdevice(dev_dummy);
        if (err < 0)
index 8931168d3e743a14fb412ed7d4e32b96dbcaffb7..18d8affecd1bff7b0aacdc22adacb8daab59b2c4 100644 (file)
@@ -516,10 +516,6 @@ static int bpq_new_device(struct net_device *edev)
        memcpy(bpq->dest_addr, bcast_addr, sizeof(bpq_eth_addr));
        memcpy(bpq->acpt_addr, bcast_addr, sizeof(bpq_eth_addr));
 
-       err = dev_alloc_name(ndev, ndev->name);
-       if (err < 0) 
-               goto error;
-
        err = register_netdevice(ndev);
        if (err)
                goto error;
index e07d487f015a7a8f5f5ba865cdc5f75b318ae4c8..4fecaed67fc4c3034f6b8cbbbeae83758b96ae2f 100644 (file)
@@ -233,10 +233,6 @@ static int __init ifb_init_one(int index)
        if (!dev_ifb)
                return -ENOMEM;
 
-       err = dev_alloc_name(dev_ifb, dev_ifb->name);
-       if (err < 0)
-               goto err;
-
        dev_ifb->rtnl_link_ops = &ifb_link_ops;
        err = register_netdevice(dev_ifb);
        if (err < 0)
index 0636f70403259ac44b2faa6f4988f8e3c92327e8..74e94054ab1a29d41828c7b9358518733eba0754 100644 (file)
@@ -1099,12 +1099,6 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 
                tun_net_init(dev);
 
-               if (strchr(dev->name, '%')) {
-                       err = dev_alloc_name(dev, dev->name);
-                       if (err < 0)
-                               goto err_free_sk;
-               }
-
                dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST |
                        TUN_USER_FEATURES;
                dev->features = dev->hw_features;
index 1481a446fefbf6f058c14b6591501b3249ae2d8b..21b104db5a9089b9c458251b08a904aec418ac41 100644 (file)
@@ -341,10 +341,6 @@ static int dlci_add(struct dlci_add *dlci)
                }
        }
 
-       err = dev_alloc_name(master, master->name);
-       if (err < 0)
-               goto err2;
-
        *(short *)(master->dev_addr) = dlci->dlci;
 
        dlp = netdev_priv(master);
index 0edb535bb2b5a746c624291288b9e973c7a76c50..fc433f28c047cf77e15c9fc19010d2e94e74a57a 100644 (file)
@@ -1070,7 +1070,7 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
        hdlc_device *hdlc = dev_to_hdlc(frad);
        pvc_device *pvc;
        struct net_device *dev;
-       int result, used;
+       int used;
 
        if ((pvc = add_pvc(frad, dlci)) == NULL) {
                printk(KERN_WARNING "%s: Memory squeeze on fr_add_pvc()\n",
@@ -1106,13 +1106,6 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
        dev->tx_queue_len = 0;
        dev->ml_priv = pvc;
 
-       result = dev_alloc_name(dev, dev->name);
-       if (result < 0) {
-               free_netdev(dev);
-               delete_unused_pvcs(hdlc);
-               return result;
-       }
-
        if (register_netdevice(dev) != 0) {
                free_netdev(dev);
                delete_unused_pvcs(hdlc);
index 7f5bb913c8b928ad20b8aa9bb8a0b84b5adcbbab..eec463f99c09625c52a485080a3492baea28fe34 100644 (file)
@@ -338,10 +338,6 @@ static int lapbeth_new_device(struct net_device *dev)
        dev_hold(dev);
        lapbeth->ethdev = dev;
 
-       rc = dev_alloc_name(ndev, ndev->name);
-       if (rc < 0) 
-               goto fail;
-
        rc = -EIO;
        if (register_netdevice(ndev))
                goto fail;
index 1d9aed6457234fe0cc18c34fe198dc6ca4e4d62b..d5084829c9e5426946ce6554e712d40796fa2695 100644 (file)
@@ -79,13 +79,8 @@ struct net_device * hostap_add_interface(struct local_info *local,
        if (!rtnl_locked)
                rtnl_lock();
 
-       ret = 0;
-       if (strchr(dev->name, '%'))
-               ret = dev_alloc_name(dev, dev->name);
-
        SET_NETDEV_DEV(dev, mdev->dev.parent);
-       if (ret >= 0)
-               ret = register_netdevice(dev);
+       ret = register_netdevice(dev);
 
        if (!rtnl_locked)
                rtnl_unlock();
index f4f4257a9d67e4c1e6e4ac112cd03a71dd5ba944..9d4a40ee16c4f5987bd1d08d766c87b7b35332e5 100644 (file)
@@ -1515,19 +1515,10 @@ static int __init init_mac80211_hwsim(void)
        if (hwsim_mon == NULL)
                goto failed;
 
-       rtnl_lock();
-
-       err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
+       err = register_netdev(hwsim_mon);
        if (err < 0)
                goto failed_mon;
 
-
-       err = register_netdevice(hwsim_mon);
-       if (err < 0)
-               goto failed_mon;
-
-       rtnl_unlock();
-
        return 0;
 
 failed_mon:
index c5971880e7b37e4a01f3c80bb5660de851aaecfc..d16cea770fa36b4d72c842064d540bcf1b19182e 100644 (file)
@@ -706,10 +706,6 @@ static struct mwifiex_private *mwifiex_add_interface(
                dev_err(adapter->dev, "no memory available for netdevice\n");
                goto error;
        }
-       if (dev_alloc_name(dev, dev->name)) {
-               dev_err(adapter->dev, "unable to alloc name for netdevice\n");
-               goto error;
-       }
 
        if (mwifiex_register_cfg80211(dev, adapter->priv[bss_index]->curr_addr,
                                      adapter->priv[bss_index]) != 0) {
index b6a6356d09b3a52857a1f47f14d1a2241b04e142..3251333a23df18b6e8f378f0f681ac818145f0e1 100644 (file)
@@ -1994,8 +1994,6 @@ static struct net_device *netiucv_init_netdevice(char *username)
                           netiucv_setup_netdevice);
        if (!dev)
                return NULL;
-       if (dev_alloc_name(dev, dev->name) < 0)
-               goto out_netdev;
 
        privptr = netdev_priv(dev);
        privptr->fsm = init_fsm("netiucvdev", dev_state_names,
index e95dc30110ebec687c6a3a4b968143fbfeb11a01..3b79bad3d02d3292330b8e92efa7bfe6b783fd40 100644 (file)
@@ -948,7 +948,7 @@ int dev_alloc_name(struct net_device *dev, const char *name)
 }
 EXPORT_SYMBOL(dev_alloc_name);
 
-static int dev_get_valid_name(struct net_device *dev, const char *name, bool fmt)
+static int dev_get_valid_name(struct net_device *dev, const char *name)
 {
        struct net *net;
 
@@ -958,7 +958,7 @@ static int dev_get_valid_name(struct net_device *dev, const char *name, bool fmt
        if (!dev_valid_name(name))
                return -EINVAL;
 
-       if (fmt && strchr(name, '%'))
+       if (strchr(name, '%'))
                return dev_alloc_name(dev, name);
        else if (__dev_get_by_name(net, name))
                return -EEXIST;
@@ -995,7 +995,7 @@ int dev_change_name(struct net_device *dev, const char *newname)
 
        memcpy(oldname, dev->name, IFNAMSIZ);
 
-       err = dev_get_valid_name(dev, newname, 1);
+       err = dev_get_valid_name(dev, newname);
        if (err < 0)
                return err;
 
@@ -5420,8 +5420,8 @@ int register_netdevice(struct net_device *dev)
                }
        }
 
-       ret = dev_get_valid_name(dev, dev->name, 0);
-       if (ret)
+       ret = dev_get_valid_name(dev, dev->name);
+       if (ret < 0)
                goto err_uninit;
 
        dev->ifindex = dev_new_index(net);
@@ -5562,19 +5562,7 @@ int register_netdev(struct net_device *dev)
        int err;
 
        rtnl_lock();
-
-       /*
-        * If the name is a format string the caller wants us to do a
-        * name allocation.
-        */
-       if (strchr(dev->name, '%')) {
-               err = dev_alloc_name(dev, dev->name);
-               if (err < 0)
-                       goto out;
-       }
-
        err = register_netdevice(dev);
-out:
        rtnl_unlock();
        return err;
 }
@@ -6056,7 +6044,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
                /* We get here if we can't use the current device name */
                if (!pat)
                        goto out;
-               if (dev_get_valid_name(dev, pat, 1))
+               if (dev_get_valid_name(dev, pat) < 0)
                        goto out;
        }
 
index 2963312571954dd7b3697102b58c325f879dea32..5a160f4a1ba0d1a7529f5c5824deae0761d74c9b 100644 (file)
@@ -1572,12 +1572,6 @@ struct net_device *rtnl_create_link(struct net *src_net, struct net *net,
        dev->rtnl_link_state = RTNL_LINK_INITIALIZING;
        dev->real_num_tx_queues = real_num_queues;
 
-       if (strchr(dev->name, '%')) {
-               err = dev_alloc_name(dev, dev->name);
-               if (err < 0)
-                       goto err_free;
-       }
-
        if (tb[IFLA_MTU])
                dev->mtu = nla_get_u32(tb[IFLA_MTU]);
        if (tb[IFLA_ADDRESS])
@@ -1597,8 +1591,6 @@ struct net_device *rtnl_create_link(struct net *src_net, struct net *net,
 
        return dev;
 
-err_free:
-       free_netdev(dev);
 err:
        return ERR_PTR(err);
 }
index 10e9b5aea07030c47f7f1dd880013b47685231ac..8871067560dba3ee7686fd2add36bc50f5f2587c 100644 (file)
@@ -413,11 +413,6 @@ static struct ip_tunnel *ipgre_tunnel_locate(struct net *net,
 
        dev_net_set(dev, net);
 
-       if (strchr(name, '%')) {
-               if (dev_alloc_name(dev, name) < 0)
-                       goto failed_free;
-       }
-
        nt = netdev_priv(dev);
        nt->parms = *parms;
        dev->rtnl_link_ops = &ipgre_link_ops;
index bfa0b9895040c39bdc62cd6cf5457ca34a0f89ce..378b20b7ca6e7401c9c4041635606b5a2526ccb6 100644 (file)
@@ -276,11 +276,6 @@ static struct ip_tunnel * ipip_tunnel_locate(struct net *net,
 
        dev_net_set(dev, net);
 
-       if (strchr(name, '%')) {
-               if (dev_alloc_name(dev, name) < 0)
-                       goto failed_free;
-       }
-
        nt = netdev_priv(dev);
        nt->parms = *parms;
 
index 3dff27cba95c2e76952582b9f79bc58f7bfdc48b..36c2842a86b25c8714e166b4b01a8293ebb2fa1b 100644 (file)
@@ -280,11 +280,6 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct ip6_tnl_parm *p)
 
        dev_net_set(dev, net);
 
-       if (strchr(name, '%')) {
-               if (dev_alloc_name(dev, name) < 0)
-                       goto failed_free;
-       }
-
        t = netdev_priv(dev);
        t->parms = *p;
        err = ip6_tnl_dev_init(dev);
index c53abcf50d298b05d59ce0db1b9fe82960e79d31..a6a32b39b60748ac99ed40ccae23db62a438ac35 100644 (file)
@@ -250,11 +250,6 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net,
 
        dev_net_set(dev, net);
 
-       if (strchr(name, '%')) {
-               if (dev_alloc_name(dev, name) < 0)
-                       goto failed_free;
-       }
-
        nt = netdev_priv(dev);
 
        nt->parms = *parms;
index 4054399be907f8be54d07cf786afc5693e562982..80c29d626aa4ae5d801d20f6ba1e6a8b9c48b2a1 100644 (file)
@@ -1144,10 +1144,6 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
                                + IEEE80211_ENCRYPT_HEADROOM;
        ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
 
-       ret = dev_alloc_name(ndev, ndev->name);
-       if (ret < 0)
-               goto fail;
-
        ieee80211_assign_perm_addr(local, ndev, type);
        memcpy(ndev->dev_addr, ndev->perm_addr, ETH_ALEN);
        SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));