mac80111: aes_gcm: clean up ieee80211_aes_gcm_key_setup_encrypt()
authorJohannes Berg <johannes.berg@intel.com>
Mon, 23 Mar 2015 14:08:14 +0000 (17:08 +0300)
committerJohannes Berg <johannes.berg@intel.com>
Mon, 30 Mar 2015 08:42:02 +0000 (10:42 +0200)
This code is written using an anti-pattern called "success handling"
which makes it hard to read, especially if you are used to normal kernel
style.  It should instead be written as a list of directives in a row
with branches for error handling.

(Basically copied from Dan's previous patch for CCM)

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/aes_gcm.c

index c2bf6698d7384195bca6e6d3952ab98e44e0be3b..fd278bbe1b0db49ef825a025f11488eec7014daa 100644 (file)
@@ -80,11 +80,15 @@ struct crypto_aead *ieee80211_aes_gcm_key_setup_encrypt(const u8 key[],
                return tfm;
 
        err = crypto_aead_setkey(tfm, key, key_len);
-       if (!err)
-               err = crypto_aead_setauthsize(tfm, IEEE80211_GCMP_MIC_LEN);
-       if (!err)
-               return tfm;
+       if (err)
+               goto free_aead;
+       err = crypto_aead_setauthsize(tfm, IEEE80211_GCMP_MIC_LEN);
+       if (err)
+               goto free_aead;
+
+       return tfm;
 
+free_aead:
        crypto_free_aead(tfm);
        return ERR_PTR(err);
 }