]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
crypto: geniv - convert to new way of freeing instances
authorEric Biggers <ebiggers@google.com>
Fri, 3 Jan 2020 04:04:36 +0000 (20:04 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 9 Jan 2020 03:30:57 +0000 (11:30 +0800)
Convert the "seqiv" template to the new way of freeing instances where a
->free() method is installed to the instance struct itself.  Also remove
the unused implementation of the old way of freeing instances from the
"echainiv" template, since it's already using the new way too.

In doing this, also simplify the code by making the helper function
aead_geniv_alloc() install the ->free() method, instead of making seqiv
and echainiv do this themselves.  This is analogous to how
skcipher_alloc_instance_simple() works.

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

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/echainiv.c
crypto/geniv.c
crypto/seqiv.c
include/crypto/internal/geniv.h

index a49cbf7b09294c1eaa751f82b460e2634d740787..4a2f02baba144b46f69cfeee4c68c0f99801cf33 100644 (file)
@@ -133,29 +133,17 @@ static int echainiv_aead_create(struct crypto_template *tmpl,
        inst->alg.base.cra_ctxsize = sizeof(struct aead_geniv_ctx);
        inst->alg.base.cra_ctxsize += inst->alg.ivsize;
 
-       inst->free = aead_geniv_free;
-
        err = aead_register_instance(tmpl, inst);
-       if (err)
-               goto free_inst;
-
-out:
-       return err;
-
+       if (err) {
 free_inst:
-       aead_geniv_free(inst);
-       goto out;
-}
-
-static void echainiv_free(struct crypto_instance *inst)
-{
-       aead_geniv_free(aead_instance(inst));
+               inst->free(inst);
+       }
+       return err;
 }
 
 static struct crypto_template echainiv_tmpl = {
        .name = "echainiv",
        .create = echainiv_aead_create,
-       .free = echainiv_free,
        .module = THIS_MODULE,
 };
 
index 7afa48414f3a4743127d276aced58f5aec3813d3..dbcc640274cda0f46d95f29360476385d2c5bbb0 100644 (file)
@@ -32,6 +32,12 @@ static int aead_geniv_setauthsize(struct crypto_aead *tfm,
        return crypto_aead_setauthsize(ctx->child, authsize);
 }
 
+static void aead_geniv_free(struct aead_instance *inst)
+{
+       crypto_drop_aead(aead_instance_ctx(inst));
+       kfree(inst);
+}
+
 struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
                                       struct rtattr **tb, u32 type, u32 mask)
 {
@@ -100,6 +106,8 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
        inst->alg.ivsize = ivsize;
        inst->alg.maxauthsize = maxauthsize;
 
+       inst->free = aead_geniv_free;
+
 out:
        return inst;
 
@@ -112,13 +120,6 @@ err_free_inst:
 }
 EXPORT_SYMBOL_GPL(aead_geniv_alloc);
 
-void aead_geniv_free(struct aead_instance *inst)
-{
-       crypto_drop_aead(aead_instance_ctx(inst));
-       kfree(inst);
-}
-EXPORT_SYMBOL_GPL(aead_geniv_free);
-
 int aead_init_geniv(struct crypto_aead *aead)
 {
        struct aead_geniv_ctx *ctx = crypto_aead_ctx(aead);
index 96d222c32accce34dc35a584a87be595e8725ba9..f124b9b54e159267968a18ddd68fffe8e0642bf9 100644 (file)
@@ -18,8 +18,6 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 
-static void seqiv_free(struct crypto_instance *inst);
-
 static void seqiv_aead_encrypt_complete2(struct aead_request *req, int err)
 {
        struct aead_request *subreq = aead_request_ctx(req);
@@ -159,15 +157,11 @@ static int seqiv_aead_create(struct crypto_template *tmpl, struct rtattr **tb)
        inst->alg.base.cra_ctxsize += inst->alg.ivsize;
 
        err = aead_register_instance(tmpl, inst);
-       if (err)
-               goto free_inst;
-
-out:
-       return err;
-
+       if (err) {
 free_inst:
-       aead_geniv_free(inst);
-       goto out;
+               inst->free(inst);
+       }
+       return err;
 }
 
 static int seqiv_create(struct crypto_template *tmpl, struct rtattr **tb)
@@ -184,15 +178,9 @@ static int seqiv_create(struct crypto_template *tmpl, struct rtattr **tb)
        return seqiv_aead_create(tmpl, tb);
 }
 
-static void seqiv_free(struct crypto_instance *inst)
-{
-       aead_geniv_free(aead_instance(inst));
-}
-
 static struct crypto_template seqiv_tmpl = {
        .name = "seqiv",
        .create = seqiv_create,
-       .free = seqiv_free,
        .module = THIS_MODULE,
 };
 
index 0108c0c7b2edbecd2b54a6584144abd097ef3263..229d37681a9d30e69710f359b7083f19fed9f1bc 100644 (file)
@@ -21,7 +21,6 @@ struct aead_geniv_ctx {
 
 struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
                                       struct rtattr **tb, u32 type, u32 mask);
-void aead_geniv_free(struct aead_instance *inst);
 int aead_init_geniv(struct crypto_aead *tfm);
 void aead_exit_geniv(struct crypto_aead *tfm);