crypto: algapi - make unregistration functions return void
authorEric Biggers <ebiggers@google.com>
Sun, 15 Dec 2019 23:51:19 +0000 (15:51 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 20 Dec 2019 06:58:35 +0000 (14:58 +0800)
Some of the algorithm unregistration functions return -ENOENT when asked
to unregister a non-registered algorithm, while others always return 0
or always return void.  But no users check the return value, except for
two of the bulk unregistration functions which print a message on error
but still always return 0 to their caller, and crypto_del_alg() which
calls crypto_unregister_instance() which always returns 0.

Since unregistering a non-registered algorithm is always a kernel bug
but there isn't anything callers should do to handle this situation at
runtime, let's simplify things by making all the unregistration
functions return void, and moving the error message into
crypto_unregister_alg() and upgrading it to a WARN().

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
12 files changed:
Documentation/crypto/devel-algos.rst
crypto/acompress.c
crypto/ahash.c
crypto/algapi.c
crypto/crypto_user_base.c
crypto/scompress.c
crypto/shash.c
include/crypto/algapi.h
include/crypto/internal/acompress.h
include/crypto/internal/hash.h
include/crypto/internal/scompress.h
include/linux/crypto.h

index fb6b7979a1de498da0b2d02a206cc2370f00b57e..f225a953ab4b9fb4891833872a1748d4c58d80a2 100644 (file)
@@ -31,28 +31,18 @@ The counterparts to those functions are listed below.
 
 ::
 
-       int crypto_unregister_alg(struct crypto_alg *alg);
-       int crypto_unregister_algs(struct crypto_alg *algs, int count);
+       void crypto_unregister_alg(struct crypto_alg *alg);
+       void crypto_unregister_algs(struct crypto_alg *algs, int count);
 
 
-Notice that both registration and unregistration functions do return a
-value, so make sure to handle errors. A return code of zero implies
-success. Any return code < 0 implies an error.
+The registration functions return 0 on success, or a negative errno
+value on failure.  crypto_register_algs() succeeds only if it
+successfully registered all the given algorithms; if it fails partway
+through, then any changes are rolled back.
 
-The bulk registration/unregistration functions register/unregister each
-transformation in the given array of length count. They handle errors as
-follows:
-
--  crypto_register_algs() succeeds if and only if it successfully
-   registers all the given transformations. If an error occurs partway
-   through, then it rolls back successful registrations before returning
-   the error code. Note that if a driver needs to handle registration
-   errors for individual transformations, then it will need to use the
-   non-bulk function crypto_register_alg() instead.
-
--  crypto_unregister_algs() tries to unregister all the given
-   transformations, continuing on error. It logs errors and always
-   returns zero.
+The unregistration functions always succeed, so they don't have a
+return value.  Don't try to unregister algorithms that aren't
+currently registered.
 
 Single-Block Symmetric Ciphers [CIPHER]
 ---------------------------------------
@@ -169,10 +159,10 @@ are as follows:
 
 ::
 
-       int crypto_unregister_ahash(struct ahash_alg *alg);
+       void crypto_unregister_ahash(struct ahash_alg *alg);
 
-       int crypto_unregister_shash(struct shash_alg *alg);
-       int crypto_unregister_shashes(struct shash_alg *algs, int count);
+       void crypto_unregister_shash(struct shash_alg *alg);
+       void crypto_unregister_shashes(struct shash_alg *algs, int count);
 
 
 Cipher Definition With struct shash_alg and ahash_alg
index abadcb035a41fe76fe3fe8180bec13141f9503d2..84a76723e851bf64d924dca14a6d60ea1dd81b90 100644 (file)
@@ -151,9 +151,9 @@ int crypto_register_acomp(struct acomp_alg *alg)
 }
 EXPORT_SYMBOL_GPL(crypto_register_acomp);
 
-int crypto_unregister_acomp(struct acomp_alg *alg)
+void crypto_unregister_acomp(struct acomp_alg *alg)
 {
-       return crypto_unregister_alg(&alg->base);
+       crypto_unregister_alg(&alg->base);
 }
 EXPORT_SYMBOL_GPL(crypto_unregister_acomp);
 
index 3815b363a6934b1f195d855d5591b026d59ceccb..181bd851b429b81997cd5a8f0e30009fc76cbdb1 100644 (file)
@@ -598,9 +598,9 @@ int crypto_register_ahash(struct ahash_alg *alg)
 }
 EXPORT_SYMBOL_GPL(crypto_register_ahash);
 
-int crypto_unregister_ahash(struct ahash_alg *alg)
+void crypto_unregister_ahash(struct ahash_alg *alg)
 {
-       return crypto_unregister_alg(&alg->halg.base);
+       crypto_unregister_alg(&alg->halg.base);
 }
 EXPORT_SYMBOL_GPL(crypto_unregister_ahash);
 
index 9589b3f0041b6b171d55684bb35edb4317617836..fe57b4f696ac7b93b18158f1c64792025aa7af4a 100644 (file)
@@ -442,7 +442,7 @@ static int crypto_remove_alg(struct crypto_alg *alg, struct list_head *list)
        return 0;
 }
 
-int crypto_unregister_alg(struct crypto_alg *alg)
+void crypto_unregister_alg(struct crypto_alg *alg)
 {
        int ret;
        LIST_HEAD(list);
@@ -451,15 +451,14 @@ int crypto_unregister_alg(struct crypto_alg *alg)
        ret = crypto_remove_alg(alg, &list);
        up_write(&crypto_alg_sem);
 
-       if (ret)
-               return ret;
+       if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name))
+               return;
 
        BUG_ON(refcount_read(&alg->cra_refcnt) != 1);
        if (alg->cra_destroy)
                alg->cra_destroy(alg);
 
        crypto_remove_final(&list);
-       return 0;
 }
 EXPORT_SYMBOL_GPL(crypto_unregister_alg);
 
@@ -483,18 +482,12 @@ err:
 }
 EXPORT_SYMBOL_GPL(crypto_register_algs);
 
-int crypto_unregister_algs(struct crypto_alg *algs, int count)
+void crypto_unregister_algs(struct crypto_alg *algs, int count)
 {
-       int i, ret;
-
-       for (i = 0; i < count; i++) {
-               ret = crypto_unregister_alg(&algs[i]);
-               if (ret)
-                       pr_err("Failed to unregister %s %s: %d\n",
-                              algs[i].cra_driver_name, algs[i].cra_name, ret);
-       }
+       int i;
 
-       return 0;
+       for (i = 0; i < count; i++)
+               crypto_unregister_alg(&algs[i]);
 }
 EXPORT_SYMBOL_GPL(crypto_unregister_algs);
 
@@ -639,7 +632,7 @@ err:
 }
 EXPORT_SYMBOL_GPL(crypto_register_instance);
 
-int crypto_unregister_instance(struct crypto_instance *inst)
+void crypto_unregister_instance(struct crypto_instance *inst)
 {
        LIST_HEAD(list);
 
@@ -651,8 +644,6 @@ int crypto_unregister_instance(struct crypto_instance *inst)
        up_write(&crypto_alg_sem);
 
        crypto_remove_final(&list);
-
-       return 0;
 }
 EXPORT_SYMBOL_GPL(crypto_unregister_instance);
 
index b785c476de67b367894eb099f1ba8cda6a351001..3fa20f12989f7ef2765a2a158a34eac455d4b9f8 100644 (file)
@@ -323,7 +323,8 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
        if (refcount_read(&alg->cra_refcnt) > 2)
                goto drop_alg;
 
-       err = crypto_unregister_instance((struct crypto_instance *)alg);
+       crypto_unregister_instance((struct crypto_instance *)alg);
+       err = 0;
 
 drop_alg:
        crypto_mod_put(alg);
index 4d50750d01c68652e85c64da900d0dd7966f684c..738f4f8f0f41ac356de42004784ec680593d1153 100644 (file)
@@ -266,9 +266,9 @@ int crypto_register_scomp(struct scomp_alg *alg)
 }
 EXPORT_SYMBOL_GPL(crypto_register_scomp);
 
-int crypto_unregister_scomp(struct scomp_alg *alg)
+void crypto_unregister_scomp(struct scomp_alg *alg)
 {
-       return crypto_unregister_alg(&alg->base);
+       crypto_unregister_alg(&alg->base);
 }
 EXPORT_SYMBOL_GPL(crypto_unregister_scomp);
 
index 8042bb0df9c057ed2c5fa11a87fe1280eae4b588..7243f60dab877a74861237838a25066a85e35ca4 100644 (file)
@@ -520,9 +520,9 @@ int crypto_register_shash(struct shash_alg *alg)
 }
 EXPORT_SYMBOL_GPL(crypto_register_shash);
 
-int crypto_unregister_shash(struct shash_alg *alg)
+void crypto_unregister_shash(struct shash_alg *alg)
 {
-       return crypto_unregister_alg(&alg->base);
+       crypto_unregister_alg(&alg->base);
 }
 EXPORT_SYMBOL_GPL(crypto_unregister_shash);
 
@@ -546,19 +546,12 @@ err:
 }
 EXPORT_SYMBOL_GPL(crypto_register_shashes);
 
-int crypto_unregister_shashes(struct shash_alg *algs, int count)
+void crypto_unregister_shashes(struct shash_alg *algs, int count)
 {
-       int i, ret;
-
-       for (i = count - 1; i >= 0; --i) {
-               ret = crypto_unregister_shash(&algs[i]);
-               if (ret)
-                       pr_err("Failed to unregister %s %s: %d\n",
-                              algs[i].base.cra_driver_name,
-                              algs[i].base.cra_name, ret);
-       }
+       int i;
 
-       return 0;
+       for (i = count - 1; i >= 0; --i)
+               crypto_unregister_shash(&algs[i]);
 }
 EXPORT_SYMBOL_GPL(crypto_unregister_shashes);
 
index 771a295ac755d599b7fe6d0e8ab3fa5ad8e100b4..25661b4650ecd3337e81b535cbd2dec829f74d01 100644 (file)
@@ -96,7 +96,7 @@ struct crypto_template *crypto_lookup_template(const char *name);
 
 int crypto_register_instance(struct crypto_template *tmpl,
                             struct crypto_instance *inst);
-int crypto_unregister_instance(struct crypto_instance *inst);
+void crypto_unregister_instance(struct crypto_instance *inst);
 
 int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg,
                      struct crypto_instance *inst, u32 mask);
index 9de57367afbb25b41679a89d6a9a9b7a4174cfb6..cf478681b53e7e5a1303d01fcf36b57410e175c5 100644 (file)
@@ -68,10 +68,8 @@ int crypto_register_acomp(struct acomp_alg *alg);
  * compression algorithm
  *
  * @alg:       algorithm definition
- *
- * Return:     zero on success; error code in case of error
  */
-int crypto_unregister_acomp(struct acomp_alg *alg);
+void crypto_unregister_acomp(struct acomp_alg *alg);
 
 int crypto_register_acomps(struct acomp_alg *algs, int count);
 void crypto_unregister_acomps(struct acomp_alg *algs, int count);
index cf8d7f99c93d8a12360e3fdd74ea881269a6e00a..d4b1be5195902d1c252735a0587caa20bd8ce047 100644 (file)
@@ -70,7 +70,7 @@ static inline int crypto_ahash_walk_last(struct crypto_hash_walk *walk)
 }
 
 int crypto_register_ahash(struct ahash_alg *alg);
-int crypto_unregister_ahash(struct ahash_alg *alg);
+void crypto_unregister_ahash(struct ahash_alg *alg);
 int crypto_register_ahashes(struct ahash_alg *algs, int count);
 void crypto_unregister_ahashes(struct ahash_alg *algs, int count);
 int ahash_register_instance(struct crypto_template *tmpl,
@@ -105,9 +105,9 @@ static inline void crypto_drop_ahash(struct crypto_ahash_spawn *spawn)
 struct hash_alg_common *ahash_attr_alg(struct rtattr *rta, u32 type, u32 mask);
 
 int crypto_register_shash(struct shash_alg *alg);
-int crypto_unregister_shash(struct shash_alg *alg);
+void crypto_unregister_shash(struct shash_alg *alg);
 int crypto_register_shashes(struct shash_alg *algs, int count);
-int crypto_unregister_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);
index 6727ef0fc4d11df26984a7bb3d6be6b5517a65e0..f834274c2493fa9d16d82cc4bf9150f412b61e6f 100644 (file)
@@ -112,10 +112,8 @@ int crypto_register_scomp(struct scomp_alg *alg);
  * compression algorithm
  *
  * @alg:       algorithm definition
- *
- * Return: zero on success; error code in case of error
  */
-int crypto_unregister_scomp(struct scomp_alg *alg);
+void crypto_unregister_scomp(struct scomp_alg *alg);
 
 int crypto_register_scomps(struct scomp_alg *algs, int count);
 void crypto_unregister_scomps(struct scomp_alg *algs, int count);
index c23f1eed7970292adb96db5682f2639687a130e4..a905e524e3322ed0da0a5faecb11216a76fadf2b 100644 (file)
@@ -584,9 +584,9 @@ static inline void crypto_init_wait(struct crypto_wait *wait)
  * Algorithm registration interface.
  */
 int crypto_register_alg(struct crypto_alg *alg);
-int crypto_unregister_alg(struct crypto_alg *alg);
+void crypto_unregister_alg(struct crypto_alg *alg);
 int crypto_register_algs(struct crypto_alg *algs, int count);
-int crypto_unregister_algs(struct crypto_alg *algs, int count);
+void crypto_unregister_algs(struct crypto_alg *algs, int count);
 
 /*
  * Algorithm query interface.