]> Git Repo - linux.git/blobdiff - drivers/net/wireless/mac80211_hwsim.c
mac80211_hwsim: Make hwsim_netgroup IDA
[linux.git] / drivers / net / wireless / mac80211_hwsim.c
index 3c64afa161bf1727d8f015b8afa658c41b3e8ff3..45ba846bc28583475c7574df642d1117550343d7 100644 (file)
@@ -253,7 +253,7 @@ static inline void hwsim_clear_chanctx_magic(struct ieee80211_chanctx_conf *c)
 
 static unsigned int hwsim_net_id;
 
-static int hwsim_netgroup;
+static struct ida hwsim_netgroup_ida = IDA_INIT;
 
 struct hwsim_net {
        int netgroup;
@@ -267,11 +267,13 @@ static inline int hwsim_net_get_netgroup(struct net *net)
        return hwsim_net->netgroup;
 }
 
-static inline void hwsim_net_set_netgroup(struct net *net)
+static inline int hwsim_net_set_netgroup(struct net *net)
 {
        struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
 
-       hwsim_net->netgroup = hwsim_netgroup++;
+       hwsim_net->netgroup = ida_simple_get(&hwsim_netgroup_ida,
+                                            0, 0, GFP_KERNEL);
+       return hwsim_net->netgroup >= 0 ? 0 : -ENOMEM;
 }
 
 static inline u32 hwsim_net_get_wmediumd(struct net *net)
@@ -3507,9 +3509,7 @@ failure:
 
 static __net_init int hwsim_init_net(struct net *net)
 {
-       hwsim_net_set_netgroup(net);
-
-       return 0;
+       return hwsim_net_set_netgroup(net);
 }
 
 static void __net_exit hwsim_exit_net(struct net *net)
@@ -3532,6 +3532,8 @@ static void __net_exit hwsim_exit_net(struct net *net)
                queue_work(hwsim_wq, &data->destroy_work);
        }
        spin_unlock_bh(&hwsim_radio_lock);
+
+       ida_simple_remove(&hwsim_netgroup_ida, hwsim_net_get_netgroup(net));
 }
 
 static struct pernet_operations hwsim_net_ops = {
This page took 0.028625 seconds and 4 git commands to generate.