crypto: api - Move alg ref count init to crypto_check_alg
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 9 Apr 2015 09:40:35 +0000 (17:40 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 10 Apr 2015 13:39:24 +0000 (21:39 +0800)
We currently initialise the crypto_alg ref count in the function
__crypto_register_alg.  As one of the callers of that function
crypto_register_instance needs to obtain a ref count before it
calls __crypto_register_alg, we need to move the initialisation
out of there.

Since both callers of __crypto_register_alg call crypto_check_alg,
this is the logical place to perform the initialisation.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Stephan Mueller <smueller@chronox.de>
crypto/algapi.c

index f1d0307b1d083f3e374dbb2db4bce45a0f483948..1462c68492ea3edb1adb29cdc760f117f97b046b 100644 (file)
@@ -64,6 +64,8 @@ static int crypto_check_alg(struct crypto_alg *alg)
        if (alg->cra_priority < 0)
                return -EINVAL;
 
+       atomic_set(&alg->cra_refcnt, 1);
+
        return crypto_set_driver_name(alg);
 }
 
@@ -187,7 +189,6 @@ static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg)
 
        ret = -EEXIST;
 
-       atomic_set(&alg->cra_refcnt, 1);
        list_for_each_entry(q, &crypto_alg_list, cra_list) {
                if (q == alg)
                        goto err;