Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: geniv - convert to new way of freeing instances

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>

authored by

Eric Biggers and committed by
Herbert Xu
0f8f6d86 48fb3e57

+16 -40
+4 -16
crypto/echainiv.c
··· 133 133 inst->alg.base.cra_ctxsize = sizeof(struct aead_geniv_ctx); 134 134 inst->alg.base.cra_ctxsize += inst->alg.ivsize; 135 135 136 - inst->free = aead_geniv_free; 137 - 138 136 err = aead_register_instance(tmpl, inst); 139 - if (err) 140 - goto free_inst; 141 - 142 - out: 143 - return err; 144 - 137 + if (err) { 145 138 free_inst: 146 - aead_geniv_free(inst); 147 - goto out; 148 - } 149 - 150 - static void echainiv_free(struct crypto_instance *inst) 151 - { 152 - aead_geniv_free(aead_instance(inst)); 139 + inst->free(inst); 140 + } 141 + return err; 153 142 } 154 143 155 144 static struct crypto_template echainiv_tmpl = { 156 145 .name = "echainiv", 157 146 .create = echainiv_aead_create, 158 - .free = echainiv_free, 159 147 .module = THIS_MODULE, 160 148 }; 161 149
+8 -7
crypto/geniv.c
··· 32 32 return crypto_aead_setauthsize(ctx->child, authsize); 33 33 } 34 34 35 + static void aead_geniv_free(struct aead_instance *inst) 36 + { 37 + crypto_drop_aead(aead_instance_ctx(inst)); 38 + kfree(inst); 39 + } 40 + 35 41 struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl, 36 42 struct rtattr **tb, u32 type, u32 mask) 37 43 { ··· 106 100 inst->alg.ivsize = ivsize; 107 101 inst->alg.maxauthsize = maxauthsize; 108 102 103 + inst->free = aead_geniv_free; 104 + 109 105 out: 110 106 return inst; 111 107 ··· 119 111 goto out; 120 112 } 121 113 EXPORT_SYMBOL_GPL(aead_geniv_alloc); 122 - 123 - void aead_geniv_free(struct aead_instance *inst) 124 - { 125 - crypto_drop_aead(aead_instance_ctx(inst)); 126 - kfree(inst); 127 - } 128 - EXPORT_SYMBOL_GPL(aead_geniv_free); 129 114 130 115 int aead_init_geniv(struct crypto_aead *aead) 131 116 {
+4 -16
crypto/seqiv.c
··· 18 18 #include <linux/slab.h> 19 19 #include <linux/string.h> 20 20 21 - static void seqiv_free(struct crypto_instance *inst); 22 - 23 21 static void seqiv_aead_encrypt_complete2(struct aead_request *req, int err) 24 22 { 25 23 struct aead_request *subreq = aead_request_ctx(req); ··· 157 159 inst->alg.base.cra_ctxsize += inst->alg.ivsize; 158 160 159 161 err = aead_register_instance(tmpl, inst); 160 - if (err) 161 - goto free_inst; 162 - 163 - out: 164 - return err; 165 - 162 + if (err) { 166 163 free_inst: 167 - aead_geniv_free(inst); 168 - goto out; 164 + inst->free(inst); 165 + } 166 + return err; 169 167 } 170 168 171 169 static int seqiv_create(struct crypto_template *tmpl, struct rtattr **tb) ··· 178 184 return seqiv_aead_create(tmpl, tb); 179 185 } 180 186 181 - static void seqiv_free(struct crypto_instance *inst) 182 - { 183 - aead_geniv_free(aead_instance(inst)); 184 - } 185 - 186 187 static struct crypto_template seqiv_tmpl = { 187 188 .name = "seqiv", 188 189 .create = seqiv_create, 189 - .free = seqiv_free, 190 190 .module = THIS_MODULE, 191 191 }; 192 192
-1
include/crypto/internal/geniv.h
··· 21 21 22 22 struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl, 23 23 struct rtattr **tb, u32 type, u32 mask); 24 - void aead_geniv_free(struct aead_instance *inst); 25 24 int aead_init_geniv(struct crypto_aead *tfm); 26 25 void aead_exit_geniv(struct crypto_aead *tfm); 27 26