All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: public_key - Make sig/tfm local to if clause in software_key_query
@ 2025-04-16  7:48 Herbert Xu
  2025-04-20  5:46 ` Lukas Wunner
  0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2025-04-16  7:48 UTC (permalink / raw)
  To: Linux Crypto Mailing List, Lukas Wunner, Ignat Korchagin

The recent code changes in this function triggered a false-positive
maybe-uninitialized warning in software_key_query.  Rearrange the
code by moving the sig/tfm variables into the if clause where they
are actually used.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index 89dc887d2c5c..e5b177c8e842 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -163,10 +163,8 @@ static u8 *pkey_pack_u32(u8 *dst, u32 val)
 static int software_key_query(const struct kernel_pkey_params *params,
 			      struct kernel_pkey_query *info)
 {
-	struct crypto_akcipher *tfm;
 	struct public_key *pkey = params->key->payload.data[asym_crypto];
 	char alg_name[CRYPTO_MAX_ALG_NAME];
-	struct crypto_sig *sig;
 	u8 *key, *ptr;
 	int ret, len;
 	bool issig;
@@ -191,6 +189,8 @@ static int software_key_query(const struct kernel_pkey_params *params,
 	memset(info, 0, sizeof(*info));
 
 	if (issig) {
+		struct crypto_sig *sig;
+
 		sig = crypto_alloc_sig(alg_name, 0, 0);
 		if (IS_ERR(sig)) {
 			ret = PTR_ERR(sig);
@@ -202,7 +202,7 @@ static int software_key_query(const struct kernel_pkey_params *params,
 		else
 			ret = crypto_sig_set_pubkey(sig, key, pkey->keylen);
 		if (ret < 0)
-			goto error_free_tfm;
+			goto error_free_sig;
 
 		len = crypto_sig_keysize(sig);
 		info->key_size = len;
@@ -221,7 +221,12 @@ static int software_key_query(const struct kernel_pkey_params *params,
 			if (pkey->key_is_private)
 				info->supported_ops |= KEYCTL_SUPPORTS_DECRYPT;
 		}
+
+error_free_sig:
+		crypto_free_sig(sig);
 	} else {
+		struct crypto_akcipher *tfm;
+
 		tfm = crypto_alloc_akcipher(alg_name, 0, 0);
 		if (IS_ERR(tfm)) {
 			ret = PTR_ERR(tfm);
@@ -233,7 +238,7 @@ static int software_key_query(const struct kernel_pkey_params *params,
 		else
 			ret = crypto_akcipher_set_pub_key(tfm, key, pkey->keylen);
 		if (ret < 0)
-			goto error_free_tfm;
+			goto error_free_akcipher;
 
 		len = crypto_akcipher_maxsize(tfm);
 		info->key_size = len * BITS_PER_BYTE;
@@ -245,15 +250,11 @@ static int software_key_query(const struct kernel_pkey_params *params,
 		info->supported_ops = KEYCTL_SUPPORTS_ENCRYPT;
 		if (pkey->key_is_private)
 			info->supported_ops |= KEYCTL_SUPPORTS_DECRYPT;
+
+error_free_akcipher:
+		crypto_free_akcipher(tfm);
 	}
 
-	ret = 0;
-
-error_free_tfm:
-	if (issig)
-		crypto_free_sig(sig);
-	else
-		crypto_free_akcipher(tfm);
 error_free_key:
 	kfree_sensitive(key);
 	pr_devel("<==%s() = %d\n", __func__, ret);
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-20  5:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16  7:48 [PATCH] crypto: public_key - Make sig/tfm local to if clause in software_key_query Herbert Xu
2025-04-20  5:46 ` Lukas Wunner
2025-04-20  5:48   ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.