Skip to contentSkip to conversation

crypto: algapi - Use crypto_unregister_algs in crypto_register_algs

PATCH In review Thorsten Blum 2 participants 2 messages Dec 11, 2025 – Dec 19, 2025 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: algapi - Use crypto_unregister_algs in crypto_register_algs

Replace the for loop with a call to crypto_unregister_algs(). Return 'ret' immediately and remove the goto statement to simplify the error handling code.

In crypto_unregister_algs(), unregister the algorithms in reverse order.

---
 crypto/algapi.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
crypto/algapi.c +5 -9
index e604d0d8b7b4..ac4fc790687e 100644
@@ -511,17 +511,13 @@ int crypto_register_algs(struct crypto_alg *algs, int count)
 
 	for (i = 0; i < count; i++) {
 		ret = crypto_register_alg(&algs[i]);
-		if (ret)
-			goto err;
+		if (ret) {
+			crypto_unregister_algs(algs, i);
+			return ret;
+		}
 	}
 
 	return 0;
-
-err:
-	for (--i; i >= 0; --i)
-		crypto_unregister_alg(&algs[i]);
-
-	return ret;
 }
 EXPORT_SYMBOL_GPL(crypto_register_algs);
 
@@ -529,7 +525,7 @@ void crypto_unregister_algs(struct crypto_alg *algs, int count)
 {
 	int i;
 
-	for (i = 0; i < count; i++)
+	for (i = count - 1; i >= 0; --i)
 		crypto_unregister_alg(&algs[i]);
 }
 EXPORT_SYMBOL_GPL(crypto_unregister_algs);
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
maintainer
#1 lore raw
Quoted 10 lines · Thorsten Blum

Replace the for loop with a call to crypto_unregister_algs(). Return 'ret' immediately and remove the goto statement to simplify the error handling code.

In crypto_unregister_algs(), unregister the algorithms in reverse order.

---
 crypto/algapi.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt