From: Chenghai Huang <huangchenghai2@huawei.com>
To: <herbert@gondor.apana.org.au>, <davem@davemloft.net>
Cc: <linux-kernel@vger.kernel.org>, <linux-crypto@vger.kernel.org>,
<liulongfang@huawei.com>, <qianweili@huawei.com>,
<wangzhou1@hisilicon.com>
Subject: [PATCH 1/2] crypto: hisilicon/sec2 - fix uninitialized type_supported in sec_create_qp_ctx
Date: Sat, 18 Jul 2026 11:05:12 +0800 [thread overview]
Message-ID: <20260718030513.3809002-2-huangchenghai2@huawei.com> (raw)
In-Reply-To: <20260718030513.3809002-1-huangchenghai2@huawei.com>
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>
---
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
next prev parent reply other threads:[~2026-07-18 3:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 3:05 [PATCH 0/2] crypto: hisilicon/sec2 - fix uninitialized type_supported and drop unused hlf_q_num Chenghai Huang
2026-07-18 3:05 ` Chenghai Huang [this message]
2026-07-18 3:05 ` [PATCH 2/2] crypto: hisilicon/sec2 - remove unused sec_ctx.hlf_q_num Chenghai Huang
2026-07-27 0:35 ` [PATCH 0/2] crypto: hisilicon/sec2 - fix uninitialized type_supported and drop unused hlf_q_num Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260718030513.3809002-2-huangchenghai2@huawei.com \
--to=huangchenghai2@huawei.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liulongfang@huawei.com \
--cc=qianweili@huawei.com \
--cc=wangzhou1@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox