diff options
author | Johannes Berg <johannes.berg@intel.com> | 2013-03-06 22:53:52 +0100 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2013-03-11 15:16:41 +0200 |
commit | 79cf2dfa362f3e6368ad8ecb10aa82b39678fedc (patch) | |
tree | a31ef2bc191d189378fc3520df7e8d303b65c0d1 /net/mac80211/key.c | |
parent | 3d5839b6aa6bbf26c04e885956109d1995d01fe2 (diff) | |
download | linux-79cf2dfa362f3e6368ad8ecb10aa82b39678fedc.tar.bz2 |
mac80211: clean up key freeing a bit
When a key is allocated but not really added, there's no
need to go through the entire teardown process. Also, if
adding a key fails, ieee80211_key_link() can take care of
freeing it instead of the (only) caller.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/mac80211/key.c')
-rw-r--r-- | net/mac80211/key.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/net/mac80211/key.c b/net/mac80211/key.c index 99e9f6ae6a54..d86be6466724 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c @@ -397,6 +397,15 @@ struct ieee80211_key *ieee80211_key_alloc(u32 cipher, int idx, size_t key_len, return key; } +static void ieee80211_key_free_common(struct ieee80211_key *key) +{ + if (key->conf.cipher == WLAN_CIPHER_SUITE_CCMP) + ieee80211_aes_key_free(key->u.ccmp.tfm); + if (key->conf.cipher == WLAN_CIPHER_SUITE_AES_CMAC) + ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm); + kfree(key); +} + static void __ieee80211_key_destroy(struct ieee80211_key *key, bool delay_tailroom) { @@ -412,10 +421,6 @@ static void __ieee80211_key_destroy(struct ieee80211_key *key, if (key->local) ieee80211_key_disable_hw_accel(key); - if (key->conf.cipher == WLAN_CIPHER_SUITE_CCMP) - ieee80211_aes_key_free(key->u.ccmp.tfm); - if (key->conf.cipher == WLAN_CIPHER_SUITE_AES_CMAC) - ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm); if (key->local) { struct ieee80211_sub_if_data *sdata = key->sdata; @@ -431,7 +436,13 @@ static void __ieee80211_key_destroy(struct ieee80211_key *key, } } - kfree(key); + ieee80211_key_free_common(key); +} + +void ieee80211_key_free_unused(struct ieee80211_key *key) +{ + WARN_ON(key->sdata || key->local); + ieee80211_key_free_common(key); } int ieee80211_key_link(struct ieee80211_key *key, @@ -469,6 +480,9 @@ int ieee80211_key_link(struct ieee80211_key *key, ret = ieee80211_key_enable_hw_accel(key); + if (ret) + __ieee80211_key_free(key, true); + mutex_unlock(&sdata->local->key_mtx); return ret; @@ -489,14 +503,6 @@ void __ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom) __ieee80211_key_destroy(key, delay_tailroom); } -void ieee80211_key_free(struct ieee80211_local *local, - struct ieee80211_key *key) -{ - mutex_lock(&local->key_mtx); - __ieee80211_key_free(key, true); - mutex_unlock(&local->key_mtx); -} - void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata) { struct ieee80211_key *key; |