vxlan: add necessary locking on device removal
[linux-drm-fsl-dcu.git] / drivers / net / vxlan.c
index 227b54a1f88ac6fd5b25005816b72b2a005e6a1e..a5ba8dd7e6bea33d060e9d5306b9eab6bb2095da 100644 (file)
@@ -1767,9 +1767,15 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
 
 static void vxlan_dellink(struct net_device *dev, struct list_head *head)
 {
+       struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id);
        struct vxlan_dev *vxlan = netdev_priv(dev);
 
+       flush_workqueue(vxlan_wq);
+
+       spin_lock(&vn->sock_lock);
        hlist_del_rcu(&vxlan->hlist);
+       spin_unlock(&vn->sock_lock);
+
        list_del(&vxlan->next);
        unregister_netdevice_queue(dev, head);
 }
@@ -1916,9 +1922,9 @@ late_initcall(vxlan_init_module);
 
 static void __exit vxlan_cleanup_module(void)
 {
-       unregister_pernet_device(&vxlan_net_ops);
        rtnl_link_unregister(&vxlan_link_ops);
        destroy_workqueue(vxlan_wq);
+       unregister_pernet_device(&vxlan_net_ops);
        rcu_barrier();
 }
 module_exit(vxlan_cleanup_module);