aboutsummaryrefslogtreecommitdiff
path: root/crypto/api.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/api.c')
-rw-r--r--crypto/api.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/crypto/api.c b/crypto/api.c
index 80bba637fba..c11ec1fd4f1 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -188,13 +188,16 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
if (crypto_init_flags(tfm, flags))
goto out_free_tfm;
- if (crypto_init_ops(tfm)) {
- crypto_exit_ops(tfm);
+ if (crypto_init_ops(tfm))
goto out_free_tfm;
- }
+
+ if (alg->cra_init && alg->cra_init(tfm))
+ goto cra_init_failed;
goto out;
+cra_init_failed:
+ crypto_exit_ops(tfm);
out_free_tfm:
kfree(tfm);
tfm = NULL;
@@ -215,6 +218,8 @@ void crypto_free_tfm(struct crypto_tfm *tfm)
alg = tfm->__crt_alg;
size = sizeof(*tfm) + alg->cra_ctxsize;
+ if (alg->cra_exit)
+ alg->cra_exit(tfm);
crypto_exit_ops(tfm);
crypto_alg_put(alg);
memset(tfm, 0, size);
@@ -224,7 +229,7 @@ void crypto_free_tfm(struct crypto_tfm *tfm)
static inline int crypto_set_driver_name(struct crypto_alg *alg)
{
static const char suffix[] = "-generic";
- char *driver_name = (char *)alg->cra_driver_name;
+ char *driver_name = alg->cra_driver_name;
int len;
if (*driver_name)
@@ -262,13 +267,13 @@ int crypto_register_alg(struct crypto_alg *alg)
down_write(&crypto_alg_sem);
list_for_each_entry(q, &crypto_alg_list, cra_list) {
- if (!strcmp(q->cra_driver_name, alg->cra_driver_name)) {
+ if (q == alg) {
ret = -EEXIST;
goto out;
}
}
- list_add_tail(&alg->cra_list, &crypto_alg_list);
+ list_add(&alg->cra_list, &crypto_alg_list);
out:
up_write(&crypto_alg_sem);
return ret;