diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2023-04-13 08:24:15 +0200 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2023-04-20 12:20:04 +0200 |
commit | ae131f4970f0778f35ed06aeb15bde2fbc1d9619 (patch) | |
tree | 32129d0609ff52d6742628db8f284e33274c95a7 /crypto/api.c | |
parent | crypto: x86/sha - Use local .L symbols for code (diff) | |
download | linux-ae131f4970f0778f35ed06aeb15bde2fbc1d9619.tar.xz linux-ae131f4970f0778f35ed06aeb15bde2fbc1d9619.zip |
crypto: api - Add crypto_tfm_get
Add a crypto_tfm_get interface to allow tfm objects to be shared.
They can still be freed in the usual way.
This should only be done with tfm objects with no keys. You must
also not modify the tfm flags in any way once it becomes shared.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/api.c')
-rw-r--r-- | crypto/api.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/crypto/api.c b/crypto/api.c index e67cc63368ed..f509d73fa682 100644 --- a/crypto/api.c +++ b/crypto/api.c @@ -408,6 +408,7 @@ struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, goto out_err; tfm->__crt_alg = alg; + refcount_set(&tfm->refcnt, 1); err = crypto_init_ops(tfm, type, mask); if (err) @@ -507,6 +508,7 @@ void *crypto_create_tfm_node(struct crypto_alg *alg, tfm = (struct crypto_tfm *)(mem + tfmsize); tfm->__crt_alg = alg; tfm->node = node; + refcount_set(&tfm->refcnt, 1); err = frontend->init_tfm(tfm); if (err) @@ -619,6 +621,8 @@ void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm) if (IS_ERR_OR_NULL(mem)) return; + if (!refcount_dec_and_test(&tfm->refcnt)) + return; alg = tfm->__crt_alg; if (!tfm->exit && alg->cra_exit) |