Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: atmel - Use unregister_{aeads,ahashes,skciphers}

Replace multiple for loops with calls to crypto_unregister_aeads(),
crypto_unregister_ahashes(), and crypto_unregister_skciphers().

Remove the definition of atmel_tdes_unregister_algs() because it is
equivalent to calling crypto_unregister_skciphers() directly, and the
function parameter 'struct atmel_tdes_dev *' is unused anyway.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Thorsten Blum and committed by
Herbert Xu
2ffc1ef4 3cd3059a

+22 -47
+6 -11
drivers/crypto/atmel-aes.c
··· 2201 2201 2202 2202 static void atmel_aes_unregister_algs(struct atmel_aes_dev *dd) 2203 2203 { 2204 - int i; 2205 - 2206 2204 #if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC) 2207 2205 if (dd->caps.has_authenc) 2208 - for (i = 0; i < ARRAY_SIZE(aes_authenc_algs); i++) 2209 - crypto_unregister_aead(&aes_authenc_algs[i]); 2206 + crypto_unregister_aeads(aes_authenc_algs, 2207 + ARRAY_SIZE(aes_authenc_algs)); 2210 2208 #endif 2211 2209 2212 2210 if (dd->caps.has_xts) ··· 2213 2215 if (dd->caps.has_gcm) 2214 2216 crypto_unregister_aead(&aes_gcm_alg); 2215 2217 2216 - for (i = 0; i < ARRAY_SIZE(aes_algs); i++) 2217 - crypto_unregister_skcipher(&aes_algs[i]); 2218 + crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); 2218 2219 } 2219 2220 2220 2221 static void atmel_aes_crypto_alg_init(struct crypto_alg *alg) ··· 2226 2229 2227 2230 static int atmel_aes_register_algs(struct atmel_aes_dev *dd) 2228 2231 { 2229 - int err, i, j; 2232 + int err, i; 2230 2233 2231 2234 for (i = 0; i < ARRAY_SIZE(aes_algs); i++) { 2232 2235 atmel_aes_crypto_alg_init(&aes_algs[i].base); ··· 2269 2272 #if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC) 2270 2273 /* i = ARRAY_SIZE(aes_authenc_algs); */ 2271 2274 err_aes_authenc_alg: 2272 - for (j = 0; j < i; j++) 2273 - crypto_unregister_aead(&aes_authenc_algs[j]); 2275 + crypto_unregister_aeads(aes_authenc_algs, i); 2274 2276 crypto_unregister_skcipher(&aes_xts_alg); 2275 2277 #endif 2276 2278 err_aes_xts_alg: ··· 2277 2281 err_aes_gcm_alg: 2278 2282 i = ARRAY_SIZE(aes_algs); 2279 2283 err_aes_algs: 2280 - for (j = 0; j < i; j++) 2281 - crypto_unregister_skcipher(&aes_algs[j]); 2284 + crypto_unregister_skciphers(aes_algs, i); 2282 2285 2283 2286 return err; 2284 2287 }
+10 -17
drivers/crypto/atmel-sha.c
··· 2418 2418 2419 2419 static void atmel_sha_unregister_algs(struct atmel_sha_dev *dd) 2420 2420 { 2421 - int i; 2422 - 2423 2421 if (dd->caps.has_hmac) 2424 - for (i = 0; i < ARRAY_SIZE(sha_hmac_algs); i++) 2425 - crypto_unregister_ahash(&sha_hmac_algs[i]); 2422 + crypto_unregister_ahashes(sha_hmac_algs, 2423 + ARRAY_SIZE(sha_hmac_algs)); 2426 2424 2427 - for (i = 0; i < ARRAY_SIZE(sha_1_256_algs); i++) 2428 - crypto_unregister_ahash(&sha_1_256_algs[i]); 2425 + crypto_unregister_ahashes(sha_1_256_algs, ARRAY_SIZE(sha_1_256_algs)); 2429 2426 2430 2427 if (dd->caps.has_sha224) 2431 2428 crypto_unregister_ahash(&sha_224_alg); 2432 2429 2433 - if (dd->caps.has_sha_384_512) { 2434 - for (i = 0; i < ARRAY_SIZE(sha_384_512_algs); i++) 2435 - crypto_unregister_ahash(&sha_384_512_algs[i]); 2436 - } 2430 + if (dd->caps.has_sha_384_512) 2431 + crypto_unregister_ahashes(sha_384_512_algs, 2432 + ARRAY_SIZE(sha_384_512_algs)); 2437 2433 } 2438 2434 2439 2435 static int atmel_sha_register_algs(struct atmel_sha_dev *dd) 2440 2436 { 2441 - int err, i, j; 2437 + int err, i; 2442 2438 2443 2439 for (i = 0; i < ARRAY_SIZE(sha_1_256_algs); i++) { 2444 2440 atmel_sha_alg_init(&sha_1_256_algs[i]); ··· 2476 2480 2477 2481 /*i = ARRAY_SIZE(sha_hmac_algs);*/ 2478 2482 err_sha_hmac_algs: 2479 - for (j = 0; j < i; j++) 2480 - crypto_unregister_ahash(&sha_hmac_algs[j]); 2483 + crypto_unregister_ahashes(sha_hmac_algs, i); 2481 2484 i = ARRAY_SIZE(sha_384_512_algs); 2482 2485 err_sha_384_512_algs: 2483 - for (j = 0; j < i; j++) 2484 - crypto_unregister_ahash(&sha_384_512_algs[j]); 2486 + crypto_unregister_ahashes(sha_384_512_algs, i); 2485 2487 crypto_unregister_ahash(&sha_224_alg); 2486 2488 err_sha_224_algs: 2487 2489 i = ARRAY_SIZE(sha_1_256_algs); 2488 2490 err_sha_1_256_algs: 2489 - for (j = 0; j < i; j++) 2490 - crypto_unregister_ahash(&sha_1_256_algs[j]); 2491 + crypto_unregister_ahashes(sha_1_256_algs, i); 2491 2492 2492 2493 return err; 2493 2494 }
+6 -19
drivers/crypto/atmel-tdes.c
··· 897 897 return IRQ_NONE; 898 898 } 899 899 900 - static void atmel_tdes_unregister_algs(struct atmel_tdes_dev *dd) 901 - { 902 - int i; 903 - 904 - for (i = 0; i < ARRAY_SIZE(tdes_algs); i++) 905 - crypto_unregister_skcipher(&tdes_algs[i]); 906 - } 907 - 908 900 static int atmel_tdes_register_algs(struct atmel_tdes_dev *dd) 909 901 { 910 - int err, i, j; 902 + int err, i; 911 903 912 904 for (i = 0; i < ARRAY_SIZE(tdes_algs); i++) { 913 905 atmel_tdes_skcipher_alg_init(&tdes_algs[i]); 914 906 915 907 err = crypto_register_skcipher(&tdes_algs[i]); 916 - if (err) 917 - goto err_tdes_algs; 908 + if (err) { 909 + crypto_unregister_skciphers(tdes_algs, i); 910 + return err; 911 + } 918 912 } 919 913 920 914 return 0; 921 - 922 - err_tdes_algs: 923 - for (j = 0; j < i; j++) 924 - crypto_unregister_skcipher(&tdes_algs[j]); 925 - 926 - return err; 927 915 } 928 916 929 917 static void atmel_tdes_get_cap(struct atmel_tdes_dev *dd) 930 918 { 931 - 932 919 dd->caps.has_dma = 0; 933 920 934 921 /* keep only major version number */ ··· 1048 1061 list_del(&tdes_dd->list); 1049 1062 spin_unlock(&atmel_tdes.lock); 1050 1063 1051 - atmel_tdes_unregister_algs(tdes_dd); 1064 + crypto_unregister_skciphers(tdes_algs, ARRAY_SIZE(tdes_algs)); 1052 1065 1053 1066 tasklet_kill(&tdes_dd->done_task); 1054 1067 tasklet_kill(&tdes_dd->queue_task);