diff mbox

mac80111: aes_ccm: cleanup ieee80211_aes_key_setup_encrypt()

Message ID 20150323140814.GA27609@mwanda (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show

Commit Message

Dan Carpenter March 23, 2015, 2:08 p.m. UTC
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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Ard Biesheuvel March 24, 2015, 9:32 a.m. UTC | #1
On 23 March 2015 at 15:08, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 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.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Thanks,
Ard.

>
> diff --git a/net/mac80211/aes_ccm.c b/net/mac80211/aes_ccm.c
> index 7869bb40..208df7c 100644
> --- a/net/mac80211/aes_ccm.c
> +++ b/net/mac80211/aes_ccm.c
> @@ -85,11 +85,15 @@ struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
>                 return tfm;
>
>         err = crypto_aead_setkey(tfm, key, key_len);
> -       if (!err)
> -               err = crypto_aead_setauthsize(tfm, mic_len);
> -       if (!err)
> -               return tfm;
> +       if (err)
> +               goto free_aead;
> +       err = crypto_aead_setauthsize(tfm, mic_len);
> +       if (err)
> +               goto free_aead;
> +
> +       return tfm;
>
> +free_aead:
>         crypto_free_aead(tfm);
>         return ERR_PTR(err);
>  }
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johannes Berg March 30, 2015, 8:40 a.m. UTC | #2
On Mon, 2015-03-23 at 17:08 +0300, Dan Carpenter wrote:
> 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.

Applied.

johannes

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/mac80211/aes_ccm.c b/net/mac80211/aes_ccm.c
index 7869bb40..208df7c 100644
--- a/net/mac80211/aes_ccm.c
+++ b/net/mac80211/aes_ccm.c
@@ -85,11 +85,15 @@  struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
 		return tfm;
 
 	err = crypto_aead_setkey(tfm, key, key_len);
-	if (!err)
-		err = crypto_aead_setauthsize(tfm, mic_len);
-	if (!err)
-		return tfm;
+	if (err)
+		goto free_aead;
+	err = crypto_aead_setauthsize(tfm, mic_len);
+	if (err)
+		goto free_aead;
+
+	return tfm;
 
+free_aead:
 	crypto_free_aead(tfm);
 	return ERR_PTR(err);
 }