[PATCH 15/30] crypto: sa2ul - fix context release on errors

From: Manorit Chawdhry

Date: Tue Sep 15 2026 - 06:08:09 EST


Fix security context cleanup in error paths to prevent memory
leaks when crypto operations fail.

Fixes: 7694b6ca649f ("crypto: sa2ul - Add crypto driver")
Assisted-by: Sisyphus:claude-sonnet-4-6
Signed-off-by: Manorit Chawdhry <m-chawdhry@xxxxxx>
---
drivers/crypto/sa2ul.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index 7ec048136114..cd80a2dabc99 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -826,16 +826,14 @@ static int sa_cipher_cra_init(struct crypto_skcipher *tfm)
if (ret)
return ret;
ret = sa_init_ctx_info(&ctx->dec, data);
- if (ret) {
- sa_free_ctx_info(&ctx->enc, data);
- return ret;
- }
+ if (ret)
+ goto ctx_dec_err;

child = crypto_alloc_skcipher(name, 0, CRYPTO_ALG_NEED_FALLBACK);
-
if (IS_ERR(child)) {
dev_err(sa_k3_dev, "Error allocating fallback algo %s\n", name);
- return PTR_ERR(child);
+ ret = PTR_ERR(child);
+ goto alloc_err;
}

ctx->fallback.skcipher = child;
@@ -846,6 +844,11 @@ static int sa_cipher_cra_init(struct crypto_skcipher *tfm)
__func__, tfm, ctx->enc.sc_id, &ctx->enc.sc_phys,
ctx->dec.sc_id, &ctx->dec.sc_phys);
return 0;
+alloc_err:
+ sa_free_ctx_info(&ctx->dec, data);
+ctx_dec_err:
+ sa_free_ctx_info(&ctx->enc, data);
+ return ret;
}

static int sa_cipher_setkey(struct crypto_skcipher *tfm, const u8 *key,

--
2.43.0