
From: Longfang Liu <liulongfang@huawei.com> Upstream: Yes Feature or Bugfix: Bugfix DTS: DTS2025022803997 There are some problems in the public framework code of v1: 1. Some memory judgments are not comprehensive. 2. Some function return values are not checked 3. Some function input parameter verification is incomplete 4. Add some comments to improve code readability 5. Modify some log description errors Signed-off-by: Longfang Liu <liulongfang@huawei.com> Signed-off-by: Qi Tao <taoqi10@huawei.com> --- v1/drv/hisi_qm_udrv.c | 9 ++++++--- v1/wd.c | 13 +++++++++++-- v1/wd_adapter.c | 3 ++- v1/wd_ecc.c | 5 +++-- v1/wd_sgl.c | 6 ++++-- v1/wd_util.c | 2 +- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c index 7b0183bc..755d88e1 100644 --- a/v1/drv/hisi_qm_udrv.c +++ b/v1/drv/hisi_qm_udrv.c @@ -768,13 +768,16 @@ static int hw_type_check(struct wd_queue *q, const char *hw_type) int hisi_qm_inject_op_register(struct wd_queue *q, struct hisi_qm_inject_op *op) { - struct q_info *qinfo = q->qinfo; - struct qm_queue_info *info = qinfo->priv; + struct qm_queue_info *info; + struct q_info *qinfo; - if (!op || !op->sqe_fill_priv || !op->sqe_parse_priv) { + if (!q || !q->qinfo || !op || !op->sqe_fill_priv || + !op->sqe_parse_priv) { WD_ERR("inject option is invalid!\n"); return -WD_EINVAL; } + qinfo = q->qinfo; + info = qinfo->priv; if (hw_type_check(q, op->hw_type)) { WD_ERR("inject option hw compare error!\n"); diff --git a/v1/wd.c b/v1/wd.c index 02bc49cc..13239b58 100644 --- a/v1/wd.c +++ b/v1/wd.c @@ -868,14 +868,18 @@ void wd_drv_unmmap_qfr(struct wd_queue *q, void *addr, enum uacce_qfrt qfrt, size_t size) { struct q_info *qinfo = q->qinfo; + int ret; if (!addr) return; if (qfrt != WD_UACCE_QFRT_SS) - munmap(addr, qinfo->qfrs_offset[qfrt]); + ret = munmap(addr, qinfo->qfrs_offset[qfrt]); else - munmap(addr, size); + ret = munmap(addr, size); + + if (ret) + WD_ERR("wd qfr unmap failed!\n"); } int wd_register_log(wd_log log) @@ -890,6 +894,11 @@ int wd_register_log(wd_log log) return -WD_EINVAL; } + /* + * No exceptions are generated during concurrency. + * Users are required to ensure the order of configuration + * operations + */ log_out = log; dbg("log register\n"); diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c index f9d5f041..0c9cd334 100644 --- a/v1/wd_adapter.c +++ b/v1/wd_adapter.c @@ -93,10 +93,11 @@ static const struct wd_drv_dio_if hw_dio_tbl[] = { { int drv_open(struct wd_queue *q) { struct q_info *qinfo = q->qinfo; + __u32 type_size = MAX_HW_TYPE; __u32 i; /* try to find another device if the user driver is not available */ - for (i = 0; i < MAX_HW_TYPE; i++) { + for (i = 0; i < type_size; i++) { if (!strcmp(qinfo->hw_type, hw_dio_tbl[i].hw_type)) { qinfo->hw_type_id = i; diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c index 8bb58792..a887e00c 100644 --- a/v1/wd_ecc.c +++ b/v1/wd_ecc.c @@ -200,7 +200,8 @@ static void *br_alloc(struct wd_mm_br *br, __u64 size) } if (br->get_bufsize && br->get_bufsize(br->usr) < size) { - WD_ERR("Blk_size < need_size<0x%llx>.\n", size); + WD_ERR("Blk_size<0x%x> < need_size<0x%llx>.\n", + br->get_bufsize(br->usr), size); return NULL; } @@ -2199,7 +2200,7 @@ int wcrypto_do_ecdsa(void *ctx, struct wcrypto_ecc_op_data *opdata, void *tag) int wcrypto_ecdsa_poll(struct wd_queue *q, unsigned int num) { if (unlikely(!q || strcmp(q->capa.alg, "ecdsa"))) { - WD_ERR("sm2 poll: input parameter error!\n"); + WD_ERR("ecdsa poll: input parameter error!\n"); return -WD_EINVAL; } diff --git a/v1/wd_sgl.c b/v1/wd_sgl.c index cb3b8eeb..eef4f6c0 100644 --- a/v1/wd_sgl.c +++ b/v1/wd_sgl.c @@ -1026,6 +1026,8 @@ void wd_sgl_memset(struct wd_sgl *sgl, int ch) return; } - for (i = 0; i < sgl->buf_num; i++) - memset(sgl->sge[i].buf, ch, sgl->pool->setup.buf_size); + for (i = 0; i < sgl->buf_num; i++) { + if (sgl->sge[i].buf) + memset(sgl->sge[i].buf, ch, sgl->pool->setup.buf_size); + } } diff --git a/v1/wd_util.c b/v1/wd_util.c index 3dac2d74..0bc9d04e 100644 --- a/v1/wd_util.c +++ b/v1/wd_util.c @@ -143,7 +143,7 @@ int wd_init_cookie_pool(struct wd_cookie_pool *pool, void wd_uninit_cookie_pool(struct wd_cookie_pool *pool) { - if (pool->cookies) { + if (pool && pool->cookies) { free(pool->cookies); pool->cookies = NULL; } -- 2.33.0