projects
/
cascardo
/
linux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
thinkpad_acpi: Fix warning for static not at beginning
[cascardo/linux.git]
/
crypto
/
algapi.c
diff --git
a/crypto/algapi.c
b/crypto/algapi.c
index
83b04e0
..
d2627a3
100644
(file)
--- a/
crypto/algapi.c
+++ b/
crypto/algapi.c
@@
-64,6
+64,8
@@
static int crypto_check_alg(struct crypto_alg *alg)
if (alg->cra_priority < 0)
return -EINVAL;
if (alg->cra_priority < 0)
return -EINVAL;
+ atomic_set(&alg->cra_refcnt, 1);
+
return crypto_set_driver_name(alg);
}
return crypto_set_driver_name(alg);
}
@@
-99,10
+101,9
@@
static struct list_head *crypto_more_spawns(struct crypto_alg *alg,
return &n->list == stack ? top : &n->inst->alg.cra_users;
}
return &n->list == stack ? top : &n->inst->alg.cra_users;
}
-static void crypto_remove_
spawn(struct crypto_spawn *spawn
,
- struct list_head *list)
+static void crypto_remove_
instance(struct crypto_instance *inst
,
+
struct list_head *list)
{
{
- struct crypto_instance *inst = spawn->inst;
struct crypto_template *tmpl = inst->tmpl;
if (crypto_is_dead(&inst->alg))
struct crypto_template *tmpl = inst->tmpl;
if (crypto_is_dead(&inst->alg))
@@
-167,7
+168,7
@@
void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
if (spawn->alg)
list_move(&spawn->list, &spawn->alg->cra_users);
else
if (spawn->alg)
list_move(&spawn->list, &spawn->alg->cra_users);
else
- crypto_remove_
spawn(spawn
, list);
+ crypto_remove_
instance(spawn->inst
, list);
}
}
EXPORT_SYMBOL_GPL(crypto_remove_spawns);
}
}
EXPORT_SYMBOL_GPL(crypto_remove_spawns);
@@
-188,7
+189,6
@@
static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg)
ret = -EEXIST;
ret = -EEXIST;
- atomic_set(&alg->cra_refcnt, 1);
list_for_each_entry(q, &crypto_alg_list, cra_list) {
if (q == alg)
goto err;
list_for_each_entry(q, &crypto_alg_list, cra_list) {
if (q == alg)
goto err;
@@
-523,11
+523,14
@@
int crypto_register_instance(struct crypto_template *tmpl,
err = crypto_check_alg(&inst->alg);
if (err)
err = crypto_check_alg(&inst->alg);
if (err)
-
goto
err;
+
return
err;
inst->alg.cra_module = tmpl->module;
inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;
inst->alg.cra_module = tmpl->module;
inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;
+ if (unlikely(!crypto_mod_get(&inst->alg)))
+ return -EAGAIN;
+
down_write(&crypto_alg_sem);
larval = __crypto_register_alg(&inst->alg);
down_write(&crypto_alg_sem);
larval = __crypto_register_alg(&inst->alg);
@@
-545,37
+548,30
@@
unlock:
goto err;
crypto_wait_for_test(larval);
goto err;
crypto_wait_for_test(larval);
+
+ /* Remove instance if test failed */
+ if (!(inst->alg.cra_flags & CRYPTO_ALG_TESTED))
+ crypto_unregister_instance(inst);
err = 0;
err:
err = 0;
err:
+ crypto_mod_put(&inst->alg);
return err;
}
EXPORT_SYMBOL_GPL(crypto_register_instance);
return err;
}
EXPORT_SYMBOL_GPL(crypto_register_instance);
-int crypto_unregister_instance(struct crypto_
alg *alg
)
+int crypto_unregister_instance(struct crypto_
instance *inst
)
{
{
- int err;
- struct crypto_instance *inst = (void *)alg;
- struct crypto_template *tmpl = inst->tmpl;
- LIST_HEAD(users);
-
- if (!(alg->cra_flags & CRYPTO_ALG_INSTANCE))
- return -EINVAL;
-
- BUG_ON(atomic_read(&alg->cra_refcnt) != 1);
+ LIST_HEAD(list);
down_write(&crypto_alg_sem);
down_write(&crypto_alg_sem);
-
hlist_del_init(&inst->list
);
-
err = crypto_remove_alg(alg, &users
);
+
crypto_remove_spawns(&inst->alg, &list, NULL
);
+
crypto_remove_instance(inst, &list
);
up_write(&crypto_alg_sem);
up_write(&crypto_alg_sem);
- if (err)
- return err;
-
- tmpl->free(inst);
- crypto_remove_final(&users);
+ crypto_remove_final(&list);
return 0;
}
return 0;
}