UADK_ALG_HW is calc_type of driver property, fix it.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wd_util.c b/wd_util.c index 633d957..6593dad 100644 --- a/wd_util.c +++ b/wd_util.c @@ -1968,7 +1968,7 @@ void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
driver->exit(priv); /* Ctx config just need clear once */ - if (driver->priority == UADK_ALG_HW) + if (driver->calc_type == UADK_ALG_HW) wd_clear_ctx_config(config);
if (driver->fallback)
End index will rollover if idx and ctx_num are zero, it will cause region without ctxs to be activated.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_util.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/wd_util.c b/wd_util.c index 6593dad..b5e3697 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2445,16 +2445,18 @@ static int wd_instance_sched_set(struct wd_sched *sched, struct wd_ctx_nums ctx_ int idx, int numa_id, int op_type) { struct sched_params sparams; - int i, ret = 0; + int i, end, ret = 0;
for (i = 0; i < CTX_MODE_MAX; i++) { sparams.numa_id = numa_id; sparams.type = op_type; sparams.mode = i; sparams.begin = idx + ctx_nums.sync_ctx_num * i; - sparams.end = idx - 1 + ctx_nums.sync_ctx_num + ctx_nums.async_ctx_num * i; - if (sparams.begin > sparams.end) + end = idx - 1 + ctx_nums.sync_ctx_num + ctx_nums.async_ctx_num * i; + if (end < 0 || sparams.begin > end) continue; + + sparams.end = end; ret = wd_sched_rr_instance(sched, &sparams); if (ret) goto out;
When the number of queues is used up, wd_find_dev_by_numa returns null. If the number of queues corresponding to the current operation type is 0, uadk is not need to obtain available devices.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_util.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/wd_util.c b/wd_util.c index b5e3697..db42fa3 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2409,6 +2409,10 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l struct uacce_dev *dev; int i;
+ /* If the ctx set number is 0, the initialization is skipped. */ + if (!ctx_set_num) + return 0; + dev = wd_find_dev_by_numa(list, numa_id); if (WD_IS_ERR(dev)) return WD_PTR_ERR(dev);
wd parse log level should be done before wd_need_info.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/wd.c b/wd.c index 300a996..a6acf8b 100644 --- a/wd.c +++ b/wd.c @@ -29,7 +29,7 @@ enum UADK_LOG_LEVEL { WD_LOG_DEBUG, };
-static int uadk_log_level; +static int uadk_log_level = -1;
struct wd_ctx_h { int fd; @@ -265,8 +265,6 @@ static struct uacce_dev *read_uacce_sysfs(const char *dev_name) if (!dev_name) return NULL;
- wd_parse_log_level(); - dev = calloc(1, sizeof(struct uacce_dev)); if (!dev) return NULL; @@ -871,11 +869,17 @@ void wd_get_version(void)
bool wd_need_debug(void) { + if (uadk_log_level < 0) + wd_parse_log_level(); + return uadk_log_level >= WD_LOG_DEBUG; }
bool wd_need_info(void) { + if (uadk_log_level < 0) + wd_parse_log_level(); + return uadk_log_level >= WD_LOG_INFO; }
The log level that is not initialized is set to invalid. the default log level is set to none. wd_parse_log_level should only execute one time.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-)
diff --git a/wd.c b/wd.c index a6acf8b..c2559a4 100644 --- a/wd.c +++ b/wd.c @@ -23,13 +23,14 @@ #define SYS_CLASS_DIR "/sys/class/uacce"
enum UADK_LOG_LEVEL { - LOG_NONE = 0, + WD_LOG_NONE = 0, WD_LOG_ERROR, WD_LOG_INFO, WD_LOG_DEBUG, + WD_LOG_INVALID, };
-static int uadk_log_level = -1; +static int uadk_log_level = WD_LOG_INVALID;
struct wd_ctx_h { int fd; @@ -52,6 +53,9 @@ static void wd_parse_log_level(void) char *file_contents; FILE *in_file;
+ if (uadk_log_level == WD_LOG_INVALID) + uadk_log_level = WD_LOG_NONE; + in_file = fopen(syslog_file, "r"); if (!in_file) { WD_ERR("failed to open the rsyslog.conf file.\n"); @@ -869,18 +873,36 @@ void wd_get_version(void)
bool wd_need_debug(void) { - if (uadk_log_level < 0) + switch (uadk_log_level) { + case WD_LOG_NONE: + case WD_LOG_ERROR: + case WD_LOG_INFO: + return false; + case WD_LOG_DEBUG: + return true; + case WD_LOG_INVALID: wd_parse_log_level(); - - return uadk_log_level >= WD_LOG_DEBUG; + return uadk_log_level >= WD_LOG_DEBUG; + default: + return false; + } }
bool wd_need_info(void) { - if (uadk_log_level < 0) + switch (uadk_log_level) { + case WD_LOG_NONE: + case WD_LOG_ERROR: + return false; + case WD_LOG_INFO: + case WD_LOG_DEBUG: + return true; + case WD_LOG_INVALID: wd_parse_log_level(); - - return uadk_log_level >= WD_LOG_INFO; + return uadk_log_level >= WD_LOG_INFO; + default: + return false; + } }
char *wd_ctx_get_dev_name(handle_t h_ctx)
integer operation may be truncated before being combined with a larger pointer type.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- lib/crypto/aes.c | 8 ++++++-- v1/wd_bmm.c | 2 +- v1/wd_rsa.c | 6 +++--- v1/wd_sgl.c | 21 +++++++++++---------- wd_mempool.c | 8 +++++--- wd_rsa.c | 6 +++--- 6 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/lib/crypto/aes.c b/lib/crypto/aes.c index 2145d24..b1425bc 100644 --- a/lib/crypto/aes.c +++ b/lib/crypto/aes.c @@ -2,6 +2,7 @@ /* Copyright 2023 Huawei Technologies Co.,Ltd. All rights reserved. */
#include <string.h> +#include <stdint.h> #include "crypto/aes.h"
#define WORD(n) (0x##n##n##n##n) @@ -284,6 +285,7 @@ static void cipher(const unsigned char *in, unsigned char *out, { #define STATE_BYTE 16 __u64 state[STATE_CNT]; + __u64 *s; __u8 i;
memcpy(state, in, STATE_BYTE); @@ -295,13 +297,15 @@ static void cipher(const unsigned char *in, unsigned char *out, sublong(&state[1]); shift_rows(state); mix_columns(state); - add_round_key(state, w + i * STATE_CNT); + s = (void *)((uintptr_t)w + i * STATE_CNT * sizeof(__u64)); + add_round_key(state, s); }
sublong(&state[0]); sublong(&state[1]); shift_rows(state); - add_round_key(state, w + nr * STATE_CNT); + s = (void *)((uintptr_t)w + nr * STATE_CNT * sizeof(__u64)); + add_round_key(state, s);
memcpy(out, state, STATE_BYTE); } diff --git a/v1/wd_bmm.c b/v1/wd_bmm.c index 8f41997..5fd15e5 100644 --- a/v1/wd_bmm.c +++ b/v1/wd_bmm.c @@ -193,7 +193,7 @@ static int usr_pool_init(struct wd_blkpool *p) p->act_start = (void *)ALIGN((uintptr_t)p->usr_mem_start, sp->align_size); for (i = 0; i < sp->block_num; i++) { - hd = p->act_start + (p->act_hd_sz + p->act_blk_sz) * i; + hd = (void *)((uintptr_t)p->act_start + (p->act_hd_sz + p->act_blk_sz) * i); hd->blk = (void *)((uintptr_t)hd + p->act_hd_sz); hd->blk_dma = sp->br.iova_map(sp->br.usr, hd->blk, blk_size); if (!hd->blk_dma) { diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c index 250f479..c5c109d 100644 --- a/v1/wd_rsa.c +++ b/v1/wd_rsa.c @@ -215,7 +215,7 @@ struct wcrypto_rsa_kg_in *wcrypto_new_kg_in(void *ctx, struct wd_dtb *e, kg_in->qbytes = q->dsize; kg_in->e = (void *)kg_in->data; kg_in->p = (void *)kg_in->e + c->key_size; - kg_in->q = (void *)kg_in->p + CRT_PARAM_SZ(c->key_size); + kg_in->q = (void *)((uintptr_t)kg_in->p + CRT_PARAM_SZ(c->key_size));
memcpy(kg_in->e, e->data, e->dsize); memcpy(kg_in->p, p->data, p->dsize); @@ -310,8 +310,8 @@ struct wcrypto_rsa_kg_out *wcrypto_new_kg_out(void *ctx) kg_out->size = (__u32)kg_out_size; if (c->setup.is_crt) { kg_out->qinv = (void *)kg_out->n + kz; - kg_out->dq = kg_out->qinv + CRT_PARAM_SZ(kz); - kg_out->dp = kg_out->dq + CRT_PARAM_SZ(kz); + kg_out->dq = (void *)((uintptr_t)kg_out->qinv + CRT_PARAM_SZ(kz)); + kg_out->dp = (void *)((uintptr_t)kg_out->dq + CRT_PARAM_SZ(kz)); }
return kg_out; diff --git a/v1/wd_sgl.c b/v1/wd_sgl.c index dffbf12..ceb7f4c 100644 --- a/v1/wd_sgl.c +++ b/v1/wd_sgl.c @@ -601,22 +601,22 @@ static void sgl_cp_to_pbuf(struct wd_sgl *src_sgl, int start_sg, int strtad, return;
size -= sz - strtad; - pbuf += sz - strtad; + pbuf = (void *)((uintptr_t)pbuf + sz - strtad); for (i = strtsg + 1; i <= sgl->buf_num - 1 && size > sz; i++) { - memcpy(pbuf + (i - strtsg - 1) * sz, sgl->sge[i].buf, sz); + memcpy((void *)((uintptr_t)pbuf + (i - strtsg - 1) * sz), sgl->sge[i].buf, sz); size -= sz; }
if (i <= sgl->buf_num - 1) { - memcpy(pbuf + (i - strtsg - 1) * sz, sgl->sge[i].buf, size); + memcpy((void *)((uintptr_t)pbuf + (i - strtsg - 1) * sz), sgl->sge[i].buf, size); } else { sgl = next; for (i = 0; i < sgl->buf_num - 1 && size > sz; i++) { - memcpy(pbuf + (i + sgl->buf_num - strtsg - 1) * sz, + memcpy((void *)((uintptr_t)pbuf + (i + sgl->buf_num - strtsg - 1) * sz), sgl->sge[i].buf, sz); size -= sz; } - memcpy(pbuf + (i + sgl->buf_num - strtsg - 1) * sz, + memcpy((void *)((uintptr_t)pbuf + (i + sgl->buf_num - strtsg - 1) * sz), sgl->sge[i].buf, size); } } @@ -687,25 +687,26 @@ static void sgl_cp_from_pbuf(struct wd_sgl *dst_sgl, int start_sg, int strtad, return;
size -= sz - strtad; - pbuf += sz - strtad; + pbuf = (void *)((uintptr_t)pbuf + sz - strtad); for (i = strtsg + 1; i <= sgl->buf_num - 1 && size > sz; i++) { - memcpy(sgl->sge[i].buf, pbuf + (i - strtsg - 1) * sz, sz); + memcpy(sgl->sge[i].buf, (void *)((uintptr_t)pbuf + (i - strtsg - 1) * sz), sz); sgl->sge[i].data_len = sz; size -= sz; }
if (i <= sgl->buf_num - 1) { - memcpy(sgl->sge[i].buf, pbuf + (i - strtsg - 1) * sz, size); + memcpy(sgl->sge[i].buf, (void *)((uintptr_t)pbuf + (i - strtsg - 1) * sz), size); } else { sgl = next; for (i = 0; i < sgl->buf_num - 1 && size > sz; i++) { memcpy(sgl->sge[i].buf, - pbuf + (i + sgl->buf_num - strtsg - 1) * sz, sz); + (void *)((uintptr_t)pbuf + (i + sgl->buf_num - strtsg - 1) * sz), + sz); sgl->sge[i].data_len = sz; size -= sz; } memcpy(sgl->sge[i].buf, - pbuf + (i + sgl->buf_num - strtsg - 1) * sz, size); + (void *)((uintptr_t)pbuf + (i + sgl->buf_num - strtsg - 1) * sz), size); } sgl->sge[i].data_len = size; } diff --git a/wd_mempool.c b/wd_mempool.c index b27d28c..db88fb0 100644 --- a/wd_mempool.c +++ b/wd_mempool.c @@ -273,8 +273,9 @@ static void set_bit(struct bitmap *bm, unsigned int pos) { unsigned long *map = bm->map; unsigned long mask = BIT_MASK(pos); - unsigned long *p = map + BIT_WORD(pos); + unsigned long *p;
+ p = (void *)((uintptr_t)map + BIT_WORD(pos) * sizeof(unsigned long)); *p |= mask; }
@@ -282,14 +283,15 @@ static void clear_bit(struct bitmap *bm, unsigned int pos) { unsigned long *map = bm->map; unsigned long mask = BIT_MASK(pos); - unsigned long *p = map + BIT_WORD(pos); + unsigned long *p;
+ p = (void *)((uintptr_t)map + BIT_WORD(pos) * sizeof(unsigned long)); *p &= ~mask; }
static int test_bit(struct bitmap *bm, unsigned int nr) { - unsigned long *p = bm->map + BIT_WORD(nr); + unsigned long *p = (void *)((uintptr_t)bm->map + BIT_WORD(nr) * sizeof(unsigned long)); unsigned long mask = BIT_MASK(nr);
return !(*p & mask); diff --git a/wd_rsa.c b/wd_rsa.c index 00ac772..ac2106e 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -620,7 +620,7 @@ struct wd_rsa_kg_in *wd_rsa_new_kg_in(handle_t sess, struct wd_dtb *e, kg_in->qbytes = q->dsize; kg_in->e = (void *)kg_in->data; kg_in->p = (void *)kg_in->e + c->key_size; - kg_in->q = (void *)kg_in->p + CRT_PARAM_SZ(c->key_size); + kg_in->q = (void *)((uintptr_t)kg_in->p + CRT_PARAM_SZ(c->key_size));
memcpy(kg_in->e, e->data, e->dsize); memcpy(kg_in->p, p->data, p->dsize); @@ -699,8 +699,8 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess) kg_out->size = kg_out_size; if (c->setup.is_crt) { kg_out->qinv = (void *)kg_out->n + kz; - kg_out->dq = kg_out->qinv + CRT_PARAM_SZ(kz); - kg_out->dp = kg_out->dq + CRT_PARAM_SZ(kz); + kg_out->dq = (void *)((uintptr_t)kg_out->qinv + CRT_PARAM_SZ(kz)); + kg_out->dp = (void *)((uintptr_t)kg_out->dq + CRT_PARAM_SZ(kz)); }
return kg_out;
void function should not return void expression.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/wd_ecc.c | 6 +++--- wd_aead.c | 4 ++-- wd_cipher.c | 4 ++-- wd_comp.c | 4 ++-- wd_dh.c | 4 ++-- wd_digest.c | 4 ++-- wd_ecc.c | 8 ++++---- wd_rsa.c | 4 ++-- 8 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c index e6b771a..f5c76a8 100644 --- a/v1/wd_ecc.c +++ b/v1/wd_ecc.c @@ -214,7 +214,7 @@ static void br_free(struct wd_mm_br *br, void *va) return; }
- return br->free(br->usr, va); + br->free(br->usr, va); }
static __u32 get_hw_keysize(__u32 ksz) @@ -1699,7 +1699,7 @@ static void get_sign_out_params(struct wcrypto_ecc_out *out, void wcrypto_get_ecdsa_sign_out_params(struct wcrypto_ecc_out *out, struct wd_dtb **r, struct wd_dtb **s) { - return get_sign_out_params(out, r, s); + get_sign_out_params(out, r, s); }
@@ -2218,7 +2218,7 @@ void wcrypto_get_sm2_sign_out_params(struct wcrypto_ecc_out *out, struct wd_dtb **r, struct wd_dtb **s) { - return get_sign_out_params(out, r, s); + get_sign_out_params(out, r, s); }
struct wcrypto_ecc_out *wcrypto_new_sm2_kg_out(void *ctx) diff --git a/wd_aead.c b/wd_aead.c index a2b4622..cd1a82b 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -903,7 +903,7 @@ int wd_aead_env_init(struct wd_sched *sched)
void wd_aead_env_uninit(void) { - return wd_alg_env_uninit(&wd_aead_env_config, &wd_aead_ops); + wd_alg_env_uninit(&wd_aead_env_config, &wd_aead_ops); }
int wd_aead_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) @@ -921,7 +921,7 @@ int wd_aead_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_aead_ctx_num_uninit(void) { - return wd_alg_env_uninit(&wd_aead_env_config, &wd_aead_ops); + wd_alg_env_uninit(&wd_aead_env_config, &wd_aead_ops); }
int wd_aead_get_env_param(__u32 node, __u32 type, __u32 mode, diff --git a/wd_cipher.c b/wd_cipher.c index 12c70fb..6a1662a 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -782,7 +782,7 @@ int wd_cipher_env_init(struct wd_sched *sched)
void wd_cipher_env_uninit(void) { - return wd_alg_env_uninit(&wd_cipher_env_config, &wd_cipher_ops); + wd_alg_env_uninit(&wd_cipher_env_config, &wd_cipher_ops); }
int wd_cipher_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) @@ -800,7 +800,7 @@ int wd_cipher_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_cipher_ctx_num_uninit(void) { - return wd_alg_env_uninit(&wd_cipher_env_config, &wd_cipher_ops); + wd_alg_env_uninit(&wd_cipher_env_config, &wd_cipher_ops); }
int wd_cipher_get_env_param(__u32 node, __u32 type, __u32 mode, diff --git a/wd_comp.c b/wd_comp.c index ae140ad..4a22a80 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -883,7 +883,7 @@ int wd_comp_env_init(struct wd_sched *sched)
void wd_comp_env_uninit(void) { - return wd_alg_env_uninit(&wd_comp_env_config, &wd_comp_ops); + wd_alg_env_uninit(&wd_comp_env_config, &wd_comp_ops); }
int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) @@ -906,7 +906,7 @@ int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_comp_ctx_num_uninit(void) { - return wd_alg_env_uninit(&wd_comp_env_config, &wd_comp_ops); + wd_alg_env_uninit(&wd_comp_env_config, &wd_comp_ops); }
int wd_comp_get_env_param(__u32 node, __u32 type, __u32 mode, diff --git a/wd_dh.c b/wd_dh.c index 080ba52..4b6a75d 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -645,7 +645,7 @@ int wd_dh_env_init(struct wd_sched *sched)
void wd_dh_env_uninit(void) { - return wd_alg_env_uninit(&wd_dh_env_config, &wd_dh_ops); + wd_alg_env_uninit(&wd_dh_env_config, &wd_dh_ops); }
int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) @@ -663,7 +663,7 @@ int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_dh_ctx_num_uninit(void) { - return wd_alg_env_uninit(&wd_dh_env_config, &wd_dh_ops); + wd_alg_env_uninit(&wd_dh_env_config, &wd_dh_ops); }
int wd_dh_get_env_param(__u32 node, __u32 type, __u32 mode, diff --git a/wd_digest.c b/wd_digest.c index 92e7fb2..c3aface 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -776,7 +776,7 @@ int wd_digest_env_init(struct wd_sched *sched)
void wd_digest_env_uninit(void) { - return wd_alg_env_uninit(&wd_digest_env_config, &wd_digest_ops); + wd_alg_env_uninit(&wd_digest_env_config, &wd_digest_ops); }
int wd_digest_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) @@ -794,7 +794,7 @@ int wd_digest_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_digest_ctx_num_uninit(void) { - return wd_alg_env_uninit(&wd_digest_env_config, &wd_digest_ops); + wd_alg_env_uninit(&wd_digest_env_config, &wd_digest_ops); }
int wd_digest_get_env_param(__u32 node, __u32 type, __u32 mode, diff --git a/wd_ecc.c b/wd_ecc.c index 7f142e2..3ddf2c0 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -1592,7 +1592,7 @@ static void get_sign_out_params(struct wd_ecc_out *out, void wd_sm2_get_sign_out_params(struct wd_ecc_out *out, struct wd_dtb **r, struct wd_dtb **s) { - return get_sign_out_params(out, r, s); + get_sign_out_params(out, r, s); }
static int set_sign_in_param(struct wd_ecc_sign_in *sin, @@ -2195,7 +2195,7 @@ struct wd_ecc_out *wd_ecdsa_new_sign_out(handle_t sess) void wd_ecdsa_get_sign_out_params(struct wd_ecc_out *out, struct wd_dtb **r, struct wd_dtb **s) { - return get_sign_out_params(out, r, s); + get_sign_out_params(out, r, s); }
struct wd_ecc_in *wd_ecdsa_new_verf_in(handle_t sess, @@ -2358,7 +2358,7 @@ int wd_ecc_env_init(struct wd_sched *sched)
void wd_ecc_env_uninit(void) { - return wd_alg_env_uninit(&wd_ecc_env_config, &wd_ecc_ops); + wd_alg_env_uninit(&wd_ecc_env_config, &wd_ecc_ops); }
int wd_ecc_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) @@ -2376,7 +2376,7 @@ int wd_ecc_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_ecc_ctx_num_uninit(void) { - return wd_alg_env_uninit(&wd_ecc_env_config, &wd_ecc_ops); + wd_alg_env_uninit(&wd_ecc_env_config, &wd_ecc_ops); }
int wd_ecc_get_env_param(__u32 node, __u32 type, __u32 mode, diff --git a/wd_rsa.c b/wd_rsa.c index ac2106e..9e8c264 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -1247,7 +1247,7 @@ int wd_rsa_env_init(struct wd_sched *sched)
void wd_rsa_env_uninit(void) { - return wd_alg_env_uninit(&wd_rsa_env_config, &wd_rsa_ops); + wd_alg_env_uninit(&wd_rsa_env_config, &wd_rsa_ops); }
int wd_rsa_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode) @@ -1265,7 +1265,7 @@ int wd_rsa_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
void wd_rsa_ctx_num_uninit(void) { - return wd_alg_env_uninit(&wd_rsa_env_config, &wd_rsa_ops); + wd_alg_env_uninit(&wd_rsa_env_config, &wd_rsa_ops); }
int wd_rsa_get_env_param(__u32 node, __u32 type, __u32 mode,
Array name should be used instead of taking address of array.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/hisi_hpre.c | 2 +- wd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 4d21788..83b2a7d 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -1777,7 +1777,7 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg) goto fail_fill_sqe; }
- ret = hisi_qm_send(h_qp, &hw_msg, SM2_SQE_NUM, &send_cnt); + ret = hisi_qm_send(h_qp, hw_msg, SM2_SQE_NUM, &send_cnt); if (unlikely(ret)) goto fail_fill_sqe;
diff --git a/wd.c b/wd.c index c2559a4..401dd9d 100644 --- a/wd.c +++ b/wd.c @@ -351,7 +351,7 @@ out:
static void wd_ctx_init_qfrs_offs(struct wd_ctx_h *ctx) { - memcpy(&ctx->qfrs_offs, &ctx->dev->qfrs_offs, + memcpy(ctx->qfrs_offs, ctx->dev->qfrs_offs, sizeof(ctx->qfrs_offs)); }
Truncation may occur before type conversion, use force cast to eliminate errors.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/drv/hisi_hpre_udrv.c | 18 +++++++++--------- v1/wd_rsa.c | 12 ++++++------ wd_mempool.c | 2 +- wd_rsa.c | 12 ++++++------ 4 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c index 7ce8f47..9496737 100644 --- a/v1/drv/hisi_hpre_udrv.c +++ b/v1/drv/hisi_hpre_udrv.c @@ -286,7 +286,7 @@ static int qm_rsa_out_transfer(struct wcrypto_rsa_msg *msg, msg->result = WD_SUCCESS; if (hw_msg->alg == HPRE_ALG_KG_CRT) { msg->out_bytes = CRT_GEN_PARAMS_SZ(kbytes); - *in_len = GEN_PARAMS_SZ(kbytes); + *in_len = (size_t)GEN_PARAMS_SZ(kbytes); *out_len = msg->out_bytes; wcrypto_get_rsa_kg_out_crt_params(key, &qinv, &dq, &dp); ret = qm_tri_bin_transfer(&qinv, &dq, &dp, "rsa kg qinv&dp&dq"); @@ -298,7 +298,7 @@ static int qm_rsa_out_transfer(struct wcrypto_rsa_msg *msg, } else if (hw_msg->alg == HPRE_ALG_KG_STD) { msg->out_bytes = GEN_PARAMS_SZ(kbytes); *out_len = msg->out_bytes; - *in_len = GEN_PARAMS_SZ(kbytes); + *in_len = (size_t)GEN_PARAMS_SZ(kbytes);
wcrypto_get_rsa_kg_out_params(key, &d, &n); ret = qm_tri_bin_transfer(&d, &n, NULL, "rsa kg d & n"); @@ -535,11 +535,11 @@ int qm_parse_rsa_sqe(void *msg, const struct qm_queue_info *info, }
if (hw_msg->alg == HPRE_ALG_KG_CRT) { - olen = CRT_GEN_PARAMS_SZ(kbytes); - ilen = GEN_PARAMS_SZ(kbytes); + olen = (size_t)CRT_GEN_PARAMS_SZ(kbytes); + ilen = (size_t)GEN_PARAMS_SZ(kbytes); } else if (hw_msg->alg == HPRE_ALG_KG_STD) { - olen = GEN_PARAMS_SZ(kbytes); - ilen = GEN_PARAMS_SZ(kbytes); + olen = (size_t)GEN_PARAMS_SZ(kbytes); + ilen = (size_t)GEN_PARAMS_SZ(kbytes); } else { olen = kbytes; ilen = kbytes; @@ -598,7 +598,7 @@ static void dh_xp_unmap(struct wcrypto_dh_msg *msg, struct wd_queue *q, { uintptr_t phy = DMA_ADDR(hw_msg->low_key, hw_msg->hi_key);
- drv_iova_unmap(q, msg->x_p, (void *)phy, GEN_PARAMS_SZ(msg->key_bytes)); + drv_iova_unmap(q, msg->x_p, (void *)phy, (size_t)GEN_PARAMS_SZ(msg->key_bytes)); }
static int qm_fill_dh_xp_params(struct wd_queue *q, struct wcrypto_dh_msg *msg, @@ -621,7 +621,7 @@ static int qm_fill_dh_xp_params(struct wd_queue *q, struct wcrypto_dh_msg *msg, return ret;
phy = (uintptr_t)drv_iova_map(q, (void *)x, - GEN_PARAMS_SZ(msg->key_bytes)); + (size_t)GEN_PARAMS_SZ(msg->key_bytes)); if (unlikely(!phy)) { WD_ERR("get dh xp parameter dma address fail!\n"); return -WD_ENOMEM; @@ -760,7 +760,7 @@ int qm_parse_dh_sqe(void *msg, const struct qm_queue_info *info, drv_iova_unmap(q, dh_msg->out, (void *)(uintptr_t)dma_out, dh_msg->key_bytes); drv_iova_unmap(q, NULL, (void *)(uintptr_t)dma_in, - GEN_PARAMS_SZ(dh_msg->key_bytes)); + (size_t)GEN_PARAMS_SZ(dh_msg->key_bytes)); drv_iova_unmap(q, NULL, (void *)(uintptr_t)dma_key, dh_msg->key_bytes); return 1; } diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c index c5c109d..702f6be 100644 --- a/v1/wd_rsa.c +++ b/v1/wd_rsa.c @@ -178,7 +178,7 @@ static int kg_in_param_check(void *ctx, struct wd_dtb *e, return -WD_EINVAL; }
- kg_in_size = GEN_PARAMS_SZ(c->key_size); + kg_in_size = (int)GEN_PARAMS_SZ(c->key_size); if (unlikely(br->get_bufsize && br->get_bufsize(br->usr) < (kg_in_size + sizeof(*kg_in)))) { WD_ERR("Blk_size < need_size<0x%lx>.\n", (kg_in_size + sizeof(*kg_in))); @@ -202,7 +202,7 @@ struct wcrypto_rsa_kg_in *wcrypto_new_kg_in(void *ctx, struct wd_dtb *e, return NULL;
br = &c->setup.br; - kg_in_size = GEN_PARAMS_SZ(c->key_size); + kg_in_size = (int)GEN_PARAMS_SZ(c->key_size); kg_in = br->alloc(br->usr, kg_in_size + sizeof(*kg_in)); if (unlikely(!kg_in)) { WD_ERR("ctx br->alloc kg_in memory fail!\n"); @@ -285,7 +285,7 @@ struct wcrypto_rsa_kg_out *wcrypto_new_kg_out(void *ctx) if (c->setup.is_crt) kg_out_size = CRT_GEN_PARAMS_SZ(c->key_size); else - kg_out_size = GEN_PARAMS_SZ(c->key_size); + kg_out_size = (int)GEN_PARAMS_SZ(c->key_size);
br = &c->setup.br; if (unlikely(!br->alloc)) { @@ -434,7 +434,7 @@ static int create_ctx_key(struct wcrypto_rsa_ctx_setup *setup,
if (setup->is_crt) { len = sizeof(struct wcrypto_rsa_prikey) + - CRT_PARAMS_SZ(ctx->key_size); + (__u32)CRT_PARAMS_SZ(ctx->key_size); if (br->get_bufsize && br->get_bufsize(br->usr) < len) { WD_ERR("Blk_size < need_size<0x%x>.\n", len); return -WD_ENOMEM; @@ -449,7 +449,7 @@ static int create_ctx_key(struct wcrypto_rsa_ctx_setup *setup, init_pkey2(pkey2, ctx->key_size); } else { len = sizeof(struct wcrypto_rsa_prikey) + - GEN_PARAMS_SZ(ctx->key_size); + (__u32)GEN_PARAMS_SZ(ctx->key_size); if (br->get_bufsize && br->get_bufsize(br->usr) < len) { WD_ERR("Blk_size < need_size<0x%x>.\n", len); return -WD_ENOMEM; @@ -464,7 +464,7 @@ static int create_ctx_key(struct wcrypto_rsa_ctx_setup *setup, init_pkey1(pkey1, ctx->key_size); }
- len = sizeof(struct wcrypto_rsa_pubkey) + GEN_PARAMS_SZ(ctx->key_size); + len = sizeof(struct wcrypto_rsa_pubkey) + (__u32)GEN_PARAMS_SZ(ctx->key_size); if (br->get_bufsize && br->get_bufsize(br->usr) < len) { br->free(br->usr, ctx->prikey); WD_ERR("Blk_size < need_size<0x%x>.\n", len); diff --git a/wd_mempool.c b/wd_mempool.c index db88fb0..1bdc0f4 100644 --- a/wd_mempool.c +++ b/wd_mempool.c @@ -795,7 +795,7 @@ static int mbind_memory(void *addr, size_t size, int node) unsigned long node_mask; int ret = 0;
- node_mask = 1U << (unsigned int)node; + node_mask = (unsigned long)(1 << (unsigned int)node); ret = mbind(addr, size, MPOL_BIND, &node_mask, max_node, 0); if (ret < 0) { WD_ERR("failed to mbind memory, ret is %d!\n", ret); diff --git a/wd_rsa.c b/wd_rsa.c index 9e8c264..7e71a17 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -607,7 +607,7 @@ struct wd_rsa_kg_in *wd_rsa_new_kg_in(handle_t sess, struct wd_dtb *e, return NULL; }
- kg_in_size = GEN_PARAMS_SZ(c->key_size); + kg_in_size = (int)GEN_PARAMS_SZ(c->key_size); kg_in = malloc(kg_in_size + sizeof(*kg_in)); if (!kg_in) { WD_ERR("failed to malloc kg_in memory!\n"); @@ -682,9 +682,9 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess) }
if (c->setup.is_crt) - kg_out_size = CRT_GEN_PARAMS_SZ(c->key_size); + kg_out_size = (int)CRT_GEN_PARAMS_SZ(c->key_size); else - kg_out_size = GEN_PARAMS_SZ(c->key_size); + kg_out_size = (int)GEN_PARAMS_SZ(c->key_size);
kg_out = malloc(kg_out_size + sizeof(*kg_out)); if (!kg_out) { @@ -828,7 +828,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
if (setup->is_crt) { len = sizeof(struct wd_rsa_prikey) + - CRT_PARAMS_SZ(sess->key_size); + (int)CRT_PARAMS_SZ(sess->key_size); sess->prikey = malloc(len); if (!sess->prikey) { WD_ERR("failed to alloc sess prikey2!\n"); @@ -839,7 +839,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup, init_pkey2(pkey2, sess->key_size); } else { len = sizeof(struct wd_rsa_prikey) + - GEN_PARAMS_SZ(sess->key_size); + (int)GEN_PARAMS_SZ(sess->key_size); sess->prikey = malloc(len); if (!sess->prikey) { WD_ERR("failed to alloc sess prikey1!\n"); @@ -851,7 +851,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup, }
len = sizeof(struct wd_rsa_pubkey) + - GEN_PARAMS_SZ(sess->key_size); + (int)GEN_PARAMS_SZ(sess->key_size); sess->pubkey = malloc(len); if (!sess->pubkey) { free(sess->prikey);
Possible access beyond array for function memcpy, need to add size check before memcpy.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_ecc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/wd_ecc.c b/wd_ecc.c index 3ddf2c0..2dc8557 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -1698,8 +1698,7 @@ static int sm2_compute_digest(struct wd_ecc_sess *sess, struct wd_dtb *hash_msg, { struct wd_hash_mt *hash = &sess->setup.hash; __u8 za[SM2_KEY_SIZE] = {0}; - __u32 za_len = SM2_KEY_SIZE; - __u32 hash_bytes; + __u32 za_len, hash_bytes; __u64 in_len = 0; char *p_in; __u64 lens; @@ -1712,7 +1711,7 @@ static int sm2_compute_digest(struct wd_ecc_sess *sess, struct wd_dtb *hash_msg, }
ret = sm2_compute_za_hash(za, &za_len, id, sess); - if (unlikely(ret)) { + if (unlikely(ret || za_len > SM2_KEY_SIZE)) { WD_ERR("failed to compute za, ret = %d!\n", ret); return ret; }
Possible truncation before conversion from 'int' to 'size_t' (aka 'unsigned long'), fix it.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/drv/hisi_hpre_udrv.c | 18 +++++++++--------- v1/wd_util.h | 1 + wd_mempool.c | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c index 9496737..3acbbde 100644 --- a/v1/drv/hisi_hpre_udrv.c +++ b/v1/drv/hisi_hpre_udrv.c @@ -286,7 +286,7 @@ static int qm_rsa_out_transfer(struct wcrypto_rsa_msg *msg, msg->result = WD_SUCCESS; if (hw_msg->alg == HPRE_ALG_KG_CRT) { msg->out_bytes = CRT_GEN_PARAMS_SZ(kbytes); - *in_len = (size_t)GEN_PARAMS_SZ(kbytes); + *in_len = GEN_PARAMS_SZ_UL(kbytes); *out_len = msg->out_bytes; wcrypto_get_rsa_kg_out_crt_params(key, &qinv, &dq, &dp); ret = qm_tri_bin_transfer(&qinv, &dq, &dp, "rsa kg qinv&dp&dq"); @@ -298,7 +298,7 @@ static int qm_rsa_out_transfer(struct wcrypto_rsa_msg *msg, } else if (hw_msg->alg == HPRE_ALG_KG_STD) { msg->out_bytes = GEN_PARAMS_SZ(kbytes); *out_len = msg->out_bytes; - *in_len = (size_t)GEN_PARAMS_SZ(kbytes); + *in_len = GEN_PARAMS_SZ_UL(kbytes);
wcrypto_get_rsa_kg_out_params(key, &d, &n); ret = qm_tri_bin_transfer(&d, &n, NULL, "rsa kg d & n"); @@ -535,11 +535,11 @@ int qm_parse_rsa_sqe(void *msg, const struct qm_queue_info *info, }
if (hw_msg->alg == HPRE_ALG_KG_CRT) { - olen = (size_t)CRT_GEN_PARAMS_SZ(kbytes); - ilen = (size_t)GEN_PARAMS_SZ(kbytes); + olen = CRT_GEN_PARAMS_SZ(kbytes); + ilen = GEN_PARAMS_SZ_UL(kbytes); } else if (hw_msg->alg == HPRE_ALG_KG_STD) { - olen = (size_t)GEN_PARAMS_SZ(kbytes); - ilen = (size_t)GEN_PARAMS_SZ(kbytes); + olen = GEN_PARAMS_SZ_UL(kbytes); + ilen = GEN_PARAMS_SZ_UL(kbytes); } else { olen = kbytes; ilen = kbytes; @@ -598,7 +598,7 @@ static void dh_xp_unmap(struct wcrypto_dh_msg *msg, struct wd_queue *q, { uintptr_t phy = DMA_ADDR(hw_msg->low_key, hw_msg->hi_key);
- drv_iova_unmap(q, msg->x_p, (void *)phy, (size_t)GEN_PARAMS_SZ(msg->key_bytes)); + drv_iova_unmap(q, msg->x_p, (void *)phy, GEN_PARAMS_SZ_UL(msg->key_bytes)); }
static int qm_fill_dh_xp_params(struct wd_queue *q, struct wcrypto_dh_msg *msg, @@ -621,7 +621,7 @@ static int qm_fill_dh_xp_params(struct wd_queue *q, struct wcrypto_dh_msg *msg, return ret;
phy = (uintptr_t)drv_iova_map(q, (void *)x, - (size_t)GEN_PARAMS_SZ(msg->key_bytes)); + GEN_PARAMS_SZ_UL(msg->key_bytes)); if (unlikely(!phy)) { WD_ERR("get dh xp parameter dma address fail!\n"); return -WD_ENOMEM; @@ -760,7 +760,7 @@ int qm_parse_dh_sqe(void *msg, const struct qm_queue_info *info, drv_iova_unmap(q, dh_msg->out, (void *)(uintptr_t)dma_out, dh_msg->key_bytes); drv_iova_unmap(q, NULL, (void *)(uintptr_t)dma_in, - (size_t)GEN_PARAMS_SZ(dh_msg->key_bytes)); + GEN_PARAMS_SZ_UL(dh_msg->key_bytes)); drv_iova_unmap(q, NULL, (void *)(uintptr_t)dma_key, dh_msg->key_bytes); return 1; } diff --git a/v1/wd_util.h b/v1/wd_util.h index 228493c..fc4586c 100644 --- a/v1/wd_util.h +++ b/v1/wd_util.h @@ -45,6 +45,7 @@ #define CRT_PARAMS_SZ(key_size) ((5 * (key_size)) >> 1) #define CRT_GEN_PARAMS_SZ(key_size) ((7 * (key_size)) >> 1) #define GEN_PARAMS_SZ(key_size) ((key_size) << 1) +#define GEN_PARAMS_SZ_UL(key_size) ((unsigned long)(key_size) << 1) #define CRT_PARAM_SZ(key_size) ((key_size) >> 1) #define GET_NEGATIVE(val) (0 - (val)) #define XTS_MODE_KEY_SHIFT 1 diff --git a/wd_mempool.c b/wd_mempool.c index 1bdc0f4..8d3ca90 100644 --- a/wd_mempool.c +++ b/wd_mempool.c @@ -795,7 +795,7 @@ static int mbind_memory(void *addr, size_t size, int node) unsigned long node_mask; int ret = 0;
- node_mask = (unsigned long)(1 << (unsigned int)node); + node_mask = 1UL << (unsigned int)node; ret = mbind(addr, size, MPOL_BIND, &node_mask, max_node, 0); if (ret < 0) { WD_ERR("failed to mbind memory, ret is %d!\n", ret);
format '%hhu' specifies type 'unsigned char' which is inconsistent with argument no. 3 of underlying type 'unsigned int'
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/wd_ecc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c index f5c76a8..8048443 100644 --- a/v1/wd_ecc.c +++ b/v1/wd_ecc.c @@ -1660,7 +1660,7 @@ int wcrypto_do_ecxdh(void *ctx, struct wcrypto_ecc_op_data *opdata, void *tag)
if (unlikely(opdata->op_type != WCRYPTO_ECXDH_GEN_KEY && opdata->op_type != WCRYPTO_ECXDH_COMPUTE_KEY)) { - WD_ERR("do ecxdh: op_type = %hhu error!\n", opdata->op_type); + WD_ERR("do ecxdh: op_type = %d error!\n", opdata->op_type); return -WD_EINVAL; }
@@ -2173,7 +2173,7 @@ int wcrypto_do_ecdsa(void *ctx, struct wcrypto_ecc_op_data *opdata, void *tag)
if (unlikely(opdata->op_type != WCRYPTO_ECDSA_SIGN && opdata->op_type != WCRYPTO_ECDSA_VERIFY)) { - WD_ERR("do ecdsa: op_type = %hhu error!\n", opdata->op_type); + WD_ERR("do ecdsa: op_type = %d error!\n", opdata->op_type); return -WD_EINVAL; }
@@ -2463,7 +2463,7 @@ int wcrypto_do_sm2(void *ctx, struct wcrypto_ecc_op_data *opdata, void *tag) opdata->op_type != WCRYPTO_SM2_KG && opdata->op_type != WCRYPTO_SM2_ENCRYPT && opdata->op_type != WCRYPTO_SM2_DECRYPT)) { - WD_ERR("do sm2: op_type = %hhu error!\n", opdata->op_type); + WD_ERR("do sm2: op_type = %d error!\n", opdata->op_type); return -WD_EINVAL; }
If the initialization is repeated, exist error code is returned and the original init check is deleted.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- include/wd_alg_common.h | 1 - wd_aead.c | 4 ++-- wd_cipher.c | 4 ++-- wd_comp.c | 4 ++-- wd_dh.c | 4 ++-- wd_digest.c | 4 ++-- wd_ecc.c | 4 ++-- wd_rsa.c | 4 ++-- wd_util.c | 12 +++--------- 9 files changed, 17 insertions(+), 24 deletions(-)
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h index 31208ad..5d8e863 100644 --- a/include/wd_alg_common.h +++ b/include/wd_alg_common.h @@ -107,7 +107,6 @@ struct wd_ctx_config_internal { __u32 ctx_num; struct wd_ctx_internal *ctxs; void *priv; - int pid; bool epoll_en; unsigned long *msg_cnt; }; diff --git a/wd_aead.c b/wd_aead.c index cd1a82b..a14234a 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -469,7 +469,7 @@ int wd_aead_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_aead_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -540,7 +540,7 @@ int wd_aead_init2_(char *alg, __u32 sched_type, int task_type,
flag = wd_alg_try_init(&wd_aead_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type >= SCHED_POLICY_BUTT || task_type < 0 || task_type >= TASK_MAX_TYPE) { diff --git a/wd_cipher.c b/wd_cipher.c index 6a1662a..a8ebeea 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -347,7 +347,7 @@ int wd_cipher_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_cipher_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -391,7 +391,7 @@ int wd_cipher_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_p
flag = wd_alg_try_init(&wd_cipher_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { diff --git a/wd_comp.c b/wd_comp.c index 4a22a80..2239e33 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -169,7 +169,7 @@ int wd_comp_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_comp_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -213,7 +213,7 @@ int wd_comp_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_par
flag = wd_alg_try_init(&wd_comp_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { diff --git a/wd_dh.c b/wd_dh.c index 4b6a75d..7feb7ee 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -161,7 +161,7 @@ int wd_dh_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_dh_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -204,7 +204,7 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param
flag = wd_alg_try_init(&wd_dh_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); diff --git a/wd_digest.c b/wd_digest.c index c3aface..df9f656 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -282,7 +282,7 @@ int wd_digest_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_digest_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -349,7 +349,7 @@ int wd_digest_init2_(char *alg, __u32 sched_type, int task_type,
flag = wd_alg_try_init(&wd_digest_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type >= SCHED_POLICY_BUTT || task_type < 0 || task_type >= TASK_MAX_TYPE) { diff --git a/wd_ecc.c b/wd_ecc.c index 2dc8557..da717a8 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -217,7 +217,7 @@ int wd_ecc_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_ecc_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -260,7 +260,7 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
flag = wd_alg_try_init(&wd_ecc_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); diff --git a/wd_rsa.c b/wd_rsa.c index 7e71a17..60c2836 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -202,7 +202,7 @@ int wd_rsa_init(struct wd_ctx_config *config, struct wd_sched *sched)
flag = wd_alg_try_init(&wd_rsa_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
ret = wd_init_param_check(config, sched); if (ret) @@ -245,7 +245,7 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para
flag = wd_alg_try_init(&wd_rsa_setting.status); if (!flag) - return 0; + return -WD_EEXIST;
if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); diff --git a/wd_util.c b/wd_util.c index db42fa3..465d958 100644 --- a/wd_util.c +++ b/wd_util.c @@ -229,12 +229,6 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in, return -WD_EINVAL; }
- /* ctx could only be invoked once for one process. */ - if (in->ctx_num && in->pid == getpid()) { - WD_ERR("ctx have initialized.\n"); - return -WD_EEXIST; - } - in->msg_cnt = wd_shared_create(WD_CTX_CNT_NUM); if (!in->msg_cnt && need_info) return -WD_EINVAL; @@ -262,7 +256,6 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in, }
in->ctxs = ctxs; - in->pid = getpid(); in->priv = cfg->priv; in->ctx_num = cfg->ctx_num;
@@ -316,7 +309,6 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in)
in->priv = NULL; in->ctx_num = 0; - in->pid = 0; if (in->ctxs) { free(in->ctxs); in->ctxs = NULL; @@ -2326,8 +2318,10 @@ bool wd_alg_try_init(enum wd_status *status) expected = WD_UNINIT; ret = __atomic_compare_exchange_n(status, &expected, WD_INITING, true, __ATOMIC_RELAXED, __ATOMIC_RELAXED); - if (expected == WD_INIT) + if (expected == WD_INIT) { + WD_ERR("The algorithm has been initialized!\n"); return false; + } usleep(WD_INIT_SLEEP_UTIME); if (!(++count % WD_INIT_RETRY_TIMES)) WD_ERR("The algorithm initizalite has been waiting for %ds!\n",
Numa node from environment variable should be checked, otherwise, the number of ctx will be set as valid nodes.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd.c | 3 +++ wd_util.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/wd.c b/wd.c index 401dd9d..ba73fd1 100644 --- a/wd.c +++ b/wd.c @@ -760,6 +760,9 @@ struct uacce_dev *wd_find_dev_by_numa(struct uacce_dev_list *list, int numa_id) p = p->next; }
+ if (dev == WD_ERR_PTR(-WD_ENODEV)) + WD_ERR("no available device was found in numa %d!\n", numa_id); + return dev; }
diff --git a/wd_util.c b/wd_util.c index 465d958..6e70549 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2001,11 +2001,12 @@ static void add_lib_to_list(struct drv_lib_list *head, tmp->next = node; }
-static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, const char *section, - __u32 op_type_num, int is_comp) +static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, struct uacce_dev_list *list, + const char *section, __u32 op_type_num, int is_comp) { struct wd_ctx_nums *ctxs = ctx_params->ctx_set_num; int i, j, ctx_num, node, ret; + struct uacce_dev *dev; char *ctx_section; const char *type;
@@ -2023,6 +2024,10 @@ static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, const char *section if (!ctx_num) return 0;
+ dev = wd_find_dev_by_numa(list, node); + if (WD_IS_ERR(dev)) + return -WD_ENODEV; + for (i = 0; i < CTX_MODE_MAX; i++) { for (j = 0; j < op_type_num; j++) { type = is_comp ? comp_ctx_type[i][j] : ctx_type[i][0]; @@ -2044,10 +2049,12 @@ static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, const char *section return -WD_EINVAL; }
-static int wd_env_set_ctx_nums(const char *name, const char *var_s, +static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const char *var_s, struct wd_ctx_params *ctx_params, __u32 op_type_num) { + char alg_type[CRYPTO_MAX_ALG_NAME]; char *left, *section, *start; + struct uacce_dev_list *list; int is_comp; int ret = 0;
@@ -2060,14 +2067,22 @@ static int wd_env_set_ctx_nums(const char *name, const char *var_s, if (!start) return -WD_ENOMEM;
+ wd_get_alg_type(alg_name, alg_type); + list = wd_get_accel_list(alg_type); + if (!list) { + WD_ERR("failed to get devices!\n"); + free(start); + return -WD_ENODEV; + } + left = start; while ((section = strsep(&left, ","))) { - ret = wd_set_ctx_nums(ctx_params, section, op_type_num, is_comp); + ret = wd_set_ctx_nums(ctx_params, list, section, op_type_num, is_comp); if (ret < 0) - goto out_free_str; + break; }
-out_free_str: + wd_free_list_accels(list); free(start); return ret; } @@ -2095,11 +2110,12 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, var_s = secure_getenv(env_name); if (var_s && strlen(var_s)) { /* environment variable has the highest priority */ - ret = wd_env_set_ctx_nums(env_name, var_s, ctx_params, max_op_type); + ret = wd_env_set_ctx_nums(driver->alg_name, env_name, var_s, + ctx_params, max_op_type); if (ret) { WD_ERR("fail to init ctx nums from %s!\n", env_name); numa_free_nodemask(ctx_params->bmp); - return -WD_EINVAL; + return ret; } } else { /* environment variable is not set, try to use user_ctx_params first */ @@ -2593,7 +2609,7 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) __u32 sched_type = attrs->sched_type; struct wd_ctx_config *ctx_config = NULL; struct wd_sched *alg_sched = NULL; - char alg_type[WD_NAME_SIZE]; + char alg_type[CRYPTO_MAX_ALG_NAME]; char *alg = attrs->alg; int driver_type = UADK_ALG_HW; int ret;
rsyslog.conf size should be checked before malloc for file content.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/wd.c b/wd.c index ba73fd1..bb85d2e 100644 --- a/wd.c +++ b/wd.c @@ -21,6 +21,7 @@ #include "wd.h" #include "wd_alg.h" #define SYS_CLASS_DIR "/sys/class/uacce" +#define FILE_MAX_SIZE (8 << 20)
enum UADK_LOG_LEVEL { WD_LOG_NONE = 0, @@ -67,6 +68,11 @@ static void wd_parse_log_level(void) goto close_file; }
+ if (file_info.st_size > FILE_MAX_SIZE) { + WD_ERR("failed to check rsyslog.conf size.\n"); + goto close_file; + } + file_contents = malloc(file_info.st_size); if (!file_contents) { WD_ERR("failed to get file contents memory.\n");
In the multi-process scenario, queue id of each process starts from 0. As a result, statistics are collected on the same queue, and the real queue ID needs to be used. In the asynchronous scenario, the number of packets that are sent busy is counted. As a result, the number of packets that are sent is greater than the actual number.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/hisi_comp.c | 1 + drv/hisi_hpre.c | 1 + drv/hisi_qm_udrv.c | 1 + drv/hisi_sec.c | 1 + include/hisi_qm_udrv.h | 1 + include/wd_alg_common.h | 1 + include/wd_util.h | 9 ++++++--- wd_aead.c | 4 ++-- wd_cipher.c | 4 ++-- wd_comp.c | 4 ++-- wd_dh.c | 4 ++-- wd_digest.c | 4 ++-- wd_ecc.c | 4 ++-- wd_rsa.c | 4 ++-- 14 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index 01e2ad8..18d0163 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -799,6 +799,7 @@ static int hisi_zip_init(void *conf, void *priv) h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx); if (unlikely(!h_qp)) goto out; + config->ctxs[i].sqn = qm_priv.sqn; }
hisi_zip_sqe_ops_adapt(h_qp); diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 83b2a7d..62a2cb6 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -484,6 +484,7 @@ static int hpre_init_qm_priv(struct wd_ctx_config_internal *config, WD_ERR("failed to alloc qp!\n"); goto out; } + config->ctxs[i].sqn = qm_priv->sqn; }
return 0; diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c index a3b5dc1..8210bf4 100644 --- a/drv/hisi_qm_udrv.c +++ b/drv/hisi_qm_udrv.c @@ -265,6 +265,7 @@ static int his_qm_set_qp_ctx(handle_t h_ctx, struct hisi_qm_priv *config, return ret; } q_info->sqn = qp_ctx.id; + config->sqn = qp_ctx.id;
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_QM_SET_QP_INFO, &qp_cfg); if (ret < 0) { diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 0cba9ad..bcedfa6 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -3043,6 +3043,7 @@ int hisi_sec_init(void *conf, void *priv) h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx); if (!h_qp) goto out; + config->ctxs[i].sqn = qm_priv.sqn; } memcpy(&sec_ctx->config, config, sizeof(struct wd_ctx_config_internal)); hisi_sec_driver_adapter((struct hisi_qp *)h_qp); diff --git a/include/hisi_qm_udrv.h b/include/hisi_qm_udrv.h index 32f8183..b94e8e2 100644 --- a/include/hisi_qm_udrv.h +++ b/include/hisi_qm_udrv.h @@ -49,6 +49,7 @@ struct hisi_qm_priv { __u8 qp_mode; __u16 sqe_size; __u16 op_type; + __u16 sqn; /* index of ctxs */ __u32 idx; bool epoll_en; diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h index 5d8e863..f69f00a 100644 --- a/include/wd_alg_common.h +++ b/include/wd_alg_common.h @@ -100,6 +100,7 @@ struct wd_ctx_internal { handle_t ctx; __u8 op_type; __u8 ctx_mode; + __u16 sqn; pthread_spinlock_t lock; };
diff --git a/include/wd_util.h b/include/wd_util.h index 163b18d..9ef2328 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -499,19 +499,22 @@ int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir);
/** * wd_dfx_msg_cnt() - Message counter interface for ctx - * @msg: Shared memory addr. + * @config: Ctx configuration in global setting. * @numSize: Number of elements. * @index: Indicates the CTX index. */ -static inline void wd_dfx_msg_cnt(unsigned long *msg, __u32 numsize, __u32 idx) +static inline void wd_dfx_msg_cnt(struct wd_ctx_config_internal *config, + __u32 numsize, __u32 idx) { + __u16 sqn; bool ret;
ret = wd_need_info(); if (idx > numsize || !ret) return;
- msg[idx]++; + sqn = config->ctxs[idx].sqn; + config->msg_cnt[sqn]++; }
#ifdef __cplusplus diff --git a/wd_aead.c b/wd_aead.c index a14234a..0967dda 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -739,7 +739,7 @@ int wd_do_aead_sync(handle_t h_sess, struct wd_aead_req *req) if (unlikely(ret)) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx; ret = send_recv_sync(ctx, &msg); req->state = msg.result; @@ -772,7 +772,6 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req) if (ret) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
msg_id = wd_get_msg_from_pool(&wd_aead_setting.pool, @@ -793,6 +792,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req) goto fail_with_msg; }
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ret = wd_add_task_to_async_queue(&wd_aead_env_config, idx); if (ret) goto fail_with_msg; diff --git a/wd_cipher.c b/wd_cipher.c index a8ebeea..1344119 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -619,7 +619,7 @@ int wd_do_cipher_sync(handle_t h_sess, struct wd_cipher_req *req) if (unlikely(ret)) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
ret = send_recv_sync(ctx, &msg); @@ -651,7 +651,6 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req) return ret;
ctx = config->ctxs + idx; - wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx);
msg_id = wd_get_msg_from_pool(&wd_cipher_setting.pool, idx, (void **)&msg); @@ -671,6 +670,7 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req) goto fail_with_msg; }
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ret = wd_add_task_to_async_queue(&wd_cipher_env_config, idx); if (ret) goto fail_with_msg; diff --git a/wd_comp.c b/wd_comp.c index 2239e33..f48938a 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -558,7 +558,7 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess, if (unlikely(ret)) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
msg_handle.send = wd_comp_setting.driver->send; @@ -809,7 +809,6 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) if (unlikely(ret)) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
tag = wd_get_msg_from_pool(&wd_comp_setting.pool, idx, (void **)&msg); @@ -827,6 +826,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req) goto fail_with_msg; }
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ret = wd_add_task_to_async_queue(&wd_comp_env_config, idx); if (unlikely(ret)) goto fail_with_msg; diff --git a/wd_dh.c b/wd_dh.c index 7feb7ee..6aebb8c 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -345,7 +345,7 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req) if (ret) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
memset(&msg, 0, sizeof(struct wd_dh_msg)); @@ -391,7 +391,6 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req) if (ret) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
mid = wd_get_msg_from_pool(&wd_dh_setting.pool, idx, (void **)&msg); @@ -411,6 +410,7 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req) goto fail_with_msg; }
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ret = wd_add_task_to_async_queue(&wd_dh_env_config, idx); if (ret) goto fail_with_msg; diff --git a/wd_digest.c b/wd_digest.c index df9f656..df2c286 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -609,7 +609,7 @@ int wd_do_digest_sync(handle_t h_sess, struct wd_digest_req *req) if (unlikely(ret)) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx; ret = send_recv_sync(ctx, dsess, &msg); req->state = msg.result; @@ -642,7 +642,6 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req) if (ret) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
msg_id = wd_get_msg_from_pool(&wd_digest_setting.pool, idx, @@ -663,6 +662,7 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req) goto fail_with_msg; }
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ret = wd_add_task_to_async_queue(&wd_digest_env_config, idx); if (ret) goto fail_with_msg; diff --git a/wd_ecc.c b/wd_ecc.c index da717a8..6c055c8 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -1548,7 +1548,7 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req) if (ret) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
memset(&msg, 0, sizeof(struct wd_ecc_msg)); @@ -2227,7 +2227,6 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req) if (ret) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
mid = wd_get_msg_from_pool(&wd_ecc_setting.pool, idx, (void **)&msg); @@ -2247,6 +2246,7 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req) goto fail_with_msg; }
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ret = wd_add_task_to_async_queue(&wd_ecc_env_config, idx); if (ret) goto fail_with_msg; diff --git a/wd_rsa.c b/wd_rsa.c index 60c2836..fff6067 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -407,7 +407,7 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req) if (ret) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); + wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
memset(&msg, 0, sizeof(struct wd_rsa_msg)); @@ -453,7 +453,6 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req) if (ret) return ret;
- wd_dfx_msg_cnt(config->msg_cnt, WD_CTX_CNT_NUM, idx); ctx = config->ctxs + idx;
mid = wd_get_msg_from_pool(&wd_rsa_setting.pool, idx, (void **)&msg); @@ -473,6 +472,7 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req) goto fail_with_msg; }
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx); ret = wd_add_task_to_async_queue(&wd_rsa_env_config, idx); if (ret) goto fail_with_msg;
Signed and unsigned MSB interpretations are different, and errors may occur when they are compared.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/hisi_comp.c | 8 ++--- drv/hisi_hpre.c | 16 +++++----- drv/hisi_qm_udrv.c | 7 +++-- drv/hisi_sec.c | 8 ++--- v1/drv/hisi_hpre_udrv.c | 4 +-- v1/drv/hisi_qm_udrv.c | 10 ++++--- v1/wd.c | 10 ++++--- v1/wd_adapter.c | 2 +- v1/wd_aead.c | 4 +-- v1/wd_bmm.c | 2 +- v1/wd_cipher.c | 2 +- v1/wd_dh.c | 3 +- v1/wd_digest.c | 4 +-- v1/wd_ecc.c | 8 ++--- v1/wd_rng.c | 4 +-- v1/wd_rsa.c | 5 ++-- v1/wd_util.c | 6 ++-- wd.c | 14 +++++---- wd_digest.c | 4 +-- wd_ecc.c | 4 +-- wd_mempool.c | 6 ++-- wd_util.c | 66 +++++++++++++++++++++-------------------- wd_zlibwrapper.c | 4 +-- 23 files changed, 107 insertions(+), 94 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index 18d0163..26df469 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -778,7 +778,7 @@ static int hisi_zip_init(void *conf, void *priv) struct hisi_qm_priv qm_priv; handle_t h_qp = 0; handle_t h_ctx; - int i; + __u32 i, j;
if (!config->ctx_num) { WD_ERR("invalid: zip init config ctx num is 0!\n"); @@ -806,8 +806,8 @@ static int hisi_zip_init(void *conf, void *priv)
return 0; out: - for (; i >= 0; i--) { - h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); + for (j = 0; j < i; j++) { + h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[j].ctx); hisi_qm_free_qp(h_qp); } return -WD_EINVAL; @@ -818,7 +818,7 @@ static void hisi_zip_exit(void *priv) struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv; struct wd_ctx_config_internal *config = &zip_ctx->config; handle_t h_qp; - int i; + __u32 i;
for (i = 0; i < config->ctx_num; i++) { h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 62a2cb6..7bf55a1 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -175,9 +175,9 @@ static int crypto_bin_to_hpre_bin(char *dst, const char *src, static int hpre_bin_to_crypto_bin(char *dst, const char *src, __u32 b_size, const char *p_name) { - int i, cnt; - int j = 0; - int k = 0; + __u32 i, cnt; + __u32 j = 0; + __u32 k = 0;
if (!dst || !src || !b_size) { WD_ERR("invalid: %s trans to crypto bin parameters err!\n", p_name); @@ -465,7 +465,7 @@ static int hpre_init_qm_priv(struct wd_ctx_config_internal *config, struct hisi_qm_priv *qm_priv) { handle_t h_ctx, h_qp; - int i, j; + __u32 i, j;
memcpy(&hpre_ctx->config, config, sizeof(*config));
@@ -542,7 +542,7 @@ static void hpre_exit(void *priv) struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv; struct wd_ctx_config_internal *config = &hpre_ctx->config; handle_t h_qp; - int i; + __u32 i;
for (i = 0; i < config->ctx_num; i++) { h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx); @@ -878,7 +878,7 @@ static int trans_d_to_hpre_bin(struct wd_dtb *d)
static bool big_than_one(const char *data, __u32 data_sz) { - int i; + __u32 i;
for (i = 0; i < data_sz - 1; i++) { if (data[i] > 0) @@ -1067,7 +1067,7 @@ static void ecc_get_io_len(__u32 atype, __u32 hsz, size_t *ilen,
static bool is_all_zero(struct wd_dtb *e) { - int i; + __u32 i;
if (!e || !e->data) { WD_ERR("invalid: e or e->data is NULL\n"); @@ -2095,7 +2095,7 @@ static int sm2_kdf(struct wd_dtb *out, struct wd_ecc_point *x2y2,
static void sm2_xor(struct wd_dtb *val1, struct wd_dtb *val2) { - int i; + __u32 i;
for (i = 0; i < val1->dsize; ++i) val1->data[i] = (char)((__u8)val1->data[i] ^ diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c index 8210bf4..acc2877 100644 --- a/drv/hisi_qm_udrv.c +++ b/drv/hisi_qm_udrv.c @@ -644,7 +644,7 @@ static struct hisi_sgl *hisi_qm_align_sgl(const void *sgl, __u32 sge_num)
static void hisi_qm_free_sglpool(struct hisi_sgl_pool *pool) { - int i; + __u32 i;
if (pool->sgl) { for (i = 0; i < pool->sgl_num; i++) @@ -662,7 +662,8 @@ static void hisi_qm_free_sglpool(struct hisi_sgl_pool *pool) handle_t hisi_qm_create_sglpool(__u32 sgl_num, __u32 sge_num) { struct hisi_sgl_pool *sgl_pool; - int i, ret; + int ret; + __u32 i;
if (!sgl_num || !sge_num || sge_num > HISI_SGE_NUM_IN_SGL) { WD_ERR("failed to create sgl_pool, sgl_num=%u, sge_num=%u!\n", @@ -827,7 +828,7 @@ void *hisi_qm_get_hw_sgl(handle_t sgl_pool, struct wd_datalist *sgl) struct hisi_sgl_pool *pool = (struct hisi_sgl_pool *)sgl_pool; struct wd_datalist *tmp = sgl; struct hisi_sgl *head, *next, *cur; - int i = 0; + __u32 i = 0;
if (!pool || !sgl) { WD_ERR("invalid: hw sgl pool or sgl is NULL!\n"); diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index bcedfa6..19d524a 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -2317,7 +2317,7 @@ static void get_galois_vector_s(struct wd_aead_msg *msg, __u8 *s) { unsigned int aad_len, cipher_len; __u8 a_c[GCM_BLOCK_SIZE] = {0}; - int i; + __u32 i;
aad_len = msg->assoc_bytes * BYTE_BITS; memcpy(&a_c[BYTE_BITS], &aad_len, sizeof(unsigned int)); @@ -3022,7 +3022,7 @@ int hisi_sec_init(void *conf, void *priv) struct hisi_qm_priv qm_priv; handle_t h_qp = 0; handle_t h_ctx; - int i, j; + __u32 i, j;
if (!config->ctx_num) { WD_ERR("invalid: sec init config ctx num is 0!\n"); @@ -3051,7 +3051,7 @@ int hisi_sec_init(void *conf, void *priv) return 0;
out: - for (j = i - 1; j >= 0; j--) { + for (j = 0; j < i; j++) { h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[j].ctx); hisi_qm_free_qp(h_qp); } @@ -3063,7 +3063,7 @@ void hisi_sec_exit(void *priv) struct hisi_sec_ctx *sec_ctx = priv; struct wd_ctx_config_internal *config; handle_t h_qp; - int i; + __u32 i;
if (!sec_ctx) { WD_ERR("hisi sec exit input parameter is err!\n"); diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c index 3acbbde..193ba56 100644 --- a/v1/drv/hisi_hpre_udrv.c +++ b/v1/drv/hisi_hpre_udrv.c @@ -1113,7 +1113,7 @@ static void correct_random(struct wd_dtb *k)
static bool is_all_zero(struct wd_dtb *e, const char *p_name) { - int i; + __u32 i;
if (!e || !e->data) { WD_ERR("invalid: %s is NULL!\n", p_name); @@ -2248,7 +2248,7 @@ static int sm2_kdf(struct wd_dtb *out, struct wcrypto_ecc_point *x2y2,
static void sm2_xor(struct wd_dtb *val1, struct wd_dtb *val2) { - int i; + __u32 i;
for (i = 0; i < val1->dsize; ++i) val1->data[i] = (char)((__u8)val1->data[i] ^ diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c index eb29598..6cbcdf5 100644 --- a/v1/drv/hisi_qm_udrv.c +++ b/v1/drv/hisi_qm_udrv.c @@ -596,7 +596,8 @@ int qm_send(struct wd_queue *q, void **req, __u32 num) { struct q_info *qinfo = q->qinfo; struct qm_queue_info *info = qinfo->priv; - int i, ret; + int ret; + __u32 i;
if (unlikely(wd_reg_read(info->ds_tx_base) == 1)) { WD_ERR("wd queue hw error happened before qm send!\n"); @@ -604,7 +605,7 @@ int qm_send(struct wd_queue *q, void **req, __u32 num) }
wd_spinlock(&info->sd_lock); - if (unlikely(__atomic_load_n(&info->used, __ATOMIC_RELAXED) > + if (unlikely((__u32)__atomic_load_n(&info->used, __ATOMIC_RELAXED) > info->sq_depth - num - 1)) { wd_unspinlock(&info->sd_lock); WD_ERR("queue is full!\n"); @@ -644,7 +645,7 @@ void qm_rx_update(struct qm_queue_info *info, __u32 num) void qm_rx_from_cache(struct qm_queue_info *info, void **resp, __u32 num) { __u16 idx = info->cq_head_index; - int i; + __u32 i;
for (i = 0; i < num; i++) { resp[i] = info->req_cache[idx]; @@ -686,8 +687,9 @@ int qm_recv(struct wd_queue *q, void **resp, __u32 num) struct qm_queue_info *info = qinfo->priv; struct cqe *cqe; __u16 sq_head; - int i, ret; void *sqe; + int ret; + __u32 i;
ret = check_ds_rx_base(info, resp, num, 1); if (unlikely(ret)) diff --git a/v1/wd.c b/v1/wd.c index 8ac2b1a..fe2ea97 100644 --- a/v1/wd.c +++ b/v1/wd.c @@ -132,14 +132,16 @@ static int get_int_attr(struct dev_info *dinfo, const char *attr) static int get_str_attr(struct dev_info *dinfo, const char *attr, char *buf, size_t buf_sz) { - int size; + __u32 size; + int ret;
- size = get_raw_attr(dinfo->dev_root, attr, buf, buf_sz); - if (size < 0) { + ret = get_raw_attr(dinfo->dev_root, attr, buf, buf_sz); + if (ret < 0) { buf[0] = '\0'; - return size; + return ret; }
+ size = ret; if (size == buf_sz) size = size - 1;
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c index 0b7b084..6b0b4d8 100644 --- a/v1/wd_adapter.c +++ b/v1/wd_adapter.c @@ -114,7 +114,7 @@ static struct wd_drv_dio_if hw_dio_tbl[] = { { int drv_open(struct wd_queue *q) { struct q_info *qinfo = q->qinfo; - int i; + __u32 i;
/* try to find another device if the user driver is not available */ for (i = 0; i < MAX_HW_TYPE; i++) { diff --git a/v1/wd_aead.c b/v1/wd_aead.c index ab1250a..7abb8a0 100644 --- a/v1/wd_aead.c +++ b/v1/wd_aead.c @@ -146,7 +146,7 @@ static void init_aead_cookie(struct wcrypto_aead_ctx *ctx, struct wcrypto_aead_ctx_setup *setup) { struct wcrypto_aead_cookie *cookie; - int i; + __u32 i;
for (i = 0; i < ctx->pool.cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + @@ -407,7 +407,7 @@ err_key_len: static void aead_requests_uninit(struct wcrypto_aead_msg **req, struct wcrypto_aead_ctx *ctx, __u32 num) { - int i; + __u32 i;
for (i = 0; i < num; i++) { if (req[i]->aiv) diff --git a/v1/wd_bmm.c b/v1/wd_bmm.c index 5fd15e5..c98c487 100644 --- a/v1/wd_bmm.c +++ b/v1/wd_bmm.c @@ -188,7 +188,7 @@ static int usr_pool_init(struct wd_blkpool *p) struct wd_blkpool_setup *sp = &p->setup; __u32 blk_size = sp->block_size; struct wd_blk_hd *hd = NULL; - int i; + __u32 i;
p->act_start = (void *)ALIGN((uintptr_t)p->usr_mem_start, sp->align_size); diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c index ad21a3a..3d7d140 100644 --- a/v1/wd_cipher.c +++ b/v1/wd_cipher.c @@ -126,7 +126,7 @@ static void init_cipher_cookie(struct wcrypto_cipher_ctx *ctx, struct wcrypto_cipher_ctx_setup *setup) { struct wcrypto_cipher_cookie *cookie; - int i; + __u32 i;
for (i = 0; i < ctx->pool.cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + diff --git a/v1/wd_dh.c b/v1/wd_dh.c index dff8a02..714ae71 100644 --- a/v1/wd_dh.c +++ b/v1/wd_dh.c @@ -90,7 +90,8 @@ static int wcrypto_init_dh_cookie(struct wcrypto_dh_ctx *ctx) { struct wcrypto_dh_ctx_setup *setup = &ctx->setup; struct wcrypto_dh_cookie *cookie; - int ret, i; + int ret; + __u32 i;
ret = wd_init_cookie_pool(&ctx->pool, sizeof(struct wcrypto_dh_cookie), WD_HPRE_CTX_MSG_NUM); diff --git a/v1/wd_digest.c b/v1/wd_digest.c index 7b01b14..86a7751 100644 --- a/v1/wd_digest.c +++ b/v1/wd_digest.c @@ -47,7 +47,7 @@ struct wcrypto_digest_ctx { struct wcrypto_digest_ctx_setup setup; };
-static int g_digest_mac_len[WCRYPTO_MAX_DIGEST_TYPE] = { +static __u32 g_digest_mac_len[WCRYPTO_MAX_DIGEST_TYPE] = { WCRYPTO_DIGEST_SM3_LEN, WCRYPTO_DIGEST_MD5_LEN, WCRYPTO_DIGEST_SHA1_LEN, WCRYPTO_DIGEST_SHA256_LEN, WCRYPTO_DIGEST_SHA224_LEN, WCRYPTO_DIGEST_SHA384_LEN, WCRYPTO_DIGEST_SHA512_LEN, @@ -102,7 +102,7 @@ static void init_digest_cookie(struct wcrypto_digest_ctx *ctx, struct wcrypto_digest_ctx_setup *setup) { struct wcrypto_digest_cookie *cookie; - int i; + __u32 i;
for (i = 0; i < ctx->pool.cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c index 8048443..93b4e1b 100644 --- a/v1/wd_ecc.c +++ b/v1/wd_ecc.c @@ -270,7 +270,7 @@ static void init_dtb_param(void *dtb, char *start, { struct wd_dtb *tmp = dtb; char *pos = start; - int i = 0; + __u32 i = 0;
while (i++ < num) { tmp->data = pos; @@ -894,7 +894,7 @@ static int fill_user_curve_cfg(struct wcrypto_ecc_curve *param, }
if (unlikely(!param->p.dsize || - param->p.dsize > BITS_TO_BYTES(setup->key_bits))) { + param->p.dsize > (__u32)BITS_TO_BYTES(setup->key_bits))) { WD_ERR("fill curve cfg:dsize %u error!\n", param->p.dsize); return -WD_EINVAL; } @@ -1068,7 +1068,7 @@ static void init_ctx_cookies(struct wcrypto_ecc_ctx *ctx, __u32 hsz = get_hw_keysize(ctx->key_size); struct q_info *qinfo = ctx->q->qinfo; struct wcrypto_ecc_cookie *cookie; - int i; + __u32 i;
for (i = 0; i < ctx->pool.cookies_num; i++) { cookie = (void *)((uintptr_t)ctx->pool.cookies + @@ -1717,7 +1717,7 @@ static bool less_than_latter(struct wd_dtb *d, struct wd_dtb *n)
static bool is_all_zero(struct wd_dtb *p) { - int i; + __u32 i;
for (i = 0; i < p->bsize; i++) { if (p->data[i]) diff --git a/v1/wd_rng.c b/v1/wd_rng.c index 2077578..a783f99 100644 --- a/v1/wd_rng.c +++ b/v1/wd_rng.c @@ -84,8 +84,8 @@ void *wcrypto_create_rng_ctx(struct wd_queue *q, struct wcrypto_rng_cookie *cookie; struct wcrypto_rng_ctx *ctx; struct q_info *qinfo; - __u32 ctx_id = 0; - int i, ret; + __u32 i, ctx_id = 0; + int ret;
if (wcrypto_setup_qinfo(setup, q, &ctx_id)) return NULL; diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c index 702f6be..61de3cc 100644 --- a/v1/wd_rsa.c +++ b/v1/wd_rsa.c @@ -430,7 +430,7 @@ static int create_ctx_key(struct wcrypto_rsa_ctx_setup *setup, struct wd_mm_br *br = &setup->br; struct wcrypto_rsa_prikey2 *pkey2; struct wcrypto_rsa_prikey1 *pkey1; - int len; + __u32 len;
if (setup->is_crt) { len = sizeof(struct wcrypto_rsa_prikey) + @@ -500,7 +500,8 @@ struct wcrypto_rsa_ctx *create_ctx(struct wcrypto_rsa_ctx_setup *setup, int ctx_ { struct wcrypto_rsa_cookie *cookie; struct wcrypto_rsa_ctx *ctx; - int i, ret; + __u32 i; + int ret;
ctx = calloc(1, sizeof(struct wcrypto_rsa_ctx)); if (!ctx) diff --git a/v1/wd_util.c b/v1/wd_util.c index 112cc16..26f46d4 100644 --- a/v1/wd_util.c +++ b/v1/wd_util.c @@ -57,7 +57,7 @@ void drv_iova_unmap(struct wd_queue *q, void *va, void *dma, size_t sz) int wd_alloc_id(__u8 *buf, __u32 size, __u32 *id, __u32 last_id, __u32 id_max) { __u32 idx = last_id; - int cnt = 0; + __u32 cnt = 0;
while (__atomic_test_and_set(&buf[idx], __ATOMIC_ACQUIRE)) { idx++; @@ -134,7 +134,7 @@ static void *get_cookie(struct wd_cookie_pool *pool)
void wd_put_cookies(struct wd_cookie_pool *pool, void **cookies, __u32 num) { - int i; + __u32 i;
for (i = 0; i < num; i++) put_cookie(pool, cookies[i]); @@ -142,7 +142,7 @@ void wd_put_cookies(struct wd_cookie_pool *pool, void **cookies, __u32 num)
int wd_get_cookies(struct wd_cookie_pool *pool, void **cookies, __u32 num) { - int i ; + __u32 i;
for (i = 0; i < num; i++) { cookies[i] = get_cookie(pool); diff --git a/wd.c b/wd.c index bb85d2e..6f61f11 100644 --- a/wd.c +++ b/wd.c @@ -161,14 +161,16 @@ static int get_int_attr(struct uacce_dev *dev, const char *attr, int *val) static int get_str_attr(struct uacce_dev *dev, const char *attr, char *buf, size_t buf_sz) { - int ret; + __u32 ret; + int size;
- ret = get_raw_attr(dev->dev_root, attr, buf, buf_sz); - if (ret < 0) { + size = get_raw_attr(dev->dev_root, attr, buf, buf_sz); + if (size < 0) { buf[0] = '\0'; - return ret; + return size; }
+ ret = size; if (ret == buf_sz) ret--;
@@ -620,6 +622,7 @@ int wd_get_avail_ctx(struct uacce_dev *dev) static int get_dev_alg_name(const char *d_name, char *dev_alg_name, size_t sz) { char dev_path[MAX_DEV_NAME_LEN] = {0}; + __u32 size; int ret;
ret = snprintf(dev_path, MAX_DEV_NAME_LEN, "%s/%s", @@ -635,7 +638,8 @@ static int get_dev_alg_name(const char *d_name, char *dev_alg_name, size_t sz) return ret; }
- if (ret == sz) + size = ret; + if (size == sz) dev_alg_name[sz - 1] = '\0';
return 0; diff --git a/wd_digest.c b/wd_digest.c index df2c286..11cdc9b 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -21,7 +21,7 @@ #define WD_POOL_MAX_ENTRIES 1024 #define DES_WEAK_KEY_NUM 4
-static int g_digest_mac_len[WD_DIGEST_TYPE_MAX] = { +static __u32 g_digest_mac_len[WD_DIGEST_TYPE_MAX] = { WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN, WD_DIGEST_SHA256_LEN, WD_DIGEST_SHA224_LEN, WD_DIGEST_SHA384_LEN, WD_DIGEST_SHA512_LEN, @@ -30,7 +30,7 @@ static int g_digest_mac_len[WD_DIGEST_TYPE_MAX] = { WD_DIGEST_AES_CMAC_LEN, WD_DIGEST_AES_GMAC_LEN };
-static int g_digest_mac_full_len[WD_DIGEST_TYPE_MAX] = { +static __u32 g_digest_mac_full_len[WD_DIGEST_TYPE_MAX] = { WD_DIGEST_SM3_FULL_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_FULL_LEN, WD_DIGEST_SHA256_FULL_LEN, WD_DIGEST_SHA224_FULL_LEN, WD_DIGEST_SHA384_FULL_LEN, WD_DIGEST_SHA512_FULL_LEN, diff --git a/wd_ecc.c b/wd_ecc.c index 6c055c8..ea54a8f 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -424,7 +424,7 @@ static void init_dtb_param(void *dtb, char *str, { struct wd_dtb *tmp = dtb; char *start = str; - int i = 0; + __u32 i = 0;
while (i++ < num) { tmp->data = start; @@ -1002,7 +1002,7 @@ static int fill_user_curve_cfg(struct wd_ecc_curve *param, }
if (!param->p.dsize || - param->p.dsize > BITS_TO_BYTES(setup->key_bits)) { + param->p.dsize > (__u32)BITS_TO_BYTES(setup->key_bits)) { WD_ERR("invalid: fill curve cfg dsize %u is error!\n", param->p.dsize); return -WD_EINVAL; } diff --git a/wd_mempool.c b/wd_mempool.c index 8d3ca90..ff9910a 100644 --- a/wd_mempool.c +++ b/wd_mempool.c @@ -377,7 +377,7 @@ static void free_mem_to_mempool_nolock(struct blkpool *bp) struct mempool *mp = bp->mp; struct memzone *iter; size_t blks; - int i; + __u32 i;
while ((iter = TAILQ_LAST(&bp->mz_list, memzone_list))) { for (i = iter->begin; i <= iter->end; i++) @@ -423,7 +423,7 @@ static int alloc_block_from_mempool(struct mempool *mp,
do { pos_first = find_next_zero_bit(mp->bitmap, pos_last); - if (pos_first == mp->bitmap->bits) { + if ((__u32)pos_first == mp->bitmap->bits) { WD_ERR("failed to find free block from mempool!\n"); return -WD_ENOMEM; } @@ -536,7 +536,7 @@ static int init_blkpool_elem(struct blkpool *bp) { struct memzone *iter; int idx = 0; - int i; + __u32 i;
bp->blk_elem = calloc(bp->depth, sizeof(void *)); if (!bp->blk_elem) { diff --git a/wd_util.c b/wd_util.c index 6e70549..9a591d5 100644 --- a/wd_util.c +++ b/wd_util.c @@ -222,7 +222,8 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in, { bool need_info = wd_need_info(); struct wd_ctx_internal *ctxs; - int i, j, ret; + __u32 i, j; + int ret;
if (!cfg->ctx_num) { WD_ERR("invalid: ctx_num is 0!\n"); @@ -302,7 +303,7 @@ void wd_clear_sched(struct wd_sched *in)
void wd_clear_ctx_config(struct wd_ctx_config_internal *in) { - int i; + __u32 i;
for (i = 0; i < in->ctx_num; i++) pthread_spin_destroy(&in->ctxs[i].lock); @@ -365,7 +366,8 @@ static void uninit_msg_pool(struct msg_pool *pool) int wd_init_async_request_pool(struct wd_async_msg_pool *pool, __u32 pool_num, __u32 msg_num, __u32 msg_size) { - int i, j, ret; + __u32 i, j; + int ret;
pool->pool_num = pool_num;
@@ -392,7 +394,7 @@ err:
void wd_uninit_async_request_pool(struct wd_async_msg_pool *pool) { - int i; + __u32 i;
for (i = 0; i < pool->pool_num; i++) uninit_msg_pool(&pool->pools[i]); @@ -424,7 +426,7 @@ int wd_get_msg_from_pool(struct wd_async_msg_pool *pool, struct msg_pool *p = &pool->pools[ctx_idx]; __u32 msg_num = p->msg_num; __u32 msg_size = p->msg_size; - int cnt = 0; + __u32 cnt = 0; __u32 idx = p->tail;
while (__atomic_test_and_set(&p->used[idx], __ATOMIC_ACQUIRE)) { @@ -657,8 +659,7 @@ free_numa_dev_num:
static int is_number(const char *str) { - size_t len; - int i; + size_t i, len;
if (!str) return 0; @@ -984,7 +985,8 @@ static int wd_parse_env(struct wd_env_config *config) { const struct wd_config_variable *var; const char *var_s; - int ret, i; + int ret; + __u32 i;
for (i = 0; i < config->table_size; i++) { var = config->table + i; @@ -1055,10 +1057,10 @@ static void wd_uninit_env_config(struct wd_env_config *config) config->table = NULL; }
-static __u8 get_ctx_mode(struct wd_env_config_per_numa *config, int idx) +static __u8 get_ctx_mode(struct wd_env_config_per_numa *config, __u32 idx) { struct wd_ctx_range **ctx_table = config->ctx_table; - int i; + __u32 i;
for (i = 0; i < config->op_type_num; i++) { if ((idx >= ctx_table[CTX_MODE_SYNC][i].begin) && @@ -1070,10 +1072,10 @@ static __u8 get_ctx_mode(struct wd_env_config_per_numa *config, int idx) }
static int get_op_type(struct wd_env_config_per_numa *config, - int idx, __u8 ctx_mode) + __u32 idx, __u8 ctx_mode) { struct wd_ctx_range **ctx_table = config->ctx_table; - int i; + __u32 i;
if (config->op_type_num == 1) return 0; @@ -1110,11 +1112,12 @@ static handle_t request_ctx_on_numa(struct wd_env_config_per_numa *config) }
static int wd_get_wd_ctx(struct wd_env_config_per_numa *config, - struct wd_ctx_config *ctx_config, int start) + struct wd_ctx_config *ctx_config, __u32 start) { int ctx_num = config->sync_ctx_num + config->async_ctx_num; handle_t h_ctx; - int i, j, ret; + __u32 i, j; + int ret;
if (!ctx_num) return 0; @@ -1144,7 +1147,7 @@ free_ctx: return ret; }
-static void wd_put_wd_ctx(struct wd_ctx_config *ctx_config, int ctx_num) +static void wd_put_wd_ctx(struct wd_ctx_config *ctx_config, __u32 ctx_num) { __u32 i;
@@ -1156,8 +1159,8 @@ static int wd_alloc_ctx(struct wd_env_config *config) { struct wd_env_config_per_numa *config_numa; struct wd_ctx_config *ctx_config; - int ctx_num = 0, start = 0, ret = 0; - int i; + __u32 i, ctx_num = 0, start = 0; + int ret;
config->ctx_config = calloc(1, sizeof(*ctx_config)); if (!config->ctx_config) @@ -1299,8 +1302,7 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config, struct wd_ctx_range **ctx_table; struct async_task_queue *head; unsigned long offset = 0; - int num = 0; - int i; + __u32 i, num = 0;
FOREACH_NUMA(i, config, config_numa) { num += config_numa->sync_ctx_num + config_numa->async_ctx_num; @@ -2005,10 +2007,11 @@ static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, struct uacce_dev_li const char *section, __u32 op_type_num, int is_comp) { struct wd_ctx_nums *ctxs = ctx_params->ctx_set_num; - int i, j, ctx_num, node, ret; + int ret, ctx_num, node; struct uacce_dev *dev; char *ctx_section; const char *type; + __u32 i, j;
ctx_section = index(section, ':'); if (!ctx_section) { @@ -2036,9 +2039,9 @@ static int wd_set_ctx_nums(struct wd_ctx_params *ctx_params, struct uacce_dev_li
/* If there're multiple configurations, use the maximum ctx number */ if (!i) - ctxs[j].sync_ctx_num = MAX(ctxs[j].sync_ctx_num, ctx_num); + ctxs[j].sync_ctx_num = MAX(ctxs[j].sync_ctx_num, (__u32)ctx_num); else - ctxs[j].async_ctx_num = MAX(ctxs[j].async_ctx_num, ctx_num); + ctxs[j].async_ctx_num = MAX(ctxs[j].async_ctx_num, (__u32)ctx_num);
/* enable a node here, all enabled nodes share the same configuration */ numa_bitmask_setbit(ctx_params->bmp, node); @@ -2123,7 +2126,7 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, copy_bitmask_to_bitmask(user_ctx_params->bmp, ctx_params->bmp); ctx_params->ctx_set_num = user_ctx_params->ctx_set_num; ctx_params->op_type_num = user_ctx_params->op_type_num; - if (ctx_params->op_type_num > max_op_type) { + if (ctx_params->op_type_num > (__u32)max_op_type) { WD_ERR("fail to check user op type numbers.\n"); numa_free_nodemask(ctx_params->bmp); return -WD_EINVAL; @@ -2141,7 +2144,7 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, }
ctx_params->op_type_num = driver->op_type_num; - if (ctx_params->op_type_num > max_op_type) { + if (ctx_params->op_type_num > (__u32)max_op_type) { WD_ERR("fail to check driver op type numbers.\n"); numa_free_nodemask(ctx_params->bmp); return -WD_EAGAIN; @@ -2411,13 +2414,13 @@ out_free_list: }
static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *list, - int idx, int numa_id, int op_type) + __u32 idx, int numa_id, __u32 op_type) { struct wd_ctx_nums ctx_nums = attrs->ctx_params->ctx_set_num[op_type]; __u32 ctx_set_num = ctx_nums.sync_ctx_num + ctx_nums.async_ctx_num; struct wd_ctx_config *ctx_config = attrs->ctx_config; struct uacce_dev *dev; - int i; + __u32 i;
/* If the ctx set number is 0, the initialization is skipped. */ if (!ctx_set_num) @@ -2446,7 +2449,7 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
static void wd_release_ctx_set(struct wd_ctx_config *ctx_config) { - int i; + __u32 i;
for (i = 0; i < ctx_config->ctx_num; i++) if (ctx_config->ctxs[i].ctx) { @@ -2467,7 +2470,7 @@ static int wd_instance_sched_set(struct wd_sched *sched, struct wd_ctx_nums ctx_ sparams.mode = i; sparams.begin = idx + ctx_nums.sync_ctx_num * i; end = idx - 1 + ctx_nums.sync_ctx_num + ctx_nums.async_ctx_num * i; - if (end < 0 || sparams.begin > end) + if (end < 0 || sparams.begin > (__u32)end) continue;
sparams.end = end; @@ -2485,10 +2488,9 @@ static int wd_init_ctx_and_sched(struct wd_init_attrs *attrs, struct bitmask *bm { struct wd_ctx_params *ctx_params = attrs->ctx_params; __u32 op_type_num = ctx_params->op_type_num; - int max_node = numa_max_node() + 1; + int i, ret, max_node = numa_max_node() + 1; struct wd_ctx_nums ctx_nums; - int i, j, ret; - int idx = 0; + __u32 j, idx = 0;
for (i = 0; i < max_node; i++) { if (!numa_bitmask_isbitset(bmp, i)) @@ -2591,7 +2593,7 @@ out_freelist:
static void wd_alg_ctx_uninit(struct wd_ctx_config *ctx_config) { - int i; + __u32 i;
for (i = 0; i < ctx_config->ctx_num; i++) if (ctx_config->ctxs[i].ctx) { diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c index 6a0dfba..d4f1756 100644 --- a/wd_zlibwrapper.c +++ b/wd_zlibwrapper.c @@ -159,8 +159,8 @@ static int wd_zlib_do_request(z_streamp strm, int flush, enum wd_comp_op_type ty { handle_t h_sess = strm->reserved; struct wd_comp_req req = {0}; - int src_len = strm->avail_in; - int dst_len = strm->avail_out; + __u32 src_len = strm->avail_in; + __u32 dst_len = strm->avail_out; int ret;
if (unlikely(flush != Z_SYNC_FLUSH && flush != Z_FINISH)) {
The max length of the file path defined by user should be PATH_MAX.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_aead.c | 3 ++- wd_cipher.c | 3 ++- wd_comp.c | 2 +- wd_dh.c | 2 +- wd_digest.c | 3 ++- wd_ecc.c | 2 +- wd_rsa.c | 2 +- wd_util.c | 20 ++++++++++---------- 8 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/wd_aead.c b/wd_aead.c index 0967dda..85acf5d 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -6,6 +6,7 @@
#include <stdlib.h> #include <pthread.h> +#include <limits.h> #include "include/drv/wd_aead_drv.h" #include "wd_aead.h"
@@ -85,7 +86,7 @@ static int wd_aead_open_driver(void) { struct wd_alg_driver *driver = NULL; const char *alg_name = "gcm(aes)"; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; int ret;
/* diff --git a/wd_cipher.c b/wd_cipher.c index 1344119..a8fbecb 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -7,6 +7,7 @@ #include <stdlib.h> #include <pthread.h> #include <sched.h> +#include <limits.h> #include "include/drv/wd_cipher_drv.h" #include "wd_cipher.h"
@@ -91,7 +92,7 @@ static int wd_cipher_open_driver(void) { struct wd_alg_driver *driver = NULL; const char *alg_name = "cbc(aes)"; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; int ret;
/* diff --git a/wd_comp.c b/wd_comp.c index f48938a..6be6b72 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -64,7 +64,7 @@ static void wd_comp_close_driver(void) static int wd_comp_open_driver(void) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; const char *alg_name = "zlib"; int ret;
diff --git a/wd_dh.c b/wd_dh.c index 6aebb8c..203d3e0 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -56,7 +56,7 @@ static void wd_dh_close_driver(void) static int wd_dh_open_driver(void) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; const char *alg_name = "dh"; int ret;
diff --git a/wd_digest.c b/wd_digest.c index 11cdc9b..73f44e5 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -6,6 +6,7 @@
#include <stdlib.h> #include <pthread.h> +#include <limits.h> #include "include/drv/wd_digest_drv.h" #include "wd_digest.h"
@@ -88,7 +89,7 @@ static int wd_digest_open_driver(void) { struct wd_alg_driver *driver = NULL; const char *alg_name = "sm3"; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; int ret;
/* diff --git a/wd_ecc.c b/wd_ecc.c index ea54a8f..695c61d 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -112,7 +112,7 @@ static void wd_ecc_close_driver(void) static int wd_ecc_open_driver(void) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; const char *alg_name = "sm2"; int ret;
diff --git a/wd_rsa.c b/wd_rsa.c index fff6067..58b1229 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -97,7 +97,7 @@ static void wd_rsa_close_driver(void) static int wd_rsa_open_driver(void) { struct wd_alg_driver *driver = NULL; - char lib_path[PATH_STR_SIZE]; + char lib_path[PATH_MAX]; const char *alg_name = "rsa"; int ret;
diff --git a/wd_util.c b/wd_util.c index 9a591d5..053a654 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2156,7 +2156,7 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, static void dladdr_empty(void) {} int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir) { - char file_path[PATH_STR_SIZE] = {0}; + char file_path[PATH_MAX] = {0}; char path[PATH_MAX]; Dl_info file_info; int len, rc, i; @@ -2167,23 +2167,23 @@ int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir) WD_ERR("fail to get lib file path.\n"); return -WD_EINVAL; } - strncpy(file_path, file_info.dli_fname, PATH_STR_SIZE - 1); + strncpy(file_path, file_info.dli_fname, PATH_MAX - 1);
/* Clear the file path's tail file name */ len = strlen(file_path) - 1; for (i = len; i >= 0; i--) { if (file_path[i] == '/') { - memset(&file_path[i], 0, PATH_STR_SIZE - i + 1); + memset(&file_path[i], 0, PATH_MAX - i + 1); break; } }
if (is_dir) { - (void)snprintf(lib_path, PATH_STR_SIZE, "%s", file_path); + (void)snprintf(lib_path, PATH_MAX, "%s", file_path); return 0; }
- len = snprintf(lib_path, PATH_STR_SIZE, "%s/%s", file_path, lib_file); + len = snprintf(lib_path, PATH_MAX, "%s/%s", file_path, lib_file); if (len < 0) return -WD_EINVAL;
@@ -2199,8 +2199,8 @@ void *wd_dlopen_drv(const char *cust_lib_dir) { typedef int (*alg_ops)(struct wd_alg_driver *drv); struct drv_lib_list *node, *head = NULL; - char lib_dir_path[PATH_STR_SIZE] = {0}; - char lib_path[PATH_STR_SIZE] = {0}; + char lib_dir_path[PATH_MAX] = {0}; + char lib_path[PATH_MAX] = {0}; struct dirent *lib_dir; alg_ops dl_func = NULL; DIR *wd_dir; @@ -2211,12 +2211,12 @@ void *wd_dlopen_drv(const char *cust_lib_dir) if (ret) return NULL; } else { - (void)snprintf(lib_path, PATH_STR_SIZE, "%s/%s", cust_lib_dir, DEF_DRV_LIB_FILE); + (void)snprintf(lib_path, PATH_MAX, "%s/%s", cust_lib_dir, DEF_DRV_LIB_FILE); ret = access(lib_path, F_OK); if (ret) return NULL;
- strncpy(lib_dir_path, cust_lib_dir, PATH_STR_SIZE - 1); + strncpy(lib_dir_path, cust_lib_dir, PATH_MAX - 1); }
wd_dir = opendir(lib_dir_path); @@ -2238,7 +2238,7 @@ void *wd_dlopen_drv(const char *cust_lib_dir) if (!node) goto free_list;
- ret = snprintf(lib_path, PATH_STR_SIZE, "%s/%s", lib_dir_path, lib_dir->d_name); + ret = snprintf(lib_path, PATH_MAX, "%s/%s", lib_dir_path, lib_dir->d_name); if (ret < 0) goto free_node;
Conversion causes data truncation, cast Expression : "size", from __u32 to int, fix it.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/wd.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/v1/wd.c b/v1/wd.c index fe2ea97..e0a86dc 100644 --- a/v1/wd.c +++ b/v1/wd.c @@ -132,7 +132,6 @@ static int get_int_attr(struct dev_info *dinfo, const char *attr) static int get_str_attr(struct dev_info *dinfo, const char *attr, char *buf, size_t buf_sz) { - __u32 size; int ret;
ret = get_raw_attr(dinfo->dev_root, attr, buf, buf_sz); @@ -141,16 +140,15 @@ static int get_str_attr(struct dev_info *dinfo, const char *attr, char *buf, return ret; }
- size = ret; - if (size == buf_sz) - size = size - 1; + if ((size_t)ret == buf_sz) + ret = ret - 1;
- buf[size] = '\0'; - while ((size > 1) && (buf[size - 1] == '\n')) { - buf[size - 1] = '\0'; - size = size - 1; + buf[ret] = '\0'; + while ((ret > 1) && (buf[ret - 1] == '\n')) { + buf[ret - 1] = '\0'; + ret = ret - 1; } - return size; + return ret; }
static int get_ul_vec_attr(struct dev_info *dinfo, const char *attr,
Cast between pointer to function type 'void *(*)(void *, void *)' and pointer to object type 'void *' is not allowed, fix it.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/wd_sgl.c | 25 ++++++++++++++++++++----- wd_util.c | 7 +++++-- 2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/v1/wd_sgl.c b/v1/wd_sgl.c index ceb7f4c..a11190a 100644 --- a/v1/wd_sgl.c +++ b/v1/wd_sgl.c @@ -181,6 +181,21 @@ alloc_sgl_err: return ret; }
+static void *wd_alloc_blk_sgl(void *pool, size_t size) +{ + return wd_alloc_blk(pool); +} + +static void *wd_blk_iova_map_sgl(void *pool, void *blk, size_t sz) +{ + return wd_blk_iova_map(pool, blk); +} + +static void wd_blk_iova_unmap_sgl(void *pool, void *blk_dma, void *blk, size_t sz) +{ + wd_blk_iova_unmap(pool, blk_dma, blk); +} + static void *sgl_buf_pool_init(struct wd_queue *q, struct wd_sglpool *pool) { struct wd_sglpool_setup *sp = &pool->setup; @@ -198,11 +213,11 @@ static void *sgl_buf_pool_init(struct wd_queue *q, struct wd_sglpool *pool) return NULL; }
- pool->buf_br.alloc = (void *)wd_alloc_blk; - pool->buf_br.free = (void *)wd_free_blk; - pool->buf_br.iova_map = (void *)wd_blk_iova_map; - pool->buf_br.iova_unmap = (void *)wd_blk_iova_unmap; - pool->buf_br.get_bufsize = (void *)wd_blksize; + pool->buf_br.alloc = wd_alloc_blk_sgl; + pool->buf_br.free = wd_free_blk; + pool->buf_br.iova_map = wd_blk_iova_map_sgl; + pool->buf_br.iova_unmap = wd_blk_iova_unmap_sgl; + pool->buf_br.get_bufsize = wd_blksize; pool->buf_br.usr = p;
return p; diff --git a/wd_util.c b/wd_util.c index 053a654..370a55a 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2153,7 +2153,10 @@ int wd_ctx_param_init(struct wd_ctx_params *ctx_params, return 0; }
-static void dladdr_empty(void) {} +static void dladdr_empty(void) +{ +} + int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir) { char file_path[PATH_MAX] = {0}; @@ -2162,7 +2165,7 @@ int wd_get_lib_file_path(char *lib_file, char *lib_path, bool is_dir) int len, rc, i;
/* Get libwd.so file's system path */ - rc = dladdr((void *)dladdr_empty, &file_info); + rc = dladdr(dladdr_empty, &file_info); if (!rc) { WD_ERR("fail to get lib file path.\n"); return -WD_EINVAL;