From: Herbert Xu <herbert@gondor.apana.org.au>
To: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Cc: linux-mm@kvack.org, Yosry Ahmed <yosry.ahmed@linux.dev>,
Kanchana P Sridhar <kanchana.p.sridhar@intel.com>
Subject: [v2 PATCH 1/7] crypto: api - Add cra_type->destroy hook
Date: Tue, 04 Mar 2025 17:25:03 +0800 [thread overview]
Message-ID: <3c3c20451382a4e17f2179d436f5841fa1cc3a28.1741080140.git.herbert@gondor.apana.org.au> (raw)
In-Reply-To: <cover.1741080140.git.herbert@gondor.apana.org.au>
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>
---
crypto/algapi.c | 9 +++++++++
crypto/internal.h | 6 ++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/crypto/algapi.c b/crypto/algapi.c
index e7a9a2ada2cf..8f72dd15cf9c 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -89,6 +89,15 @@ static void crypto_destroy_instance(struct crypto_alg *alg)
schedule_work(&inst->free_work);
}
+void crypto_destroy_alg(struct crypto_alg *alg)
+{
+ if (alg->cra_type && alg->cra_type->destroy)
+ alg->cra_type->destroy(alg);
+
+ if (alg->cra_destroy)
+ alg->cra_destroy(alg);
+}
+
/*
* This function adds a spawn to the list secondary_spawns which
* will be used at the end of crypto_remove_spawns to unregister
diff --git a/crypto/internal.h b/crypto/internal.h
index 08d43b40e7db..11567ea24fc3 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -40,6 +40,7 @@ struct crypto_type {
void (*show)(struct seq_file *m, struct crypto_alg *alg);
int (*report)(struct sk_buff *skb, struct crypto_alg *alg);
void (*free)(struct crypto_instance *inst);
+ void (*destroy)(struct crypto_alg *alg);
unsigned int type;
unsigned int maskclear;
@@ -127,6 +128,7 @@ void *crypto_create_tfm_node(struct crypto_alg *alg,
const struct crypto_type *frontend, int node);
void *crypto_clone_tfm(const struct crypto_type *frontend,
struct crypto_tfm *otfm);
+void crypto_destroy_alg(struct crypto_alg *alg);
static inline void *crypto_create_tfm(struct crypto_alg *alg,
const struct crypto_type *frontend)
@@ -163,8 +165,8 @@ static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
static inline void crypto_alg_put(struct crypto_alg *alg)
{
- if (refcount_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy)
- alg->cra_destroy(alg);
+ if (refcount_dec_and_test(&alg->cra_refcnt))
+ crypto_destroy_alg(alg);
}
static inline int crypto_tmpl_get(struct crypto_template *tmpl)
--
2.39.5
next prev parent reply other threads:[~2025-03-04 9:25 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 9:25 [v2 PATCH 0/7] crypto: acomp - Add request chaining and virtual address support Herbert Xu
2025-03-04 9:25 ` Herbert Xu [this message]
2025-03-04 9:25 ` [v2 PATCH 2/7] crypto: scomp - Remove tfm argument from alloc/free_ctx Herbert Xu
2025-03-04 9:25 ` [v2 PATCH 3/7] crypto: acomp - Add request chaining and virtual addresses Herbert Xu
2025-03-04 21:59 ` Sridhar, Kanchana P
2025-03-05 1:51 ` Herbert Xu
2025-03-05 20:09 ` Sridhar, Kanchana P
2025-03-04 9:25 ` [v2 PATCH 4/7] crypto: testmgr - Remove NULL dst acomp tests Herbert Xu
2025-03-04 9:25 ` [v2 PATCH 5/7] crypto: scomp - Remove support for most non-trivial destination SG lists Herbert Xu
2025-03-04 9:25 ` [v2 PATCH 6/7] crypto: scomp - Add chaining and virtual address support Herbert Xu
2025-03-04 9:25 ` [v2 PATCH 7/7] crypto: acomp - Move stream management into scomp layer Herbert Xu
2025-03-05 1:46 ` [v2 PATCH 0/7] crypto: acomp - Add request chaining and virtual address support Jonathan Cameron
2025-03-05 21:37 ` Cabiddu, Giovanni
2025-03-06 0:42 ` Herbert Xu
2025-03-06 12:14 ` Cabiddu, Giovanni
2025-03-06 8:15 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3c3c20451382a4e17f2179d436f5841fa1cc3a28.1741080140.git.herbert@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=kanchana.p.sridhar@intel.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=yosry.ahmed@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox