Skip to content

Commit b737958

Browse files
authored
Merge pull request #50 from willwillhi1/main
Use spinlock when accessing vif_list
2 parents 3db379f + 061d40c commit b737958

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

vwifi.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ struct owl_context {
6262
struct list_head ap_list; /**< maintaining multiple AP */
6363
};
6464

65+
static DEFINE_SPINLOCK(vif_list_lock);
66+
6567
/* SME stands for "station management entity" */
6668
enum sme_state { SME_DISCONNECTED, SME_CONNECTING, SME_CONNECTED };
6769

@@ -460,13 +462,15 @@ static enum hrtimer_restart owl_beacon(struct hrtimer *timer)
460462
if (vif->privacy)
461463
capability |= WLAN_CAPABILITY_PRIVACY;
462464

465+
spin_lock(&vif_list_lock);
463466
struct owl_vif *sta;
464467
list_for_each_entry (sta, &owl->vif_list, list) {
465468
if (sta->wdev.iftype != NL80211_IFTYPE_STATION)
466469
continue;
467470

468471
owl_beacon_inform_bss(vif, sta, &bss_meta, capability, timestamp);
469472
}
473+
spin_unlock(&vif_list_lock);
470474

471475
/* beacon at next TBTT */
472476
u64 tsf, until_tbtt;
@@ -1263,15 +1267,12 @@ static struct wireless_dev *owinterface_add(struct wiphy *wiphy, int if_idx)
12631267
hash_init(vif->bss_sta_table);
12641268

12651269
/* Add vif into global vif_list */
1266-
if (mutex_lock_interruptible(&owl->lock))
1267-
goto error_add_list;
1270+
spin_lock_bh(&vif_list_lock);
12681271
list_add_tail(&vif->list, &owl->vif_list);
1269-
mutex_unlock(&owl->lock);
1272+
spin_unlock_bh(&vif_list_lock);
12701273

12711274
return &vif->wdev;
12721275

1273-
error_add_list:
1274-
unregister_netdev(vif->ndev);
12751276
error_ndev_register:
12761277
free_netdev(vif->ndev);
12771278
error_alloc_ndev:
@@ -1779,8 +1780,13 @@ static void owl_free(void)
17791780
{
17801781
struct owl_vif *vif = NULL, *safe = NULL;
17811782

1782-
list_for_each_entry_safe (vif, safe, &owl->vif_list, list)
1783+
spin_lock_bh(&vif_list_lock);
1784+
list_for_each_entry_safe (vif, safe, &owl->vif_list, list) {
1785+
spin_unlock_bh(&vif_list_lock);
17831786
owl_delete_interface(vif);
1787+
spin_lock_bh(&vif_list_lock);
1788+
}
1789+
spin_unlock_bh(&vif_list_lock);
17841790

17851791
kfree(owl);
17861792
}

0 commit comments

Comments
 (0)