crypto: hisilicon/sec2 - fix uninitialized type_supported in sec_create_qp_ctx

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@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Chenghai Huang
2026-07-27 10:29:27 +10:00
committed by Herbert Xu
parent b0b8583719
commit 67ca4ac78f
+12 -12
View File
@@ -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)