crypto: aead - Add type-safe function for freeing instances
authorHerbert Xu <herbert@gondor.apana.org.au>
Wed, 8 Jul 2015 23:17:17 +0000 (07:17 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 14 Jul 2015 06:56:45 +0000 (14:56 +0800)
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 <herbert@gondor.apana.org.au>
crypto/aead.c
include/crypto/internal/aead.h

index 07bf99773548bf9f088b6ff8380edb4caf7cda4a..8cd45a7eb7afb7d1a7095e625238cd99ef423b7a 100644 (file)
@@ -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
index c3942f4d6e9f97883daf3e9726186835a4dc230e..a292e960fb33c4073576962d634ce6c7f36af475 100644 (file)
@@ -21,6 +21,7 @@
 struct rtattr;
 
 struct aead_instance {
+       void (*free)(struct aead_instance *inst);
        union {
                struct {
                        char head[offsetof(struct aead_alg, base)];