Skip to content

Commit 4b00434

Browse files
broonieherbertx
authored andcommitted
crypto: Add bulk algorithm registration interface
Hardware crypto engines frequently need to register a selection of different algorithms with the core. Simplify their code slightly, especially the error handling, by providing functions to register a number of algorithms in a single call. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent b85a088 commit 4b00434

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎crypto/algapi.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,41 @@ int crypto_unregister_alg(struct crypto_alg *alg)
405405
}
406406
EXPORT_SYMBOL_GPL(crypto_unregister_alg);
407407

408+
int crypto_register_algs(struct crypto_alg *algs, int count)
409+
{
410+
int i, ret;
411+
412+
for (i = 0; i < count; i++) {
413+
ret = crypto_register_alg(&algs[i]);
414+
if (ret)
415+
goto err;
416+
}
417+
418+
return 0;
419+
420+
err:
421+
for (--i; i >= 0; --i)
422+
crypto_unregister_alg(&algs[i]);
423+
424+
return ret;
425+
}
426+
EXPORT_SYMBOL_GPL(crypto_register_algs);
427+
428+
int crypto_unregister_algs(struct crypto_alg *algs, int count)
429+
{
430+
int i, ret;
431+
432+
for (i = 0; i < count; i++) {
433+
ret = crypto_unregister_alg(&algs[i]);
434+
if (ret)
435+
pr_err("Failed to unregister %s %s: %d\n",
436+
algs[i].cra_driver_name, algs[i].cra_name, ret);
437+
}
438+
439+
return 0;
440+
}
441+
EXPORT_SYMBOL_GPL(crypto_unregister_algs);
442+
408443
int crypto_register_template(struct crypto_template *tmpl)
409444
{
410445
struct crypto_template *q;

‎include/linux/crypto.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ struct crypto_alg {
314314
*/
315315
int crypto_register_alg(struct crypto_alg *alg);
316316
int crypto_unregister_alg(struct crypto_alg *alg);
317+
int crypto_register_algs(struct crypto_alg *algs, int count);
318+
int crypto_unregister_algs(struct crypto_alg *algs, int count);
317319

318320
/*
319321
* Algorithm query interface.

0 commit comments

Comments
 (0)