]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
cfg80211: combine duplicate wdev init code
authorJohannes Berg <johannes.berg@intel.com>
Thu, 13 Sep 2018 12:12:03 +0000 (14:12 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 2 Oct 2018 07:56:29 +0000 (09:56 +0200)
There's a bit of duplicated code to initialize a wdev, pull it out
into a separate function to call from both places.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/wireless/core.c
net/wireless/core.h
net/wireless/nl80211.c

index 4d5215e6b534e2c39c0e2d7af99e2cca01fb62c4..144eab227748fc7879d9d70fea0514bcad6750c6 100644 (file)
@@ -1153,6 +1153,28 @@ void cfg80211_stop_iface(struct wiphy *wiphy, struct wireless_dev *wdev,
 }
 EXPORT_SYMBOL(cfg80211_stop_iface);
 
+void cfg80211_init_wdev(struct cfg80211_registered_device *rdev,
+                       struct wireless_dev *wdev)
+{
+       mutex_init(&wdev->mtx);
+       INIT_LIST_HEAD(&wdev->event_list);
+       spin_lock_init(&wdev->event_lock);
+       INIT_LIST_HEAD(&wdev->mgmt_registrations);
+       spin_lock_init(&wdev->mgmt_registrations_lock);
+
+       /*
+        * We get here also when the interface changes network namespaces,
+        * as it's registered into the new one, but we don't want it to
+        * change ID in that case. Checking if the ID is already assigned
+        * works, because 0 isn't considered a valid ID and the memory is
+        * 0-initialized.
+        */
+       if (!wdev->identifier)
+               wdev->identifier = ++rdev->wdev_id;
+       list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
+       rdev->devlist_generation++;
+}
+
 static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
                                         unsigned long state, void *ptr)
 {
@@ -1178,23 +1200,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
                 * called within code protected by it when interfaces
                 * are added with nl80211.
                 */
-               mutex_init(&wdev->mtx);
-               INIT_LIST_HEAD(&wdev->event_list);
-               spin_lock_init(&wdev->event_lock);
-               INIT_LIST_HEAD(&wdev->mgmt_registrations);
-               spin_lock_init(&wdev->mgmt_registrations_lock);
-
-               /*
-                * We get here also when the interface changes network namespaces,
-                * as it's registered into the new one, but we don't want it to
-                * change ID in that case. Checking if the ID is already assigned
-                * works, because 0 isn't considered a valid ID and the memory is
-                * 0-initialized.
-                */
-               if (!wdev->identifier)
-                       wdev->identifier = ++rdev->wdev_id;
-               list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
-               rdev->devlist_generation++;
+               cfg80211_init_wdev(rdev, wdev);
                /* can only change netns with wiphy */
                dev->features |= NETIF_F_NETNS_LOCAL;
 
index 7f52ef56932035fe0d0a503128a9e24f88c0dd22..45fd4e21dbda8687e1914107679c0d7496662741 100644 (file)
@@ -187,6 +187,9 @@ struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
 int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
                          struct net *net);
 
+void cfg80211_init_wdev(struct cfg80211_registered_device *rdev,
+                       struct wireless_dev *wdev);
+
 static inline void wdev_lock(struct wireless_dev *wdev)
        __acquires(wdev)
 {
index b4908bcb0d77e58dbcf55f389456bc71c4ca0540..0827cbdbb7b68feb4bdf7c19e3cec3578035363e 100644 (file)
@@ -3252,15 +3252,7 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
                 * P2P Device and NAN do not have a netdev, so don't go
                 * through the netdev notifier and must be added here
                 */
-               mutex_init(&wdev->mtx);
-               INIT_LIST_HEAD(&wdev->event_list);
-               spin_lock_init(&wdev->event_lock);
-               INIT_LIST_HEAD(&wdev->mgmt_registrations);
-               spin_lock_init(&wdev->mgmt_registrations_lock);
-
-               wdev->identifier = ++rdev->wdev_id;
-               list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
-               rdev->devlist_generation++;
+               cfg80211_init_wdev(rdev, wdev);
                break;
        default:
                break;