]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: move net_set_todo inside rollback_registered()
authorJakub Kicinski <kuba@kernel.org>
Tue, 19 Jan 2021 20:25:18 +0000 (12:25 -0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 21 Jan 2021 05:04:18 +0000 (21:04 -0800)
Commit 19dbffef8f48 ("[NET]: Fix free_netdev on register_netdev
failure.") moved net_set_todo() outside of rollback_registered()
so that rollback_registered() can be used in the failure path of
register_netdevice() but without risking a double free.

Since commit 7e09adf7d54b ("net: Fix inconsistent teardown and
release of private netdev state."), however, we have a better
way of handling that condition, since destructors don't call
free_netdev() directly.

After the change in commit 5a137c4f496a ("net: make free_netdev()
more lenient with unregistering devices") we can now move
net_set_todo() back.

Reviewed-by: Edwin Peer <edwin.peer@broadcom.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/dev.c

index 07a0347c33fb0c46f38d9d73250b5fc1060b1b0e..9476edf702646e5bf2dab5bdb8a3669d68bf26d5 100644 (file)
@@ -9546,8 +9546,10 @@ static void rollback_registered_many(struct list_head *head)
 
        synchronize_net();
 
-       list_for_each_entry(dev, head, unreg_list)
+       list_for_each_entry(dev, head, unreg_list) {
                dev_put(dev);
+               net_set_todo(dev);
+       }
 }
 
 static void rollback_registered(struct net_device *dev)
@@ -10109,7 +10111,6 @@ int register_netdevice(struct net_device *dev)
                /* Expect explicit free_netdev() on failure */
                dev->needs_free_netdev = false;
                rollback_registered(dev);
-               net_set_todo(dev);
                goto out;
        }
        /*
@@ -10732,8 +10733,6 @@ void unregister_netdevice_queue(struct net_device *dev, struct list_head *head)
                list_move_tail(&dev->unreg_list, head);
        } else {
                rollback_registered(dev);
-               /* Finish processing unregister after unlock */
-               net_set_todo(dev);
        }
 }
 EXPORT_SYMBOL(unregister_netdevice_queue);
@@ -10747,12 +10746,8 @@ EXPORT_SYMBOL(unregister_netdevice_queue);
  */
 void unregister_netdevice_many(struct list_head *head)
 {
-       struct net_device *dev;
-
        if (!list_empty(head)) {
                rollback_registered_many(head);
-               list_for_each_entry(dev, head, unreg_list)
-                       net_set_todo(dev);
                list_del(head);
        }
 }