Skip to content

Commit 2ffc1ef

Browse files
tobluxherbertx
authored andcommitted
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>
1 parent 3cd3059 commit 2ffc1ef

3 files changed

Lines changed: 22 additions & 47 deletions

File tree

drivers/crypto/atmel-aes.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,12 +2201,10 @@ static irqreturn_t atmel_aes_irq(int irq, void *dev_id)
22012201

22022202
static void atmel_aes_unregister_algs(struct atmel_aes_dev *dd)
22032203
{
2204-
int i;
2205-
22062204
#if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC)
22072205
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));
22102208
#endif
22112209

22122210
if (dd->caps.has_xts)
@@ -2215,8 +2213,7 @@ static void atmel_aes_unregister_algs(struct atmel_aes_dev *dd)
22152213
if (dd->caps.has_gcm)
22162214
crypto_unregister_aead(&aes_gcm_alg);
22172215

2218-
for (i = 0; i < ARRAY_SIZE(aes_algs); i++)
2219-
crypto_unregister_skcipher(&aes_algs[i]);
2216+
crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
22202217
}
22212218

22222219
static void atmel_aes_crypto_alg_init(struct crypto_alg *alg)
@@ -2229,7 +2226,7 @@ static void atmel_aes_crypto_alg_init(struct crypto_alg *alg)
22292226

22302227
static int atmel_aes_register_algs(struct atmel_aes_dev *dd)
22312228
{
2232-
int err, i, j;
2229+
int err, i;
22332230

22342231
for (i = 0; i < ARRAY_SIZE(aes_algs); i++) {
22352232
atmel_aes_crypto_alg_init(&aes_algs[i].base);
@@ -2272,17 +2269,15 @@ static int atmel_aes_register_algs(struct atmel_aes_dev *dd)
22722269
#if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC)
22732270
/* i = ARRAY_SIZE(aes_authenc_algs); */
22742271
err_aes_authenc_alg:
2275-
for (j = 0; j < i; j++)
2276-
crypto_unregister_aead(&aes_authenc_algs[j]);
2272+
crypto_unregister_aeads(aes_authenc_algs, i);
22772273
crypto_unregister_skcipher(&aes_xts_alg);
22782274
#endif
22792275
err_aes_xts_alg:
22802276
crypto_unregister_aead(&aes_gcm_alg);
22812277
err_aes_gcm_alg:
22822278
i = ARRAY_SIZE(aes_algs);
22832279
err_aes_algs:
2284-
for (j = 0; j < i; j++)
2285-
crypto_unregister_skcipher(&aes_algs[j]);
2280+
crypto_unregister_skciphers(aes_algs, i);
22862281

22872282
return err;
22882283
}

drivers/crypto/atmel-sha.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,27 +2418,23 @@ EXPORT_SYMBOL_GPL(atmel_sha_authenc_abort);
24182418

24192419
static void atmel_sha_unregister_algs(struct atmel_sha_dev *dd)
24202420
{
2421-
int i;
2422-
24232421
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));
24262424

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));
24292426

24302427
if (dd->caps.has_sha224)
24312428
crypto_unregister_ahash(&sha_224_alg);
24322429

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));
24372433
}
24382434

24392435
static int atmel_sha_register_algs(struct atmel_sha_dev *dd)
24402436
{
2441-
int err, i, j;
2437+
int err, i;
24422438

24432439
for (i = 0; i < ARRAY_SIZE(sha_1_256_algs); i++) {
24442440
atmel_sha_alg_init(&sha_1_256_algs[i]);
@@ -2480,18 +2476,15 @@ static int atmel_sha_register_algs(struct atmel_sha_dev *dd)
24802476

24812477
/*i = ARRAY_SIZE(sha_hmac_algs);*/
24822478
err_sha_hmac_algs:
2483-
for (j = 0; j < i; j++)
2484-
crypto_unregister_ahash(&sha_hmac_algs[j]);
2479+
crypto_unregister_ahashes(sha_hmac_algs, i);
24852480
i = ARRAY_SIZE(sha_384_512_algs);
24862481
err_sha_384_512_algs:
2487-
for (j = 0; j < i; j++)
2488-
crypto_unregister_ahash(&sha_384_512_algs[j]);
2482+
crypto_unregister_ahashes(sha_384_512_algs, i);
24892483
crypto_unregister_ahash(&sha_224_alg);
24902484
err_sha_224_algs:
24912485
i = ARRAY_SIZE(sha_1_256_algs);
24922486
err_sha_1_256_algs:
2493-
for (j = 0; j < i; j++)
2494-
crypto_unregister_ahash(&sha_1_256_algs[j]);
2487+
crypto_unregister_ahashes(sha_1_256_algs, i);
24952488

24962489
return err;
24972490
}

drivers/crypto/atmel-tdes.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -897,38 +897,25 @@ static irqreturn_t atmel_tdes_irq(int irq, void *dev_id)
897897
return IRQ_NONE;
898898
}
899899

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-
908900
static int atmel_tdes_register_algs(struct atmel_tdes_dev *dd)
909901
{
910-
int err, i, j;
902+
int err, i;
911903

912904
for (i = 0; i < ARRAY_SIZE(tdes_algs); i++) {
913905
atmel_tdes_skcipher_alg_init(&tdes_algs[i]);
914906

915907
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+
}
918912
}
919913

920914
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;
927915
}
928916

929917
static void atmel_tdes_get_cap(struct atmel_tdes_dev *dd)
930918
{
931-
932919
dd->caps.has_dma = 0;
933920

934921
/* keep only major version number */
@@ -1061,7 +1048,7 @@ static void atmel_tdes_remove(struct platform_device *pdev)
10611048
list_del(&tdes_dd->list);
10621049
spin_unlock(&atmel_tdes.lock);
10631050

1064-
atmel_tdes_unregister_algs(tdes_dd);
1051+
crypto_unregister_skciphers(tdes_algs, ARRAY_SIZE(tdes_algs));
10651052

10661053
tasklet_kill(&tdes_dd->done_task);
10671054
tasklet_kill(&tdes_dd->queue_task);

0 commit comments

Comments
 (0)