Skip to content

Commit a39c66c

Browse files
ebiggersherbertx
authored andcommitted
crypto: shash - convert shash_free_instance() to new style
Convert shash_free_instance() and its users 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. Also give shash_free_instance() a more descriptive name to reflect that it's only for instances with a single spawn, not for any instance. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 758ec5a commit a39c66c

7 files changed

Lines changed: 20 additions & 15 deletions

File tree

‎crypto/ccm.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,12 @@ static int cbcmac_create(struct crypto_template *tmpl, struct rtattr **tb)
927927
inst->alg.final = crypto_cbcmac_digest_final;
928928
inst->alg.setkey = crypto_cbcmac_digest_setkey;
929929

930+
inst->free = shash_free_singlespawn_instance;
931+
930932
err = shash_register_instance(tmpl, inst);
931933
if (err) {
932934
err_free_inst:
933-
shash_free_instance(shash_crypto_instance(inst));
935+
shash_free_singlespawn_instance(inst);
934936
}
935937
return err;
936938
}
@@ -939,7 +941,6 @@ static struct crypto_template crypto_ccm_tmpls[] = {
939941
{
940942
.name = "cbcmac",
941943
.create = cbcmac_create,
942-
.free = shash_free_instance,
943944
.module = THIS_MODULE,
944945
}, {
945946
.name = "ccm_base",

‎crypto/cmac.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,19 @@ static int cmac_create(struct crypto_template *tmpl, struct rtattr **tb)
280280
inst->alg.final = crypto_cmac_digest_final;
281281
inst->alg.setkey = crypto_cmac_digest_setkey;
282282

283+
inst->free = shash_free_singlespawn_instance;
284+
283285
err = shash_register_instance(tmpl, inst);
284286
if (err) {
285287
err_free_inst:
286-
shash_free_instance(shash_crypto_instance(inst));
288+
shash_free_singlespawn_instance(inst);
287289
}
288290
return err;
289291
}
290292

291293
static struct crypto_template crypto_cmac_tmpl = {
292294
.name = "cmac",
293295
.create = cmac_create,
294-
.free = shash_free_instance,
295296
.module = THIS_MODULE,
296297
};
297298

‎crypto/hmac.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,19 @@ static int hmac_create(struct crypto_template *tmpl, struct rtattr **tb)
224224
inst->alg.init_tfm = hmac_init_tfm;
225225
inst->alg.exit_tfm = hmac_exit_tfm;
226226

227+
inst->free = shash_free_singlespawn_instance;
228+
227229
err = shash_register_instance(tmpl, inst);
228230
if (err) {
229231
err_free_inst:
230-
shash_free_instance(shash_crypto_instance(inst));
232+
shash_free_singlespawn_instance(inst);
231233
}
232234
return err;
233235
}
234236

235237
static struct crypto_template hmac_tmpl = {
236238
.name = "hmac",
237239
.create = hmac_create,
238-
.free = shash_free_instance,
239240
.module = THIS_MODULE,
240241
};
241242

‎crypto/shash.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,12 @@ int shash_register_instance(struct crypto_template *tmpl,
590590
}
591591
EXPORT_SYMBOL_GPL(shash_register_instance);
592592

593-
void shash_free_instance(struct crypto_instance *inst)
593+
void shash_free_singlespawn_instance(struct shash_instance *inst)
594594
{
595-
crypto_drop_spawn(crypto_instance_ctx(inst));
596-
kfree(shash_instance(inst));
595+
crypto_drop_spawn(shash_instance_ctx(inst));
596+
kfree(inst);
597597
}
598-
EXPORT_SYMBOL_GPL(shash_free_instance);
598+
EXPORT_SYMBOL_GPL(shash_free_singlespawn_instance);
599599

600600
MODULE_LICENSE("GPL");
601601
MODULE_DESCRIPTION("Synchronous cryptographic hash type");

‎crypto/vmac.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,18 +660,19 @@ static int vmac_create(struct crypto_template *tmpl, struct rtattr **tb)
660660
inst->alg.final = vmac_final;
661661
inst->alg.setkey = vmac_setkey;
662662

663+
inst->free = shash_free_singlespawn_instance;
664+
663665
err = shash_register_instance(tmpl, inst);
664666
if (err) {
665667
err_free_inst:
666-
shash_free_instance(shash_crypto_instance(inst));
668+
shash_free_singlespawn_instance(inst);
667669
}
668670
return err;
669671
}
670672

671673
static struct crypto_template vmac64_tmpl = {
672674
.name = "vmac64",
673675
.create = vmac_create,
674-
.free = shash_free_instance,
675676
.module = THIS_MODULE,
676677
};
677678

‎crypto/xcbc.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,19 @@ static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb)
239239
inst->alg.final = crypto_xcbc_digest_final;
240240
inst->alg.setkey = crypto_xcbc_digest_setkey;
241241

242+
inst->free = shash_free_singlespawn_instance;
243+
242244
err = shash_register_instance(tmpl, inst);
243245
if (err) {
244246
err_free_inst:
245-
shash_free_instance(shash_crypto_instance(inst));
247+
shash_free_singlespawn_instance(inst);
246248
}
247249
return err;
248250
}
249251

250252
static struct crypto_template crypto_xcbc_tmpl = {
251253
.name = "xcbc",
252254
.create = xcbc_create,
253-
.free = shash_free_instance,
254255
.module = THIS_MODULE,
255256
};
256257

‎include/crypto/internal/hash.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int crypto_register_shashes(struct shash_alg *algs, int count);
125125
void crypto_unregister_shashes(struct shash_alg *algs, int count);
126126
int shash_register_instance(struct crypto_template *tmpl,
127127
struct shash_instance *inst);
128-
void shash_free_instance(struct crypto_instance *inst);
128+
void shash_free_singlespawn_instance(struct shash_instance *inst);
129129

130130
int crypto_grab_shash(struct crypto_shash_spawn *spawn,
131131
struct crypto_instance *inst,

0 commit comments

Comments
 (0)