Skip to content

Commit

Permalink
crypto: shash - convert shash_free_instance() to new style
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
ebiggers authored and herbertx committed Jan 9, 2020
1 parent 758ec5a commit a39c66c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
5 changes: 3 additions & 2 deletions crypto/ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,12 @@ static int cbcmac_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.final = crypto_cbcmac_digest_final;
inst->alg.setkey = crypto_cbcmac_digest_setkey;

inst->free = shash_free_singlespawn_instance;

err = shash_register_instance(tmpl, inst);
if (err) {
err_free_inst:
shash_free_instance(shash_crypto_instance(inst));
shash_free_singlespawn_instance(inst);
}
return err;
}
Expand All @@ -939,7 +941,6 @@ static struct crypto_template crypto_ccm_tmpls[] = {
{
.name = "cbcmac",
.create = cbcmac_create,
.free = shash_free_instance,
.module = THIS_MODULE,
}, {
.name = "ccm_base",
Expand Down
5 changes: 3 additions & 2 deletions crypto/cmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,19 @@ static int cmac_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.final = crypto_cmac_digest_final;
inst->alg.setkey = crypto_cmac_digest_setkey;

inst->free = shash_free_singlespawn_instance;

err = shash_register_instance(tmpl, inst);
if (err) {
err_free_inst:
shash_free_instance(shash_crypto_instance(inst));
shash_free_singlespawn_instance(inst);
}
return err;
}

static struct crypto_template crypto_cmac_tmpl = {
.name = "cmac",
.create = cmac_create,
.free = shash_free_instance,
.module = THIS_MODULE,
};

Expand Down
5 changes: 3 additions & 2 deletions crypto/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,19 @@ static int hmac_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.init_tfm = hmac_init_tfm;
inst->alg.exit_tfm = hmac_exit_tfm;

inst->free = shash_free_singlespawn_instance;

err = shash_register_instance(tmpl, inst);
if (err) {
err_free_inst:
shash_free_instance(shash_crypto_instance(inst));
shash_free_singlespawn_instance(inst);
}
return err;
}

static struct crypto_template hmac_tmpl = {
.name = "hmac",
.create = hmac_create,
.free = shash_free_instance,
.module = THIS_MODULE,
};

Expand Down
8 changes: 4 additions & 4 deletions crypto/shash.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,12 @@ int shash_register_instance(struct crypto_template *tmpl,
}
EXPORT_SYMBOL_GPL(shash_register_instance);

void shash_free_instance(struct crypto_instance *inst)
void shash_free_singlespawn_instance(struct shash_instance *inst)
{
crypto_drop_spawn(crypto_instance_ctx(inst));
kfree(shash_instance(inst));
crypto_drop_spawn(shash_instance_ctx(inst));
kfree(inst);
}
EXPORT_SYMBOL_GPL(shash_free_instance);
EXPORT_SYMBOL_GPL(shash_free_singlespawn_instance);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Synchronous cryptographic hash type");
5 changes: 3 additions & 2 deletions crypto/vmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,18 +660,19 @@ static int vmac_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.final = vmac_final;
inst->alg.setkey = vmac_setkey;

inst->free = shash_free_singlespawn_instance;

err = shash_register_instance(tmpl, inst);
if (err) {
err_free_inst:
shash_free_instance(shash_crypto_instance(inst));
shash_free_singlespawn_instance(inst);
}
return err;
}

static struct crypto_template vmac64_tmpl = {
.name = "vmac64",
.create = vmac_create,
.free = shash_free_instance,
.module = THIS_MODULE,
};

Expand Down
5 changes: 3 additions & 2 deletions crypto/xcbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,19 @@ static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.final = crypto_xcbc_digest_final;
inst->alg.setkey = crypto_xcbc_digest_setkey;

inst->free = shash_free_singlespawn_instance;

err = shash_register_instance(tmpl, inst);
if (err) {
err_free_inst:
shash_free_instance(shash_crypto_instance(inst));
shash_free_singlespawn_instance(inst);
}
return err;
}

static struct crypto_template crypto_xcbc_tmpl = {
.name = "xcbc",
.create = xcbc_create,
.free = shash_free_instance,
.module = THIS_MODULE,
};

Expand Down
2 changes: 1 addition & 1 deletion include/crypto/internal/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int crypto_register_shashes(struct shash_alg *algs, int count);
void crypto_unregister_shashes(struct shash_alg *algs, int count);
int shash_register_instance(struct crypto_template *tmpl,
struct shash_instance *inst);
void shash_free_instance(struct crypto_instance *inst);
void shash_free_singlespawn_instance(struct shash_instance *inst);

int crypto_grab_shash(struct crypto_shash_spawn *spawn,
struct crypto_instance *inst,
Expand Down

0 comments on commit a39c66c

Please sign in to comment.