aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211/key.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211/key.c')
-rw-r--r--net/mac80211/key.c32
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,
397 return key; 397 return key;
398} 398}
399 399
400static void ieee80211_key_free_common(struct ieee80211_key *key)
401{
402 if (key->conf.cipher == WLAN_CIPHER_SUITE_CCMP)
403 ieee80211_aes_key_free(key->u.ccmp.tfm);
404 if (key->conf.cipher == WLAN_CIPHER_SUITE_AES_CMAC)
405 ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm);
406 kfree(key);
407}
408
400static void __ieee80211_key_destroy(struct ieee80211_key *key, 409static void __ieee80211_key_destroy(struct ieee80211_key *key,
401 bool delay_tailroom) 410 bool delay_tailroom)
402{ 411{
@@ -412,10 +421,6 @@ static void __ieee80211_key_destroy(struct ieee80211_key *key,
412 if (key->local) 421 if (key->local)
413 ieee80211_key_disable_hw_accel(key); 422 ieee80211_key_disable_hw_accel(key);
414 423
415 if (key->conf.cipher == WLAN_CIPHER_SUITE_CCMP)
416 ieee80211_aes_key_free(key->u.ccmp.tfm);
417 if (key->conf.cipher == WLAN_CIPHER_SUITE_AES_CMAC)
418 ieee80211_aes_cmac_key_free(key->u.aes_cmac.tfm);
419 if (key->local) { 424 if (key->local) {
420 struct ieee80211_sub_if_data *sdata = key->sdata; 425 struct ieee80211_sub_if_data *sdata = key->sdata;
421 426
@@ -431,7 +436,13 @@ static void __ieee80211_key_destroy(struct ieee80211_key *key,
431 } 436 }
432 } 437 }
433 438
434 kfree(key); 439 ieee80211_key_free_common(key);
440}
441
442void ieee80211_key_free_unused(struct ieee80211_key *key)
443{
444 WARN_ON(key->sdata || key->local);
445 ieee80211_key_free_common(key);
435} 446}
436 447
437int ieee80211_key_link(struct ieee80211_key *key, 448int ieee80211_key_link(struct ieee80211_key *key,
@@ -469,6 +480,9 @@ int ieee80211_key_link(struct ieee80211_key *key,
469 480
470 ret = ieee80211_key_enable_hw_accel(key); 481 ret = ieee80211_key_enable_hw_accel(key);
471 482
483 if (ret)
484 __ieee80211_key_free(key, true);
485
472 mutex_unlock(&sdata->local->key_mtx); 486 mutex_unlock(&sdata->local->key_mtx);
473 487
474 return ret; 488 return ret;
@@ -489,14 +503,6 @@ void __ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom)
489 __ieee80211_key_destroy(key, delay_tailroom); 503 __ieee80211_key_destroy(key, delay_tailroom);
490} 504}
491 505
492void ieee80211_key_free(struct ieee80211_local *local,
493 struct ieee80211_key *key)
494{
495 mutex_lock(&local->key_mtx);
496 __ieee80211_key_free(key, true);
497 mutex_unlock(&local->key_mtx);
498}
499
500void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata) 506void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
501{ 507{
502 struct ieee80211_key *key; 508 struct ieee80211_key *key;