summaryrefslogtreecommitdiff
path: root/crypto/algapi.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-07-09 07:17:15 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2015-07-14 14:56:45 +0800
commitfc4dcc099be78f9d45aef725dcdff2aad12398b6 (patch)
tree2f646f35138ce1bb6a9ea25ed4f58a180ab9672b /crypto/algapi.c
parent710490db4c91e1a77a243f666e33207b770219be (diff)
downloadlinux-crypto-fc4dcc099be78f9d45aef725dcdff2aad12398b6.tar.gz
linux-crypto-fc4dcc099be78f9d45aef725dcdff2aad12398b6.zip
crypto: api - Add instance free function to crypto_type
Currently the task of freeing an instance is given to the crypto template. However, it has no type information on the instance so we have to resort to checking type information at runtime. This patch introduces a free function to crypto_type that will be used to free an instance. This can then be used to free an instance in a type-safe manner. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/algapi.c')
-rw-r--r--crypto/algapi.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c
index ceebfcf2..d130b41d 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -67,12 +67,22 @@ static int crypto_check_alg(struct crypto_alg *alg)
return crypto_set_driver_name(alg);
}
+static void crypto_free_instance(struct crypto_instance *inst)
+{
+ if (!inst->alg.cra_type->free) {
+ inst->tmpl->free(inst);
+ return;
+ }
+
+ inst->alg.cra_type->free(inst);
+}
+
static void crypto_destroy_instance(struct crypto_alg *alg)
{
struct crypto_instance *inst = (void *)alg;
struct crypto_template *tmpl = inst->tmpl;
- tmpl->free(inst);
+ crypto_free_instance(inst);
crypto_tmpl_put(tmpl);
}
@@ -481,7 +491,7 @@ void crypto_unregister_template(struct crypto_template *tmpl)
hlist_for_each_entry_safe(inst, n, list, list) {
BUG_ON(atomic_read(&inst->alg.cra_refcnt) != 1);
- tmpl->free(inst);
+ crypto_free_instance(inst);
}
crypto_remove_final(&users);
}