crypto: fix broken crypto_register_instance() module handling
Commit 9c521a200b
("crypto: api - remove instance when test failed")
tried to grab a module reference count before the module was even set.
Worse, it then goes on to free the module reference count after it is
set so you quickly end up with a negative module reference count which
prevents people from using any instances belonging to that module.
This patch moves the module initialisation before the reference
count.
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
eea3a00264
commit
34c9a0ffc7
1 changed files with 3 additions and 3 deletions
|
@ -525,12 +525,12 @@ int crypto_register_instance(struct crypto_template *tmpl,
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (unlikely(!crypto_mod_get(&inst->alg)))
|
|
||||||
return -EAGAIN;
|
|
||||||
|
|
||||||
inst->alg.cra_module = tmpl->module;
|
inst->alg.cra_module = tmpl->module;
|
||||||
inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;
|
inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;
|
||||||
|
|
||||||
|
if (unlikely(!crypto_mod_get(&inst->alg)))
|
||||||
|
return -EAGAIN;
|
||||||
|
|
||||||
down_write(&crypto_alg_sem);
|
down_write(&crypto_alg_sem);
|
||||||
|
|
||||||
larval = __crypto_register_alg(&inst->alg);
|
larval = __crypto_register_alg(&inst->alg);
|
||||||
|
|
Loading…
Reference in a new issue