diff mbox series

[net-next,11/17] tls: allocate the fallback aead after checking that the cipher is valid

Message ID 335e32511ed55a0b30f3f81a78fa8f323b3bdf8f.1692977948.git.sd@queasysnail.net (mailing list archive)
State Accepted
Commit d2322cf5ed59f084ac86d9339f7c3acccd177bfd
Delegated to: Netdev Maintainers
Headers show
Series tls: expand tls_cipher_size_desc to simplify getsockopt/setsockopt | expand

Checks

Context Check Description
netdev/series_format fail Series longer than 15 patches (and no cover letter)
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1330 this patch: 1330
netdev/cc_maintainers warning 3 maintainers not CCed: pabeni@redhat.com edumazet@google.com davem@davemloft.net
netdev/build_clang success Errors and warnings before: 1353 this patch: 1353
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1353 this patch: 1353
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 35 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sabrina Dubroca Aug. 25, 2023, 9:35 p.m. UTC
No need to allocate the aead if we're going to fail afterwards.

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
 net/tls/tls_device_fallback.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c
index cb224fb2a394..4de9061f38f5 100644
--- a/net/tls/tls_device_fallback.c
+++ b/net/tls/tls_device_fallback.c
@@ -475,15 +475,6 @@  int tls_sw_fallback_init(struct sock *sk,
 	const u8 *key;
 	int rc;
 
-	offload_ctx->aead_send =
-	    crypto_alloc_aead("gcm(aes)", 0, CRYPTO_ALG_ASYNC);
-	if (IS_ERR(offload_ctx->aead_send)) {
-		rc = PTR_ERR(offload_ctx->aead_send);
-		pr_err_ratelimited("crypto_alloc_aead failed rc=%d\n", rc);
-		offload_ctx->aead_send = NULL;
-		goto err_out;
-	}
-
 	switch (crypto_info->cipher_type) {
 	case TLS_CIPHER_AES_GCM_128:
 		key = ((struct tls12_crypto_info_aes_gcm_128 *)crypto_info)->key;
@@ -493,10 +484,19 @@  int tls_sw_fallback_init(struct sock *sk,
 		break;
 	default:
 		rc = -EINVAL;
-		goto free_aead;
+		goto err_out;
 	}
 	cipher_desc = get_cipher_desc(crypto_info->cipher_type);
 
+	offload_ctx->aead_send =
+	    crypto_alloc_aead("gcm(aes)", 0, CRYPTO_ALG_ASYNC);
+	if (IS_ERR(offload_ctx->aead_send)) {
+		rc = PTR_ERR(offload_ctx->aead_send);
+		pr_err_ratelimited("crypto_alloc_aead failed rc=%d\n", rc);
+		offload_ctx->aead_send = NULL;
+		goto err_out;
+	}
+
 	rc = crypto_aead_setkey(offload_ctx->aead_send, key, cipher_desc->key);
 	if (rc)
 		goto free_aead;