net: introduce a function to check if a netdev name is in use
[platform/kernel/linux-starfive.git] / net / core / dev.c
index 7ee9fec..1594cd2 100644 (file)
@@ -303,6 +303,12 @@ static struct netdev_name_node *netdev_name_node_lookup_rcu(struct net *net,
        return NULL;
 }
 
+bool netdev_name_in_use(struct net *net, const char *name)
+{
+       return netdev_name_node_lookup(net, name);
+}
+EXPORT_SYMBOL(netdev_name_in_use);
+
 int netdev_name_node_alt_create(struct net_device *dev, const char *name)
 {
        struct netdev_name_node *name_node;
@@ -1133,7 +1139,7 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
        }
 
        snprintf(buf, IFNAMSIZ, name, i);
-       if (!__dev_get_by_name(net, buf))
+       if (!netdev_name_in_use(net, buf))
                return i;
 
        /* It is possible to run out of possible slots
@@ -1187,7 +1193,7 @@ static int dev_get_valid_name(struct net *net, struct net_device *dev,
 
        if (strchr(name, '%'))
                return dev_alloc_name_ns(net, dev, name);
-       else if (__dev_get_by_name(net, name))
+       else if (netdev_name_in_use(net, name))
                return -EEXIST;
        else if (dev->name != name)
                strlcpy(dev->name, name, IFNAMSIZ);
@@ -2921,6 +2927,8 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq)
                if (dev->num_tc)
                        netif_setup_tc(dev, txq);
 
+               dev_qdisc_change_real_num_tx(dev, txq);
+
                dev->real_num_tx_queues = txq;
 
                if (disabling) {
@@ -5837,7 +5845,7 @@ static void gro_normal_one(struct napi_struct *napi, struct sk_buff *skb, int se
                gro_normal_list(napi);
 }
 
-static int napi_gro_complete(struct napi_struct *napi, struct sk_buff *skb)
+static void napi_gro_complete(struct napi_struct *napi, struct sk_buff *skb)
 {
        struct packet_offload *ptype;
        __be16 type = skb->protocol;
@@ -5866,12 +5874,11 @@ static int napi_gro_complete(struct napi_struct *napi, struct sk_buff *skb)
        if (err) {
                WARN_ON(&ptype->list == head);
                kfree_skb(skb);
-               return NET_RX_SUCCESS;
+               return;
        }
 
 out:
        gro_normal_one(napi, skb, NAPI_GRO_CB(skb)->count);
-       return NET_RX_SUCCESS;
 }
 
 static void __napi_gro_flush_chain(struct napi_struct *napi, u32 index,
@@ -6898,19 +6905,25 @@ EXPORT_SYMBOL(netif_napi_add);
 
 void napi_disable(struct napi_struct *n)
 {
+       unsigned long val, new;
+
        might_sleep();
        set_bit(NAPI_STATE_DISABLE, &n->state);
 
-       while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
-               msleep(1);
-       while (test_and_set_bit(NAPI_STATE_NPSVC, &n->state))
-               msleep(1);
+       do {
+               val = READ_ONCE(n->state);
+               if (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
+                       usleep_range(20, 200);
+                       continue;
+               }
+
+               new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC;
+               new &= ~(NAPIF_STATE_THREADED | NAPIF_STATE_PREFER_BUSY_POLL);
+       } while (cmpxchg(&n->state, val, new) != val);
 
        hrtimer_cancel(&n->timer);
 
-       clear_bit(NAPI_STATE_PREFER_BUSY_POLL, &n->state);
        clear_bit(NAPI_STATE_DISABLE, &n->state);
-       clear_bit(NAPI_STATE_THREADED, &n->state);
 }
 EXPORT_SYMBOL(napi_disable);
 
@@ -11146,7 +11159,7 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net,
         * we can use it in the destination network namespace.
         */
        err = -EEXIST;
-       if (__dev_get_by_name(net, dev->name)) {
+       if (netdev_name_in_use(net, dev->name)) {
                /* We get here if we can't use the current device name */
                if (!pat)
                        goto out;
@@ -11499,7 +11512,7 @@ static void __net_exit default_device_exit(struct net *net)
 
                /* Push remaining network devices to init_net */
                snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
-               if (__dev_get_by_name(&init_net, fb_name))
+               if (netdev_name_in_use(&init_net, fb_name))
                        snprintf(fb_name, IFNAMSIZ, "dev%%d");
                err = dev_change_net_namespace(dev, &init_net, fb_name);
                if (err) {