[PATCH 1/2] crypto: hisilicon/sec2 - fix uninitialized type_supported in sec_create_qp_ctx
From: Chenghai Huang
Date: Fri Jul 17 2026 - 23:05:39 EST
sec_create_qp_ctx() reads ctx->type_supported to pick its callback, but
sec_skcipher_init() and sec_aead_init() set it after sec_ctx_base_init()
has already walked the qp_ctx loop, so the value is uninitialized when
first consumed. Set type_supported in sec_ctx_base_init() before the
loop; the alg init paths now just select req_op from it.
Signed-off-by: Chenghai Huang <huangchenghai2@xxxxxxxxxx>
---
drivers/crypto/hisilicon/sec2/sec_crypto.c | 24 +++++++++++-----------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c
index 77e0e03cbcab..5c2b9f710be0 100644
--- a/drivers/crypto/hisilicon/sec2/sec_crypto.c
+++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c
@@ -672,6 +672,11 @@ static int sec_ctx_base_init(struct sec_ctx *ctx)
ctx->hlf_q_num = sec->ctx_q_num >> 1;
ctx->pbuf_supported = ctx->sec->iommu_used;
+ if (sec->qm.ver < QM_HW_V3)
+ ctx->type_supported = SEC_BD_TYPE2;
+ else
+ ctx->type_supported = SEC_BD_TYPE3;
+
ctx->qp_ctx = kzalloc_objs(struct sec_qp_ctx, sec->ctx_q_num);
if (!ctx->qp_ctx) {
ret = -ENOMEM;
@@ -2067,13 +2072,10 @@ static int sec_skcipher_ctx_init(struct crypto_skcipher *tfm)
if (!ctx->qps)
return 0;
- if (ctx->sec->qm.ver < QM_HW_V3) {
- ctx->type_supported = SEC_BD_TYPE2;
- ctx->req_op = &sec_skcipher_req_ops;
- } else {
- ctx->type_supported = SEC_BD_TYPE3;
+ if (ctx->type_supported == SEC_BD_TYPE3)
ctx->req_op = &sec_skcipher_req_ops_v3;
- }
+ else
+ ctx->req_op = &sec_skcipher_req_ops;
return 0;
}
@@ -2100,13 +2102,11 @@ static int sec_aead_init(struct crypto_aead *tfm)
ret = sec_ctx_base_init(ctx);
if (ret)
return ret;
- if (ctx->sec->qm.ver < QM_HW_V3) {
- ctx->type_supported = SEC_BD_TYPE2;
- ctx->req_op = &sec_aead_req_ops;
- } else {
- ctx->type_supported = SEC_BD_TYPE3;
+
+ if (ctx->type_supported == SEC_BD_TYPE3)
ctx->req_op = &sec_aead_req_ops_v3;
- }
+ else
+ ctx->req_op = &sec_aead_req_ops;
ret = sec_auth_init(ctx);
if (ret)
--
2.43.0