summaryrefslogtreecommitdiffstats
path: root/crypto/akcipher.c
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2020-01-03 05:04:40 +0100
committerHerbert Xu <herbert@gondor.apana.org.au>2020-01-09 04:30:58 +0100
commitd4fdc2dfaa755e0bf22de6a2774cac2e5ae45cf4 (patch)
tree18c2e44d234eaff00fbb2b9ae243d4ea69619651 /crypto/akcipher.c
parentcrypto: algapi - remove crypto_template::{alloc,free}() (diff)
downloadlinux-d4fdc2dfaa755e0bf22de6a2774cac2e5ae45cf4.tar.xz
linux-d4fdc2dfaa755e0bf22de6a2774cac2e5ae45cf4.zip
crypto: algapi - enforce that all instances have a ->free() method
All instances need to have a ->free() method, but people could forget to set it and then not notice if the instance is never unregistered. To help detect this bug earlier, don't allow an instance without a ->free() method to be registered, and complain loudly if someone tries to do it. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/akcipher.c')
-rw-r--r--crypto/akcipher.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/crypto/akcipher.c b/crypto/akcipher.c
index eeed6c151d2f..f866085c8a4a 100644
--- a/crypto/akcipher.c
+++ b/crypto/akcipher.c
@@ -147,6 +147,8 @@ EXPORT_SYMBOL_GPL(crypto_unregister_akcipher);
int akcipher_register_instance(struct crypto_template *tmpl,
struct akcipher_instance *inst)
{
+ if (WARN_ON(!inst->free))
+ return -EINVAL;
akcipher_prepare_alg(&inst->alg);
return crypto_register_instance(tmpl, akcipher_crypto_instance(inst));
}