From cadafa01f838e762f1535044b6a41b2c236b7edf Mon Sep 17 00:00:00 2001 From: Xiongfeng Wang Date: Thu, 8 Aug 2019 15:26:49 +0800 Subject: [PATCH] crypto: api - add a helper to (un)register a array of templates mainline inclusion from mainline-5.0-rc1 commit 9572442dcf487e534e70b30f43e21a364cf483e9 category: feature bugzilla: 20209 CVE: NA --------------------------- This patch add a helper to (un)register a array of templates. The following patches will use this helper to simplify the code. Signed-off-by: Xiongfeng Wang Reviewed-by: Eric Biggers Signed-off-by: Herbert Xu Reviewed-by: ZhangXiaoxu Signed-off-by: Yang Yingliang --- crypto/algapi.c | 27 +++++++++++++++++++++++++++ include/crypto/algapi.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/crypto/algapi.c b/crypto/algapi.c index c0755cf4f53f..a0f9e807fdb4 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -485,6 +485,24 @@ int crypto_register_template(struct crypto_template *tmpl) } EXPORT_SYMBOL_GPL(crypto_register_template); +int crypto_register_templates(struct crypto_template *tmpls, int count) +{ + int i, err; + + for (i = 0; i < count; i++) { + err = crypto_register_template(&tmpls[i]); + if (err) + goto out; + } + return 0; + +out: + for (--i; i >= 0; --i) + crypto_unregister_template(&tmpls[i]); + return err; +} +EXPORT_SYMBOL_GPL(crypto_register_templates); + void crypto_unregister_template(struct crypto_template *tmpl) { struct crypto_instance *inst; @@ -514,6 +532,15 @@ void crypto_unregister_template(struct crypto_template *tmpl) } EXPORT_SYMBOL_GPL(crypto_unregister_template); +void crypto_unregister_templates(struct crypto_template *tmpls, int count) +{ + int i; + + for (i = count - 1; i >= 0; --i) + crypto_unregister_template(&tmpls[i]); +} +EXPORT_SYMBOL_GPL(crypto_unregister_templates); + static struct crypto_template *__crypto_lookup_template(const char *name) { struct crypto_template *q, *tmpl = NULL; diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index bd5e8ccf1687..6b9cd6597617 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -141,7 +141,9 @@ extern const struct crypto_type crypto_blkcipher_type; void crypto_mod_put(struct crypto_alg *alg); int crypto_register_template(struct crypto_template *tmpl); +int crypto_register_templates(struct crypto_template *tmpls, int count); void crypto_unregister_template(struct crypto_template *tmpl); +void crypto_unregister_templates(struct crypto_template *tmpls, int count); struct crypto_template *crypto_lookup_template(const char *name); int crypto_register_instance(struct crypto_template *tmpl, -- GitLab