Skip to content

Commit 3d6979b

Browse files
committed
crypto: api - Add cra_type->destroy hook
Add a cra_type->destroy hook so that resources can be freed after the last user of a registered algorithm is gone. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 01894c8 commit 3d6979b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

crypto/api.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,5 +707,15 @@ void crypto_req_done(void *data, int err)
707707
}
708708
EXPORT_SYMBOL_GPL(crypto_req_done);
709709

710+
void crypto_destroy_alg(struct crypto_alg *alg)
711+
{
712+
if (alg->cra_type && alg->cra_type->destroy)
713+
alg->cra_type->destroy(alg);
714+
715+
if (alg->cra_destroy)
716+
alg->cra_destroy(alg);
717+
}
718+
EXPORT_SYMBOL_GPL(crypto_destroy_alg);
719+
710720
MODULE_DESCRIPTION("Cryptographic core API");
711721
MODULE_LICENSE("GPL");

crypto/internal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct crypto_type {
4040
void (*show)(struct seq_file *m, struct crypto_alg *alg);
4141
int (*report)(struct sk_buff *skb, struct crypto_alg *alg);
4242
void (*free)(struct crypto_instance *inst);
43+
void (*destroy)(struct crypto_alg *alg);
4344

4445
unsigned int type;
4546
unsigned int maskclear;
@@ -127,6 +128,7 @@ void *crypto_create_tfm_node(struct crypto_alg *alg,
127128
const struct crypto_type *frontend, int node);
128129
void *crypto_clone_tfm(const struct crypto_type *frontend,
129130
struct crypto_tfm *otfm);
131+
void crypto_destroy_alg(struct crypto_alg *alg);
130132

131133
static inline void *crypto_create_tfm(struct crypto_alg *alg,
132134
const struct crypto_type *frontend)
@@ -163,8 +165,8 @@ static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
163165

164166
static inline void crypto_alg_put(struct crypto_alg *alg)
165167
{
166-
if (refcount_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy)
167-
alg->cra_destroy(alg);
168+
if (refcount_dec_and_test(&alg->cra_refcnt))
169+
crypto_destroy_alg(alg);
168170
}
169171

170172
static inline int crypto_tmpl_get(struct crypto_template *tmpl)

0 commit comments

Comments
 (0)