]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: wilc1000: set net device registration as last step during interface creation
authorAlexis Lothoré <alexis.lothore@bootlin.com>
Tue, 14 May 2024 15:51:19 +0000 (17:51 +0200)
committerKalle Valo <kvalo@kernel.org>
Fri, 17 May 2024 08:01:51 +0000 (11:01 +0300)
net device registration is currently done in wilc_netdev_ifc_init but
other initialization operations are still done after this registration.
Since net device is assumed to be usable right after registration, it
should be the very last step of initialization.

Move netdev registration at the very end of wilc_netdev_ifc_init to let
this function completely initialize netdevice before registering it.

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://msgid.link/20240514-mac_addr_at_probe-v2-1-afef09f1cd10@bootlin.com
drivers/net/wireless/microchip/wilc1000/netdev.c

index 73f56f7b002bf373277804db28c18cc8a4338a67..acc9b9a6455241106635b1a1ed042cc6b8f73902 100644 (file)
@@ -965,16 +965,6 @@ struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
        vif->priv.wdev.iftype = type;
        vif->priv.dev = ndev;
 
-       if (rtnl_locked)
-               ret = cfg80211_register_netdevice(ndev);
-       else
-               ret = register_netdev(ndev);
-
-       if (ret) {
-               ret = -EFAULT;
-               goto error;
-       }
-
        ndev->needs_free_netdev = true;
        vif->iftype = vif_type;
        vif->idx = wilc_get_available_idx(wl);
@@ -985,13 +975,24 @@ struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
        mutex_unlock(&wl->vif_mutex);
        synchronize_rcu();
 
-       return vif;
-
-error:
        if (rtnl_locked)
-               cfg80211_unregister_netdevice(ndev);
+               ret = cfg80211_register_netdevice(ndev);
        else
-               unregister_netdev(ndev);
+               ret = register_netdev(ndev);
+
+       if (ret) {
+               ret = -EFAULT;
+               goto error_remove_vif;
+       }
+
+       return vif;
+
+error_remove_vif:
+       mutex_lock(&wl->vif_mutex);
+       list_del_rcu(&vif->list);
+       wl->vif_num -= 1;
+       mutex_unlock(&wl->vif_mutex);
+       synchronize_rcu();
        free_netdev(ndev);
        return ERR_PTR(ret);
 }