Skip to contentSkip to conversation

crypto: acomp - Use unregister_acomps in register_acomps

PATCH In review Thorsten Blum 2 participants 7 messages Dec 19, 2025 – Jan 23 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 crypto: acomp - Use unregister_acomps in register_acomps

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

---
 crypto/acompress.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
crypto/acompress.c +4 -8
index be28cbfd22e3..b353615fe265 100644
@@ -337,17 +337,13 @@ int crypto_register_acomps(struct acomp_alg *algs, int count)
 
 	for (i = 0; i < count; i++) {
 		ret = crypto_register_acomp(&algs[i]);
-		if (ret)
-			goto err;
+		if (ret) {
+			crypto_unregister_acomps(algs, i);
+			return ret;
+		}
 	}
 
 	return 0;
-
-err:
-	for (--i; i >= 0; --i)
-		crypto_unregister_acomp(&algs[i]);
-
-	return ret;
 }
 EXPORT_SYMBOL_GPL(crypto_register_acomps);
 
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
#1 lore raw

PATCH 2/6 crypto: ahash - Use unregister_ahashes in register_ahashes

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

---
 crypto/ahash.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
crypto/ahash.c +4 -8
index 66492ae75fcf..c563a68dc000 100644
@@ -1020,17 +1020,13 @@ int crypto_register_ahashes(struct ahash_alg *algs, int count)
 
 	for (i = 0; i < count; i++) {
 		ret = crypto_register_ahash(&algs[i]);
-		if (ret)
-			goto err;
+		if (ret) {
+			crypto_unregister_ahashes(algs, i);
+			return ret;
+		}
 	}
 
 	return 0;
-
-err:
-	for (--i; i >= 0; --i)
-		crypto_unregister_ahash(&algs[i]);
-
-	return ret;
 }
 EXPORT_SYMBOL_GPL(crypto_register_ahashes);
 
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
#2 lore raw

PATCH 3/6 crypto: shash - Use unregister_shashes in register_shashes

In reply to Thorsten Blum

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

---
 crypto/shash.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
crypto/shash.c +4 -8
index 4721f5f134f4..5238e0def4fd 100644
@@ -542,17 +542,13 @@ int crypto_register_shashes(struct shash_alg *algs, int count)
 
 	for (i = 0; i < count; i++) {
 		ret = crypto_register_shash(&algs[i]);
-		if (ret)
-			goto err;
+		if (ret) {
+			crypto_unregister_shashes(algs, i);
+			return ret;
+		}
 	}
 
 	return 0;
-
-err:
-	for (--i; i >= 0; --i)
-		crypto_unregister_shash(&algs[i]);
-
-	return ret;
 }
 EXPORT_SYMBOL_GPL(crypto_register_shashes);
 
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
#3 lore raw

PATCH 4/6 crypto: skcipher - Use unregister_skciphers in register_skciphers

In reply to Thorsten Blum

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

---
 crypto/skcipher.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
crypto/skcipher.c +4 -8
index 14a820cb06c7..09f1ba82f99a 100644
@@ -741,17 +741,13 @@ int crypto_register_skciphers(struct skcipher_alg *algs, int count)
 
 	for (i = 0; i < count; i++) {
 		ret = crypto_register_skcipher(&algs[i]);
-		if (ret)
-			goto err;
+		if (ret) {
+			crypto_unregister_skciphers(algs, i);
+			return ret;
+		}
 	}
 
 	return 0;
-
-err:
-	for (--i; i >= 0; --i)
-		crypto_unregister_skcipher(&algs[i]);
-
-	return ret;
 }
 EXPORT_SYMBOL_GPL(crypto_register_skciphers);
 
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
#4 lore raw

PATCH 5/6 crypto: lskcipher - Use unregister_lskciphers in register_lskciphers

In reply to Thorsten Blum

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

---
 crypto/lskcipher.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
crypto/lskcipher.c +4 -8
index c2e2c38b5aa8..bb166250b732 100644
@@ -384,17 +384,13 @@ int crypto_register_lskciphers(struct lskcipher_alg *algs, int count)
 
 	for (i = 0; i < count; i++) {
 		ret = crypto_register_lskcipher(&algs[i]);
-		if (ret)
-			goto err;
+		if (ret) {
+			crypto_unregister_lskciphers(algs, i);
+			return ret;
+		}
 	}
 
 	return 0;
-
-err:
-	for (--i; i >= 0; --i)
-		crypto_unregister_lskcipher(&algs[i]);
-
-	return ret;
 }
 EXPORT_SYMBOL_GPL(crypto_register_lskciphers);
 
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
#5 lore raw

PATCH 6/6 crypto: engine - Use unregister_* in register_{aeads,ahashes,skciphers}

In reply to Thorsten Blum

Replace the for loops with calls to unregister_aeads(), unregister_ahashes(), and unregister_skciphers(), respectively. Return 'ret' immediately and remove the goto statements to simplify the error handling code. No functional changes.

---
 crypto/crypto_engine.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)
crypto/crypto_engine.c +12 -21
index 18e1689efe12..e124bb773958 100644
@@ -524,16 +524,13 @@ int crypto_engine_register_aeads(struct aead_engine_alg *algs, int count)
 
 	for (i = 0; i < count; i++) {
 		ret = crypto_engine_register_aead(&algs[i]);
-		if (ret)
-			goto err;
+		if (ret) {
+			crypto_engine_unregister_aeads(algs, i);
+			return ret;
+		}
 	}
 
 	return 0;
-
-err:
-	crypto_engine_unregister_aeads(algs, i);
-
-	return ret;
 }
 EXPORT_SYMBOL_GPL(crypto_engine_register_aeads);
 
@@ -566,16 +563,13 @@ int crypto_engine_register_ahashes(struct ahash_engine_alg *algs, int count)
 
 	for (i = 0; i < count; i++) {
 		ret = crypto_engine_register_ahash(&algs[i]);
-		if (ret)
-			goto err;
+		if (ret) {
+			crypto_engine_unregister_ahashes(algs, i);
+			return ret;
+		}
 	}
 
 	return 0;
-
-err:
-	crypto_engine_unregister_ahashes(algs, i);
-
-	return ret;
 }
 EXPORT_SYMBOL_GPL(crypto_engine_register_ahashes);
 
@@ -638,16 +632,13 @@ int crypto_engine_register_skciphers(struct skcipher_engine_alg *algs,
 
 	for (i = 0; i < count; i++) {
 		ret = crypto_engine_register_skcipher(&algs[i]);
-		if (ret)
-			goto err;
+		if (ret) {
+			crypto_engine_unregister_skciphers(algs, i);
+			return ret;
+		}
 	}
 
 	return 0;
-
-err:
-	crypto_engine_unregister_skciphers(algs, i);
-
-	return ret;
 }
 EXPORT_SYMBOL_GPL(crypto_engine_register_skciphers);
 
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
maintainer
#6 lore raw
In reply to Thorsten Blum
Quoted 8 lines · Thorsten Blum

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

---
 crypto/acompress.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

All 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