[PATCH] crypto: rockchip - fix algorithm rollback on registration failure

Wanhui Fu fuwh1120 at 163.com
Fri Dec 4 02:06:01 PST 2026


The rollback loop uses i, the index of the failed registration, for
the type check and hash unregistration. Use the loop index k in both
places to clean up the algorithms that were successfully registered.

Found it by self-developed static analysis tool and compile-test passed.

Fixes: bfd927ffa219 ("crypto: rockchip - add hash support for crypto engine in rk3288")
Signed-off-by: Wanhui Fu <fuwh1120 at 163.com>
---
 drivers/crypto/rockchip/rk3288_crypto.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/rockchip/rk3288_crypto.c b/drivers/crypto/rockchip/rk3288_crypto.c
index bb23a179c257..b981ae481410 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -279,10 +279,10 @@ static int rk_crypto_register(struct rk_crypto_info *crypto_info)
 
 err_cipher_algs:
 	for (k = 0; k < i; k++) {
-		if (rk_cipher_algs[i]->type == CRYPTO_ALG_TYPE_SKCIPHER)
+		if (rk_cipher_algs[k]->type == CRYPTO_ALG_TYPE_SKCIPHER)
 			crypto_engine_unregister_skcipher(&rk_cipher_algs[k]->alg.skcipher);
 		else
-			crypto_engine_unregister_ahash(&rk_cipher_algs[i]->alg.hash);
+			crypto_engine_unregister_ahash(&rk_cipher_algs[k]->alg.hash);
 	}
 	return err;
 }
-- 
2.25.1




More information about the linux-arm-kernel mailing list