Skip to content

Commit

Permalink
crypto: aead - Add type-safe function for freeing instances
Browse files Browse the repository at this point in the history
This patch adds a type-safe function for freeing AEAD instances
to struct aead_instance.  This replaces the existing free function
in struct crypto_template which does not know the type of the
instance that it's freeing.

Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
herbertx committed Jul 14, 2015
1 parent 319382a commit ba75e15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crypto/aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,22 @@ static void crypto_aead_show(struct seq_file *m, struct crypto_alg *alg)
seq_printf(m, "geniv : <none>\n");
}

static void crypto_aead_free_instance(struct crypto_instance *inst)
{
struct aead_instance *aead = aead_instance(inst);

if (!aead->free) {
inst->tmpl->free(inst);
return;
}

aead->free(aead);
}

static const struct crypto_type crypto_new_aead_type = {
.extsize = crypto_alg_extsize,
.init_tfm = crypto_aead_init_tfm,
.free = crypto_aead_free_instance,
#ifdef CONFIG_PROC_FS
.show = crypto_aead_show,
#endif
Expand Down
1 change: 1 addition & 0 deletions include/crypto/internal/aead.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
struct rtattr;

struct aead_instance {
void (*free)(struct aead_instance *inst);
union {
struct {
char head[offsetof(struct aead_alg, base)];
Expand Down

0 comments on commit ba75e15

Please sign in to comment.