]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: qce - unregister previously registered algos in error path
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 3 Dec 2024 09:19:30 +0000 (10:19 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:47:11 +0000 (12:47 +0100)
commit e80cf84b608725303113d6fe98bb727bf7b7a40d upstream.

If we encounter an error when registering alorithms with the crypto
framework, we just bail out and don't unregister the ones we
successfully registered in prior iterations of the loop.

Add code that goes back over the algos and unregisters them before
returning an error from qce_register_algs().

Cc: stable@vger.kernel.org
Fixes: ec8f5d8f6f76 ("crypto: qce - Qualcomm crypto engine driver")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/crypto/qce/core.c

index 84efb9dc5dc3deab3dad0d535d2dae51ea9d78e7..92233b9a5501ebedc3a4ccc57509b18b8d8b6a7c 100644 (file)
@@ -45,16 +45,19 @@ static void qce_unregister_algs(struct qce_device *qce)
 static int qce_register_algs(struct qce_device *qce)
 {
        const struct qce_algo_ops *ops;
-       int i, ret = -ENODEV;
+       int i, j, ret = -ENODEV;
 
        for (i = 0; i < ARRAY_SIZE(qce_ops); i++) {
                ops = qce_ops[i];
                ret = ops->register_algs(qce);
-               if (ret)
-                       break;
+               if (ret) {
+                       for (j = i - 1; j >= 0; j--)
+                               ops->unregister_algs(qce);
+                       return ret;
+               }
        }
 
-       return ret;
+       return 0;
 }
 
 static int qce_handle_request(struct crypto_async_request *async_req)