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)) {