Commit 758ec5ac authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu

crypto: cryptd - convert to new way of freeing instances

Convert the "cryptd" template to the new way of freeing instances, where
a ->free() method is installed to the instance struct itself.  This
replaces the weakly-typed method crypto_template::free().

This will allow removing support for the old way of freeing instances.

Note that the 'default' case in cryptd_free() was already unreachable.
So, we aren't missing anything by keeping only the ahash and aead parts.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 0f8f6d86
...@@ -631,6 +631,14 @@ static int cryptd_hash_import(struct ahash_request *req, const void *in) ...@@ -631,6 +631,14 @@ static int cryptd_hash_import(struct ahash_request *req, const void *in)
return crypto_shash_import(desc, in); return crypto_shash_import(desc, in);
} }
static void cryptd_hash_free(struct ahash_instance *inst)
{
struct hashd_instance_ctx *ctx = ahash_instance_ctx(inst);
crypto_drop_shash(&ctx->spawn);
kfree(inst);
}
static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
struct cryptd_queue *queue) struct cryptd_queue *queue)
{ {
...@@ -681,6 +689,8 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, ...@@ -681,6 +689,8 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
inst->alg.setkey = cryptd_hash_setkey; inst->alg.setkey = cryptd_hash_setkey;
inst->alg.digest = cryptd_hash_digest_enqueue; inst->alg.digest = cryptd_hash_digest_enqueue;
inst->free = cryptd_hash_free;
err = ahash_register_instance(tmpl, inst); err = ahash_register_instance(tmpl, inst);
if (err) { if (err) {
err_free_inst: err_free_inst:
...@@ -808,6 +818,14 @@ static void cryptd_aead_exit_tfm(struct crypto_aead *tfm) ...@@ -808,6 +818,14 @@ static void cryptd_aead_exit_tfm(struct crypto_aead *tfm)
crypto_free_aead(ctx->child); crypto_free_aead(ctx->child);
} }
static void cryptd_aead_free(struct aead_instance *inst)
{
struct aead_instance_ctx *ctx = aead_instance_ctx(inst);
crypto_drop_aead(&ctx->aead_spawn);
kfree(inst);
}
static int cryptd_create_aead(struct crypto_template *tmpl, static int cryptd_create_aead(struct crypto_template *tmpl,
struct rtattr **tb, struct rtattr **tb,
struct cryptd_queue *queue) struct cryptd_queue *queue)
...@@ -857,6 +875,8 @@ static int cryptd_create_aead(struct crypto_template *tmpl, ...@@ -857,6 +875,8 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
inst->alg.encrypt = cryptd_aead_encrypt_enqueue; inst->alg.encrypt = cryptd_aead_encrypt_enqueue;
inst->alg.decrypt = cryptd_aead_decrypt_enqueue; inst->alg.decrypt = cryptd_aead_decrypt_enqueue;
inst->free = cryptd_aead_free;
err = aead_register_instance(tmpl, inst); err = aead_register_instance(tmpl, inst);
if (err) { if (err) {
out_drop_aead: out_drop_aead:
...@@ -889,31 +909,9 @@ static int cryptd_create(struct crypto_template *tmpl, struct rtattr **tb) ...@@ -889,31 +909,9 @@ static int cryptd_create(struct crypto_template *tmpl, struct rtattr **tb)
return -EINVAL; return -EINVAL;
} }
static void cryptd_free(struct crypto_instance *inst)
{
struct cryptd_instance_ctx *ctx = crypto_instance_ctx(inst);
struct hashd_instance_ctx *hctx = crypto_instance_ctx(inst);
struct aead_instance_ctx *aead_ctx = crypto_instance_ctx(inst);
switch (inst->alg.cra_flags & CRYPTO_ALG_TYPE_MASK) {
case CRYPTO_ALG_TYPE_AHASH:
crypto_drop_shash(&hctx->spawn);
kfree(ahash_instance(inst));
return;
case CRYPTO_ALG_TYPE_AEAD:
crypto_drop_aead(&aead_ctx->aead_spawn);
kfree(aead_instance(inst));
return;
default:
crypto_drop_spawn(&ctx->spawn);
kfree(inst);
}
}
static struct crypto_template cryptd_tmpl = { static struct crypto_template cryptd_tmpl = {
.name = "cryptd", .name = "cryptd",
.create = cryptd_create, .create = cryptd_create,
.free = cryptd_free,
.module = THIS_MODULE, .module = THIS_MODULE,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment