Skip to content

Commit

Permalink
mac80211: simplify key locking
Browse files Browse the repository at this point in the history
Since I recently made station management able
to sleep, I can now rework key management as
well; since it will no longer need a spinlock
and can also use a mutex instead, a bunch of
code to allow drivers' set_key to sleep while
key management is protected by a spinlock can
now be removed.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Johannes Berg authored and John W. Linville committed Jun 3, 2010
1 parent efe4c45 commit ad0e2b5
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 267 deletions.
18 changes: 8 additions & 10 deletions net/mac80211/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_key *key;
int err;

if (!netif_running(dev))
return -ENETDOWN;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

switch (params->cipher) {
Expand All @@ -145,7 +148,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
if (!key)
return -ENOMEM;

rcu_read_lock();
mutex_lock(&sdata->local->sta_mtx);

if (mac_addr) {
sta = sta_info_get_bss(sdata, mac_addr);
Expand All @@ -160,7 +163,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,

err = 0;
out_unlock:
rcu_read_unlock();
mutex_unlock(&sdata->local->sta_mtx);

return err;
}
Expand All @@ -174,7 +177,7 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

rcu_read_lock();
mutex_lock(&sdata->local->sta_mtx);

if (mac_addr) {
ret = -ENOENT;
Expand Down Expand Up @@ -202,7 +205,7 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,

ret = 0;
out_unlock:
rcu_read_unlock();
mutex_unlock(&sdata->local->sta_mtx);

return ret;
}
Expand Down Expand Up @@ -305,15 +308,10 @@ static int ieee80211_config_default_key(struct wiphy *wiphy,
struct net_device *dev,
u8 key_idx)
{
struct ieee80211_sub_if_data *sdata;

rcu_read_lock();
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);

sdata = IEEE80211_DEV_TO_SUB_IF(dev);
ieee80211_set_default_key(sdata, key_idx);

rcu_read_unlock();

return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions net/mac80211/ieee80211_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,10 @@ struct ieee80211_local {
struct mutex iflist_mtx;

/*
* Key lock, protects sdata's key_list and sta_info's
* Key mutex, protects sdata's key_list and sta_info's
* key pointers (write access, they're RCU.)
*/
spinlock_t key_lock;
struct mutex key_mtx;


/* Scanning and BSS list */
Expand Down
5 changes: 2 additions & 3 deletions net/mac80211/iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ static int ieee80211_open(struct net_device *dev)

changed |= ieee80211_reset_erp_info(sdata);
ieee80211_bss_info_change_notify(sdata, changed);
ieee80211_enable_keys(sdata);

if (sdata->vif.type == NL80211_IFTYPE_STATION)
netif_carrier_off(dev);
Expand Down Expand Up @@ -522,8 +521,8 @@ static int ieee80211_stop(struct net_device *dev)
BSS_CHANGED_BEACON_ENABLED);
}

/* disable all keys for as long as this netdev is down */
ieee80211_disable_keys(sdata);
/* free all remaining keys, there shouldn't be any */
ieee80211_free_keys(sdata);
drv_remove_interface(local, &sdata->vif);
}

Expand Down
Loading

0 comments on commit ad0e2b5

Please sign in to comment.