From 280e01c8a0aae071d54200f9a5fdcdc5035c3a9c Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Sun, 24 Apr 2022 09:54:29 +0800
Subject: [PATCH 125/183] uadk: fix parameter used as working variable

input parameter of function should not be used as
working variable, fix it.

Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
 drv/hisi_hpre.c         |  3 ++-
 drv/hisi_sec.c          |  3 ++-
 v1/drv/hisi_hpre_udrv.c | 13 ++++++----
 v1/drv/hisi_sec_udrv.c  |  3 ++-
 v1/wd.c                 | 13 +++++-----
 v1/wd_adapter.c         | 15 ++++++------
 v1/wd_aead.c            |  3 ++-
 v1/wd_cipher.c          |  3 ++-
 v1/wd_comp.c            |  3 ++-
 v1/wd_dh.c              |  3 ++-
 v1/wd_digest.c          |  3 ++-
 v1/wd_ecc.c             |  6 +++--
 v1/wd_rng.c             |  3 ++-
 v1/wd_rsa.c             |  3 ++-
 v1/wd_sgl.c             | 54 ++++++++++++++++++++++++-----------------
 wd_aead.c               |  3 ++-
 wd_cipher.c             |  3 ++-
 wd_comp.c               |  9 ++++---
 wd_dh.c                 |  3 ++-
 wd_digest.c             |  3 ++-
 wd_ecc.c                |  6 +++--
 wd_mempool.c            | 18 ++++++++------
 wd_util.c               |  3 ++-
 23 files changed, 110 insertions(+), 69 deletions(-)

diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index bf0f440..4e62c0f 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -1965,11 +1965,12 @@ static void msg_pack(char *dst, __u64 *out_len,
 }
 
 static int sm2_kdf(struct wd_dtb *out, struct wd_ecc_point *x2y2,
-		   __u64 m_len, struct wd_hash_mt *hash)
+		   __u64 mt_len, struct wd_hash_mt *hash)
 {
 	char p_out[MAX_HASH_LENS] = {0};
 	__u32 h_bytes, x2y2_len;
 	char *tmp = out->data;
+	__u64 m_len = mt_len;
 	__u64 in_len, lens;
 	char *p_in, *t_out;
 	__u8 ctr[4];
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 88eacc3..b17ce0f 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -487,9 +487,10 @@ int hisi_sec_init(struct wd_ctx_config_internal *config, void *priv);
 void hisi_sec_exit(void *priv);
 
 /* increment counter (128-bit int) by software */
-static void ctr_iv_inc(__u8 *counter, __u32 c)
+static void ctr_iv_inc(__u8 *counter, __u32 len)
 {
 	__u32 n = CTR_128BIT_COUNTER;
+	__u32 c = len;
 
 	do {
 		--n;
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
index 76ba3e8..805160e 100644
--- a/v1/drv/hisi_hpre_udrv.c
+++ b/v1/drv/hisi_hpre_udrv.c
@@ -1873,13 +1873,14 @@ static int split_req(struct qm_queue_info *info,
 	return 0;
 }
 
-static int fill_sm2_enc_sqe(void *message, struct qm_queue_info *info, __u16 i)
+static int fill_sm2_enc_sqe(void *msg, struct qm_queue_info *info, __u16 idx)
 {
 	struct wcrypto_hash_mt *hash = &((struct q_info *)info->q->qinfo)->hash;
-	struct wcrypto_ecc_msg *req_src = message;
+	struct wcrypto_ecc_msg *req_src = msg;
 	struct wcrypto_sm2_enc_in *ein = (void *)req_src->in;
 	struct wcrypto_ecc_msg *req_dst[2] = {NULL};
 	struct wd_dtb *plaintext = &ein->plaintext;
+	__u16 i = idx;
 	int ret;
 
 	if (plaintext->dsize <= HW_PLAINTEXT_BYTES_MAX &&
@@ -2053,11 +2054,12 @@ static int qm_parse_ecc_sqe_general(void *msg, const struct qm_queue_info *info,
 	return 1;
 }
 
-static int parse_first_sqe(void *hw_msg, struct qm_queue_info *info, __u16 i,
+static int parse_first_sqe(void *hw_msg, struct qm_queue_info *info, __u16 idx,
 			   __u16 usr)
 {
-	struct wcrypto_ecc_msg *msg = info->req_cache[i];
+	struct wcrypto_ecc_msg *msg = info->req_cache[idx];
 	struct wcrypto_ecc_msg *msg_src;
+	__u16 i = idx;
 	int ret;
 
 	ret = qm_parse_ecc_sqe_general(hw_msg, info, i, usr);
@@ -2177,10 +2179,11 @@ static void msg_pack(char *dst, __u64 *out_len,
 }
 
 static int sm2_kdf(struct wd_dtb *out, struct wcrypto_ecc_point *x2y2,
-		   __u64 m_len, struct q_info *q_info)
+		   __u64 hash_mt_len, struct q_info *q_info)
 {
 	struct wcrypto_hash_mt *hash = &q_info->hash;
 	char p_out[MAX_HASH_LENS] = {0};
+	__u64 m_len = hash_mt_len;
 	__u32 h_bytes, x2y2_len;
 	char *tmp = out->data;
 	__u64 in_len, lens;
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c
index 0e8bf57..4d5ede5 100644
--- a/v1/drv/hisi_sec_udrv.c
+++ b/v1/drv/hisi_sec_udrv.c
@@ -206,10 +206,11 @@ static void fill_bd3_addr_type(__u8 data_fmt, struct hisi_sec_bd3_sqe *sqe3)
 }
 
 /* increment counter (128-bit int) by c */
-static void ctr_iv_inc(__u8 *counter, __u32 c, __u8 data_fmt)
+static void ctr_iv_inc(__u8 *counter, __u32 shift_len, __u8 data_fmt)
 {
 	__u32 n = CTR_128BIT_COUNTER;
 	__u8 *counter1 = counter;
+	__u32 c = shift_len;
 
 	if (data_fmt == WD_SGL_BUF) {
 		counter1 = wd_get_first_sge_buf((struct wd_sgl *)counter);
diff --git a/v1/wd.c b/v1/wd.c
index 8e3a91c..8ef83c6 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -845,19 +845,20 @@ void *wd_dma_to_va(struct wd_queue *q, void *dma)
 void *wd_drv_mmap_qfr(struct wd_queue *q, enum uacce_qfrt qfrt, size_t size)
 {
 	struct q_info *qinfo = q->qinfo;
+	size_t tmp = size;
 	off_t off;
 
 	off = qfrt * getpagesize();
 
 	if (qfrt != WD_UACCE_QFRT_SS)
-		size = qinfo->qfrs_offset[qfrt];
+		tmp = qinfo->qfrs_offset[qfrt];
 
-	return mmap(0, size, PROT_READ | PROT_WRITE,
+	return mmap(0, tmp, PROT_READ | PROT_WRITE,
 		    MAP_SHARED, qinfo->fd, off);
 }
 
 void wd_drv_unmmap_qfr(struct wd_queue *q, void *addr,
-				     enum uacce_qfrt qfrt, size_t size)
+		       enum uacce_qfrt qfrt, size_t size)
 {
 	struct q_info *qinfo = q->qinfo;
 
@@ -865,9 +866,9 @@ void wd_drv_unmmap_qfr(struct wd_queue *q, void *addr,
 		return;
 
 	if (qfrt != WD_UACCE_QFRT_SS)
-		size = qinfo->qfrs_offset[qfrt];
-
-	munmap(addr, size);
+		munmap(addr, qinfo->qfrs_offset[qfrt]);
+	else
+		munmap(addr, size);
 }
 int wd_register_log(wd_log log)
 {
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c
index 53bf41e..0b7b084 100644
--- a/v1/wd_adapter.c
+++ b/v1/wd_adapter.c
@@ -198,15 +198,16 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
 	struct wd_ss_region *rgn = NULL;
 	struct q_info *qinfo = q->qinfo;
 	unsigned long info = 0;
+	size_t tmp = size;
 	unsigned long i = 0;
 	void *ptr = NULL;
 	int ret = 1;
 
 	/* Make sure memory map granularity size align */
 	if (!qinfo->iommu_type)
-		size = ALIGN(size, WD_UACCE_GRAN_SIZE);
+		tmp = ALIGN(tmp, WD_UACCE_GRAN_SIZE);
 
-	ptr = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_SS, size);
+	ptr = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_SS, tmp);
 	if (ptr == MAP_FAILED) {
 		int value = errno;
 
@@ -215,8 +216,8 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
 	}
 
 	qinfo->ss_va = ptr;
-	qinfo->ss_size = size;
-	size = 0;
+	qinfo->ss_size = tmp;
+	tmp = 0;
 	while (ret > 0) {
 		info = (unsigned long)i;
 		ret = ioctl(qinfo->fd, WD_UACCE_CMD_GET_SS_DMA, &info);
@@ -238,8 +239,8 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
 			rgn->size = (info & WD_UACCE_GRAN_NUM_MASK) <<
 				WD_UACCE_GRAN_SHIFT;
 		rgn->pa = info & (~WD_UACCE_GRAN_NUM_MASK);
-		rgn->va = ptr + size;
-		size += rgn->size;
+		rgn->va = ptr + tmp;
+		tmp += rgn->size;
 		drv_add_slice(q, rgn);
 		i++;
 	}
@@ -248,7 +249,7 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
 
 err_out:
 	drv_free_slice(q);
-	drv_unmap_reserve_mem(q, ptr, size);
+	drv_unmap_reserve_mem(q, ptr, tmp);
 
 	return NULL;
 }
diff --git a/v1/wd_aead.c b/v1/wd_aead.c
index d66f6e0..4ff690a 100644
--- a/v1/wd_aead.c
+++ b/v1/wd_aead.c
@@ -635,6 +635,7 @@ int wcrypto_aead_poll(struct wd_queue *q, unsigned int num)
 	struct wcrypto_aead_msg *aead_resp = NULL;
 	struct wcrypto_aead_ctx *ctx;
 	struct wcrypto_aead_tag *tag;
+	unsigned int tmp = num;
 	int count = 0;
 	int ret;
 
@@ -664,7 +665,7 @@ int wcrypto_aead_poll(struct wd_queue *q, unsigned int num)
 		ctx->setup.cb(aead_resp, tag->wcrypto_tag.tag);
 		aead_requests_uninit(&aead_resp, ctx, 1);
 		wd_put_cookies(&ctx->pool, (void **)&tag, 1);
-	} while (--num);
+	} while (--tmp);
 
 	return count;
 }
diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c
index 355d9aa..ad21a3a 100644
--- a/v1/wd_cipher.c
+++ b/v1/wd_cipher.c
@@ -504,6 +504,7 @@ int wcrypto_cipher_poll(struct wd_queue *q, unsigned int num)
 	struct wcrypto_cipher_msg *cipher_resp = NULL;
 	struct wcrypto_cipher_ctx *ctx;
 	struct wcrypto_cipher_tag *tag;
+	unsigned int tmp = num;
 	int count = 0;
 	int ret;
 
@@ -532,7 +533,7 @@ int wcrypto_cipher_poll(struct wd_queue *q, unsigned int num)
 		ctx = tag->wcrypto_tag.ctx;
 		ctx->setup.cb(cipher_resp, tag->wcrypto_tag.tag);
 		wd_put_cookies(&ctx->pool, (void **)&tag, 1);
-	} while (--num);
+	} while (--tmp);
 
 	return count;
 }
diff --git a/v1/wd_comp.c b/v1/wd_comp.c
index 7debef7..33546d4 100644
--- a/v1/wd_comp.c
+++ b/v1/wd_comp.c
@@ -280,6 +280,7 @@ int wcrypto_comp_poll(struct wd_queue *q, unsigned int num)
 	struct wcrypto_comp_msg *resp = NULL;
 	struct wcrypto_comp_ctx *ctx;
 	struct wcrypto_comp_tag *tag;
+	unsigned int tmp = num;
 	int count = 0;
 	int ret;
 
@@ -309,7 +310,7 @@ int wcrypto_comp_poll(struct wd_queue *q, unsigned int num)
 		ctx->cb(resp, tag->wcrypto_tag.tag);
 		wd_put_cookies(&ctx->pool, (void **)&tag, 1);
 		resp = NULL;
-	} while (--num);
+	} while (--tmp);
 
 	return ret < 0 ? ret : count;
 }
diff --git a/v1/wd_dh.c b/v1/wd_dh.c
index d11d5cd..49f52d9 100644
--- a/v1/wd_dh.c
+++ b/v1/wd_dh.c
@@ -371,6 +371,7 @@ int wcrypto_dh_poll(struct wd_queue *q, unsigned int num)
 	struct wcrypto_dh_msg *resp = NULL;
 	struct wcrypto_dh_ctx *ctx;
 	struct wcrypto_cb_tag *tag;
+	unsigned int tmp = num;
 	int count = 0;
 	int ret;
 
@@ -394,7 +395,7 @@ int wcrypto_dh_poll(struct wd_queue *q, unsigned int num)
 		ctx->setup.cb(resp, tag->tag);
 		wd_put_cookies(&ctx->pool, (void **)&tag, 1);
 		resp = NULL;
-	} while (--num);
+	} while (--tmp);
 
 	return count;
 }
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index 71e5747..14df736 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -422,6 +422,7 @@ int wcrypto_digest_poll(struct wd_queue *q, unsigned int num)
 	struct wcrypto_digest_msg *digest_resp = NULL;
 	struct wcrypto_digest_ctx *ctx;
 	struct wcrypto_digest_tag *tag;
+	unsigned int tmp = num;
 	int count = 0;
 	int ret;
 
@@ -451,7 +452,7 @@ int wcrypto_digest_poll(struct wd_queue *q, unsigned int num)
 		ctx = tag->wcrypto_tag.ctx;
 		ctx->setup.cb(digest_resp, tag->wcrypto_tag.tag);
 		wd_put_cookies(&ctx->pool, (void **)&tag, 1);
-	} while (--num);
+	} while (--tmp);
 
 	return count;
 }
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index dfa5192..58dabfc 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -180,8 +180,9 @@ static int trans_to_binpad(char *dst, const char *src,
 	return WD_SUCCESS;
 }
 
-static void wd_memset_zero(void *data, __u32 size)
+static void wd_memset_zero(void *data, __u32 mem_size)
 {
+	__u32 size = mem_size;
 	char *s = data;
 
 	if (unlikely(!s))
@@ -1620,6 +1621,7 @@ static int ecc_poll(struct wd_queue *q, unsigned int num)
 	struct wcrypto_ecc_msg *resp = NULL;
 	struct wcrypto_ecc_ctx *ctx;
 	struct wcrypto_cb_tag *tag;
+	unsigned int tmp = num;
 	int count = 0;
 	int ret;
 
@@ -1638,7 +1640,7 @@ static int ecc_poll(struct wd_queue *q, unsigned int num)
 		ctx->setup.cb(resp, tag->tag);
 		wd_put_cookies(&ctx->pool, (void **)&tag, 1);
 		resp = NULL;
-	} while (--num);
+	} while (--tmp);
 
 	return count;
 }
diff --git a/v1/wd_rng.c b/v1/wd_rng.c
index d9d420e..7b3bda3 100644
--- a/v1/wd_rng.c
+++ b/v1/wd_rng.c
@@ -160,6 +160,7 @@ int wcrypto_rng_poll(struct wd_queue *q, unsigned int num)
 	struct wcrypto_rng_msg *resp = NULL;
 	struct wcrypto_rng_ctx *ctx;
 	struct wcrypto_cb_tag *tag;
+	unsigned int tmp = num;
 	int count = 0;
 	int ret;
 
@@ -184,7 +185,7 @@ int wcrypto_rng_poll(struct wd_queue *q, unsigned int num)
 		ctx->setup.cb(resp, tag->tag);
 		wd_put_cookies(&ctx->pool, (void **)&tag, 1);
 		resp = NULL;
-	} while (--num);
+	} while (--tmp);
 
 	return count;
 }
diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c
index 4de249f..6ba29d7 100644
--- a/v1/wd_rsa.c
+++ b/v1/wd_rsa.c
@@ -1034,6 +1034,7 @@ int wcrypto_rsa_poll(struct wd_queue *q, unsigned int num)
 	struct wcrypto_rsa_msg *resp = NULL;
 	struct wcrypto_rsa_ctx *ctx;
 	struct wcrypto_cb_tag *tag;
+	unsigned int tmp = num;
 	int count = 0;
 	int ret;
 
@@ -1056,7 +1057,7 @@ int wcrypto_rsa_poll(struct wd_queue *q, unsigned int num)
 		ctx->setup.cb(resp, tag->tag);
 		wd_put_cookies(&ctx->pool, (void **)&tag, 1);
 		resp = NULL;
-	} while (--num);
+	} while (--tmp);
 
 	return count;
 }
diff --git a/v1/wd_sgl.c b/v1/wd_sgl.c
index 9bdbe92..dffbf12 100644
--- a/v1/wd_sgl.c
+++ b/v1/wd_sgl.c
@@ -512,32 +512,33 @@ struct wd_sgl *wd_alloc_sgl(void *pool, __u32 size)
 void wd_free_sgl(void *pool, struct wd_sgl *sgl)
 {
 	struct wd_sglpool *p = pool;
+	struct wd_sgl *tmp = sgl;
 	struct wd_sgl *next;
 	int i;
 
-	if (unlikely(!p || !sgl || !p->sgl_pool)) {
+	if (unlikely(!p || !tmp || !p->sgl_pool)) {
 		WD_ERR("pool or sgl or p->sgl_pool is null!\n");
 		return;
 	}
 
-	if (unlikely((uintptr_t)sgl->next & FLAG_MERGED_SGL)) {
+	if (unlikely((uintptr_t)tmp->next & FLAG_MERGED_SGL)) {
 		WD_ERR("This is a merged sgl, u cannot free it!\n");
 		return;
 	}
 
 	do {
-		next = sgl->next;
-		sgl->buf_sum = sgl->buf_num;
-		sgl->next = NULL;
-		sgl->sum_data_bytes = 0;
-		for (i = 0; i < sgl->buf_num; i++)
-			sgl->sge[i].data_len = 0;
+		next = tmp->next;
+		tmp->buf_sum = tmp->buf_num;
+		tmp->next = NULL;
+		tmp->sum_data_bytes = 0;
+		for (i = 0; i < tmp->buf_num; i++)
+			tmp->sge[i].data_len = 0;
 
 		/* have to update current 'wd_sgl' before free it */
-		wd_free_blk(p->sgl_pool, sgl);
+		wd_free_blk(p->sgl_pool, tmp);
 		wd_get_free_blk_num(p->sgl_pool, &p->free_sgl_num);
 		next = (struct wd_sgl *)((uintptr_t)next & (~FLAG_MERGED_SGL));
-		sgl = next;
+		tmp = next;
 	} while (next);
 }
 
@@ -577,12 +578,16 @@ int wd_sgl_merge(struct wd_sgl *dst_sgl, struct wd_sgl *src_sgl)
 	return WD_SUCCESS;
 }
 
-static void sgl_cp_to_pbuf(struct wd_sgl *sgl, int strtsg, int strtad,
-			   void *pbuf, size_t size)
+static void sgl_cp_to_pbuf(struct wd_sgl *src_sgl, int start_sg, int strtad,
+			   void *buf, size_t sgl_sz)
 {
-	__u32 sz = sgl->pool->setup.buf_size;
-	__u32 act_sz = MIN(size, sz - strtad);
+	__u32 sz = src_sgl->pool->setup.buf_size;
+	__u32 act_sz = MIN(sgl_sz, sz - strtad);
+	struct wd_sgl *sgl = src_sgl;
+	int strtsg = start_sg;
+	size_t size = sgl_sz;
 	struct wd_sgl *next;
+	void *pbuf = buf;
 	int i;
 
 	next = (struct wd_sgl *)((uintptr_t)sgl->next & (~FLAG_MERGED_SGL));
@@ -654,12 +659,16 @@ int wd_sgl_cp_to_pbuf(struct wd_sgl *sgl, size_t offset, void *pbuf, size_t size
 	return 0;
 }
 
-static void sgl_cp_from_pbuf(struct wd_sgl *sgl, int strtsg, int strtad,
-			     void *pbuf, size_t size)
+static void sgl_cp_from_pbuf(struct wd_sgl *dst_sgl, int start_sg, int strtad,
+			     void *buf, size_t mem_sz)
 {
-	__u32 sz = sgl->pool->setup.buf_size;
-	__u32 act_sz = MIN(size, sz - strtad);
+	__u32 sz = dst_sgl->pool->setup.buf_size;
+	__u32 act_sz = MIN(mem_sz, sz - strtad);
+	struct wd_sgl *sgl = dst_sgl;
+	int strtsg = start_sg;
+	size_t size = mem_sz;
 	struct wd_sgl *next;
+	void *pbuf = buf;
 	int i;
 
 	next = (struct wd_sgl *)((uintptr_t)sgl->next & (~FLAG_MERGED_SGL));
@@ -766,18 +775,19 @@ void wd_sgl_iova_unmap(void *pool, void *sgl_iova, struct wd_sgl *sgl)
 
 void *wd_get_last_sge_buf(struct wd_sgl *sgl)
 {
+	struct wd_sgl *tmp = sgl;
 	uintptr_t next;
 
-	if (unlikely(!sgl || !sgl->buf_num)) {
+	if (unlikely(!tmp || !tmp->buf_num)) {
 		WD_ERR("sgl or buf_num in sgl is null!\n");
 		return NULL;
 	}
 
-	next = (uintptr_t)sgl->next & (~FLAG_MERGED_SGL);
+	next = (uintptr_t)tmp->next & (~FLAG_MERGED_SGL);
 	if (next)
-		sgl = (struct wd_sgl *)next;
+		tmp = (struct wd_sgl *)next;
 
-	return sgl->sge[sgl->buf_num - 1].buf;
+	return tmp->sge[tmp->buf_num - 1].buf;
 }
 
 void *wd_get_first_sge_buf(struct wd_sgl *sgl)
diff --git a/wd_aead.c b/wd_aead.c
index 36ca842..b3e7b41 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -639,6 +639,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 	struct wd_aead_msg resp_msg, *msg;
 	struct wd_aead_req *req;
 	__u64 recv_count = 0;
+	__u32 tmp = expt;
 	int ret;
 
 	if (!count) {
@@ -678,7 +679,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 		wd_put_msg_to_pool(&wd_aead_setting.pool,
 					       idx, resp_msg.tag);
 		*count = recv_count;
-	} while (--expt);
+	} while (--tmp);
 
 	return ret;
 }
diff --git a/wd_cipher.c b/wd_cipher.c
index 43e83b7..b074dd2 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -548,6 +548,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 	struct wd_cipher_msg resp_msg, *msg;
 	struct wd_cipher_req *req;
 	__u64 recv_count = 0;
+	__u32 tmp = expt;
 	int ret;
 
 	if (unlikely(!count)) {
@@ -588,7 +589,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 		wd_put_msg_to_pool(&wd_cipher_setting.pool, idx,
 				   resp_msg.tag);
 		*count = recv_count;
-	} while (--expt);
+	} while (--tmp);
 
 	return ret;
 }
diff --git a/wd_comp.c b/wd_comp.c
index cc8f192..502bc23 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -187,6 +187,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 	struct wd_comp_msg *msg;
 	struct wd_comp_req *req;
 	__u64 recv_count = 0;
+	__u32 tmp = expt;
 	int ret;
 
 	if (unlikely(!count)) {
@@ -228,7 +229,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 		/* free msg cache to msg_pool */
 		wd_put_msg_to_pool(&wd_comp_setting.pool, idx, resp_msg.tag);
 		*count = recv_count;
-	} while (--expt);
+	} while (--tmp);
 
 	return ret;
 }
@@ -545,14 +546,16 @@ int wd_do_comp_sync2(handle_t h_sess, struct wd_comp_req *req)
 	return 0;
 }
 
-static unsigned int bit_reverse(register unsigned int x)
+static unsigned int bit_reverse(register unsigned int target)
 {
+	register unsigned int x = target;
+
 	x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
 	x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
 	x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
 	x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
 
-	return((x >> 16) | (x << 16));
+	return ((x >> 16) | (x << 16));
 }
 
 /**
diff --git a/wd_dh.c b/wd_dh.c
index c16701d..2b02e3c 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -365,6 +365,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 	struct wd_dh_req *req;
 	struct wd_dh_msg *msg;
 	__u32 rcv_cnt = 0;
+	__u32 tmp = expt;
 	int ret;
 
 	if (unlikely(!count)) {
@@ -405,7 +406,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 		req->cb(req);
 		wd_put_msg_to_pool(&wd_dh_setting.pool, idx, rcv_msg.tag);
 		*count = rcv_cnt;
-	} while (--expt);
+	} while (--tmp);
 
 	return ret;
 }
diff --git a/wd_digest.c b/wd_digest.c
index d5602ef..1d4e4cc 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -444,6 +444,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 	struct wd_digest_msg recv_msg, *msg;
 	struct wd_digest_req *req;
 	__u32 recv_cnt = 0;
+	__u32 tmp = expt;
 	int ret;
 
 	if (unlikely(!count)) {
@@ -486,7 +487,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 		wd_put_msg_to_pool(&wd_digest_setting.pool, idx,
 				   recv_msg.tag);
 		*count = recv_cnt;
-	} while (--expt);
+	} while (--tmp);
 
 	return ret;
 }
diff --git a/wd_ecc.c b/wd_ecc.c
index 9005103..c6bd111 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -301,10 +301,11 @@ static __u32 get_hash_bytes(__u8 type)
 	return val;
 }
 
-static void init_dtb_param(void *dtb, char *start,
+static void init_dtb_param(void *dtb, char *str,
 			   __u32 dsz, __u32 bsz, __u32 num)
 {
 	struct wd_dtb *tmp = dtb;
+	char *start = str;
 	int i = 0;
 
 	while (i++ < num) {
@@ -2190,6 +2191,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 	struct wd_ctx_internal *ctx;
 	struct wd_ecc_req *req;
 	__u32 rcv_cnt = 0;
+	__u32 tmp = expt;
 	int ret;
 
 	if (unlikely(!count)) {
@@ -2230,7 +2232,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
 		req->cb(req);
 		wd_put_msg_to_pool(&wd_ecc_setting.pool, idx, recv_msg.tag);
 		*count = rcv_cnt;
-	} while (--expt);
+	} while (--tmp);
 
 	return ret;
 }
diff --git a/wd_mempool.c b/wd_mempool.c
index 03df19a..d9259de 100644
--- a/wd_mempool.c
+++ b/wd_mempool.c
@@ -174,8 +174,9 @@ struct mempool {
  *
  * Undefined if no bit exists, so code should check against 0 first.
  */
-static __always_inline unsigned long wd_ffs(unsigned long word)
+static __always_inline unsigned long wd_ffs(unsigned long target_word)
 {
+	unsigned long word = target_word;
 	int num = 0;
 
 	if ((word & 0xffffffff) == 0) {
@@ -234,9 +235,11 @@ static void destroy_bitmap(struct bitmap *bm)
 }
 
 static unsigned long _find_next_bit(unsigned long *map, unsigned long bits,
-				    unsigned long start, unsigned long invert)
+				    unsigned long begin_position,
+				    unsigned long invert)
 {
 	unsigned long tmp, mask, next_bit;
+	unsigned long start = begin_position;
 
 	if (start >= bits)
 		return bits;
@@ -888,15 +891,16 @@ static void uninit_mempool(struct mempool *mp)
 handle_t wd_mempool_create(size_t size, int node)
 {
 	struct mempool *mp;
+	size_t tmp = size;
 	int ret;
 
-	if (!size || node < 0 || node > numa_max_node()) {
-		WD_ERR("invalid: numa node is %d, size is %ld!\n", node, size);
+	if (!tmp || node < 0 || node > numa_max_node()) {
+		WD_ERR("invalid: numa node is %d, size is %ld!\n", node, tmp);
 		return (handle_t)(-WD_EINVAL);
 	}
 
-	if (WD_MEMPOOL_SIZE_MASK & size)
-		size += WD_MEMPOOL_BLOCK_SIZE - (WD_MEMPOOL_SIZE_MASK & size);
+	if (WD_MEMPOOL_SIZE_MASK & tmp)
+		tmp += WD_MEMPOOL_BLOCK_SIZE - (WD_MEMPOOL_SIZE_MASK & tmp);
 
 	mp = calloc(1, sizeof(*mp));
 	if (!mp) {
@@ -905,7 +909,7 @@ handle_t wd_mempool_create(size_t size, int node)
 	}
 
 	mp->node = node;
-	mp->size = size;
+	mp->size = tmp;
 	mp->blk_size = WD_MEMPOOL_BLOCK_SIZE;
 
 	ret = alloc_mem_from_hugepage(mp);
diff --git a/wd_util.c b/wd_util.c
index 43cedc6..8bda8d7 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -162,12 +162,13 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in)
 
 void wd_memset_zero(void *data, __u32 size)
 {
+	__u32 tmp = size;
 	char *s = data;
 
 	if (!s)
 		return;
 
-	while (size--)
+	while (tmp--)
 		*s++ = 0;
 }
 
-- 
2.27.0

