Skip to content

Commit 59fce56

Browse files
tobluxgregkh
authored andcommitted
crypto: atmel - Use unregister_{aeads,ahashes,skciphers}
[ Upstream commit 2ffc1ef ] 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> Stable-dep-of: 57a1394 ("crypto: atmel-aes - guard unregister on error in atmel_aes_register_algs") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 60c571a commit 59fce56

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
@@ -2200,12 +2200,10 @@ static irqreturn_t atmel_aes_irq(int irq, void *dev_id)
22002200

22012201
static void atmel_aes_unregister_algs(struct atmel_aes_dev *dd)
22022202
{
2203-
int i;
2204-
22052203
#if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC)
22062204
if (dd->caps.has_authenc)
2207-
for (i = 0; i < ARRAY_SIZE(aes_authenc_algs); i++)
2208-
crypto_unregister_aead(&aes_authenc_algs[i]);
2205+
crypto_unregister_aeads(aes_authenc_algs,
2206+
ARRAY_SIZE(aes_authenc_algs));
22092207
#endif
22102208

22112209
if (dd->caps.has_xts)
@@ -2214,8 +2212,7 @@ static void atmel_aes_unregister_algs(struct atmel_aes_dev *dd)
22142212
if (dd->caps.has_gcm)
22152213
crypto_unregister_aead(&aes_gcm_alg);
22162214

2217-
for (i = 0; i < ARRAY_SIZE(aes_algs); i++)
2218-
crypto_unregister_skcipher(&aes_algs[i]);
2215+
crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
22192216
}
22202217

22212218
static void atmel_aes_crypto_alg_init(struct crypto_alg *alg)
@@ -2228,7 +2225,7 @@ static void atmel_aes_crypto_alg_init(struct crypto_alg *alg)
22282225

22292226
static int atmel_aes_register_algs(struct atmel_aes_dev *dd)
22302227
{
2231-
int err, i, j;
2228+
int err, i;
22322229

22332230
for (i = 0; i < ARRAY_SIZE(aes_algs); i++) {
22342231
atmel_aes_crypto_alg_init(&aes_algs[i].base);
@@ -2271,17 +2268,15 @@ static int atmel_aes_register_algs(struct atmel_aes_dev *dd)
22712268
#if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC)
22722269
/* i = ARRAY_SIZE(aes_authenc_algs); */
22732270
err_aes_authenc_alg:
2274-
for (j = 0; j < i; j++)
2275-
crypto_unregister_aead(&aes_authenc_algs[j]);
2271+
crypto_unregister_aeads(aes_authenc_algs, i);
22762272
crypto_unregister_skcipher(&aes_xts_alg);
22772273
#endif
22782274
err_aes_xts_alg:
22792275
crypto_unregister_aead(&aes_gcm_alg);
22802276
err_aes_gcm_alg:
22812277
i = ARRAY_SIZE(aes_algs);
22822278
err_aes_algs:
2283-
for (j = 0; j < i; j++)
2284-
crypto_unregister_skcipher(&aes_algs[j]);
2279+
crypto_unregister_skciphers(aes_algs, i);
22852280

22862281
return err;
22872282
}

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 int 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)