From 023d3890ce1ba9bd9b4ce5f2f1f2a60a8219e015 Mon Sep 17 00:00:00 2001
From: veega2022 <zhuweijia@huawei.com>
Date: Tue, 12 Nov 2024 17:58:25 +0800
Subject: [PATCH 06/27] hikptool: Resolve the review problems found in the R&D
 self-check.

Code review comments are rectified.

Signed-off-by: veega2022 <zhuweijia@huawei.com>
---
 cxl/func_lib/cxl_func/cxl_feature.c          | 12 ++-
 cxl/func_lib/cxl_func/cxl_feature.h          |  1 +
 hikp_init_main.c                             |  3 +-
 libhikptdev/src/rciep/hikpt_rciep.c          | 12 ++-
 libhikptdev/src/rciep/hikpt_rciep.h          |  1 +
 net/nic/nic_mac/hikp_nic_xsfp.c              |  8 ++
 net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c |  2 +-
 net/nic/nic_ppp/hikp_nic_ppp.c               |  8 +-
 net/ub/ub_bp/hikp_ub_bp.c                    |  3 +-
 net/ub/ub_crd/hikp_ub_crd.c                  |  6 +-
 net/ub/ub_dfx/hikp_ub_dfx.c                  | 26 +++---
 net/ub/ub_ppp/hikp_unic_ppp.c                | 54 +++++++++---
 net/ub/ub_ppp/hikp_unic_ppp.h                |  2 +-
 ossl/ossl_user_linux.c                       |  4 +-
 pcie/func_lib/osal/os_common.c               | 29 -------
 pcie/func_lib/osal/os_common.h               | 22 ++---
 pcie/func_lib/pcie_func/pcie_link_ltssm.c    | 87 +++++++++-----------
 pcie/func_lib/pcie_func/pcie_reg_dump.c      | 24 +++---
 pcie/func_lib/pcie_func/pcie_reg_read.c      |  6 +-
 pcie/func_lib/pcie_func/pcie_statistics.c    | 54 ++++++------
 pcie/usr_cmd/cmd_analysis/pcie_cmd_dumpreg.c |  2 +-
 sas/sas_func/sas_analy_queue.c               |  6 +-
 sas/sas_func/sas_analy_queue.h               |  2 +
 sas/sas_func/sas_common.h                    |  4 +
 sas/sas_func/sas_dump_reg.c                  |  2 +-
 sas/sas_func/sas_read_dev.c                  |  4 +-
 sas/sas_func/sas_read_dqe.c                  |  4 +-
 sas/sas_func/sas_read_errcode.c              | 16 ++--
 sata/sata_func/sata_dump_reg.c               |  2 +-
 tool_lib/op_logs.c                           | 14 ++--
 tool_lib/tool_lib.c                          | 12 +--
 31 files changed, 226 insertions(+), 206 deletions(-)
 delete mode 100644 pcie/func_lib/osal/os_common.c

diff --git a/cxl/func_lib/cxl_func/cxl_feature.c b/cxl/func_lib/cxl_func/cxl_feature.c
index cd41b09..12fadbd 100644
--- a/cxl/func_lib/cxl_func/cxl_feature.c
+++ b/cxl/func_lib/cxl_func/cxl_feature.c
@@ -342,7 +342,7 @@ int cxl_reg_show_execute(uint32_t port_id, uint32_t mode_code, uint32_t cmd_type
 	uint32_t i;
 	size_t data_unit_len;
 	struct hikp_cmd_header req_header;
-	struct hikp_cmd_ret *cmd_ret;
+	struct hikp_cmd_ret *cmd_ret = NULL;
 	struct cxl_cmd_paras_in req_para;
 	struct cxl_out_data *data_head = NULL;
 	struct cxl_data_unit *data_unit_buf = NULL;
@@ -359,8 +359,14 @@ int cxl_reg_show_execute(uint32_t port_id, uint32_t mode_code, uint32_t cmd_type
 		return ret;
 	}
 
+	if (cmd_ret->rsp_data_num < CXL_DATA_OFFSET) {
+		printf("cxl_cmd mode_code: %u cmd_type: %u,"
+		       "The value of rsp data num is less than 2, rsp data num: %u\n",
+		       mode_code, cmd_type, cmd_ret->rsp_data_num);
+		free(cmd_ret);
+		return -EINVAL;
+	}
 	data_head = (struct cxl_out_data *)cmd_ret->rsp_data;
-	data_unit_buf = (struct cxl_data_unit *)(cmd_ret->rsp_data + data_head->data_offset);
 	data_unit_len = data_head->length / sizeof(struct cxl_data_unit);
 
 	ret = cxl_data_unit_buf_check(data_head->data_offset, data_unit_len, cmd_ret->rsp_data_num);
@@ -369,6 +375,8 @@ int cxl_reg_show_execute(uint32_t port_id, uint32_t mode_code, uint32_t cmd_type
 		return ret;
 	}
 
+	data_unit_buf = (struct cxl_data_unit *)(cmd_ret->rsp_data + data_head->data_offset);
+
 	for (i = 0; i < (sizeof(g_prtf) / sizeof((g_prtf)[0])); i++) {
 		if (mode_code == g_prtf[i].mode_code &&
 		    cmd_type == g_prtf[i].cmd_type && g_prtf[i].cxl_prt_handle) {
diff --git a/cxl/func_lib/cxl_func/cxl_feature.h b/cxl/func_lib/cxl_func/cxl_feature.h
index 4d30ebe..3ac6f75 100644
--- a/cxl/func_lib/cxl_func/cxl_feature.h
+++ b/cxl/func_lib/cxl_func/cxl_feature.h
@@ -28,6 +28,7 @@
 #define CXL_HDM_CNT_EACH_PORT 2
 #define CXL_DATA_UNIT_SIZE 2  // reg addr + data
 #define CXL_MEM_HEADER_LOG_UNIT 4
+#define CXL_DATA_OFFSET 2
 
 enum cxl_cmd_type {
 	CXL_CPA = 0,
diff --git a/hikp_init_main.c b/hikp_init_main.c
index 4629b40..e159ad9 100644
--- a/hikp_init_main.c
+++ b/hikp_init_main.c
@@ -92,7 +92,8 @@ static int parse_and_init_cmd(const char *arg)
 		if (strnlen(cmd_ptr->name, MAX_CMD_LEN) != strnlen(arg, MAX_CMD_LEN))
 			continue;
 
-		if (strncmp(arg, cmd_ptr->name, strnlen(cmd_ptr->name, MAX_CMD_LEN - 1) + 1) == 0) {
+		if ((strncmp(arg, cmd_ptr->name,
+		    strnlen(cmd_ptr->name, MAX_CMD_LEN - 1) + 1) == 0) && cmd_ptr->cmd_init) {
 			g_tool.p_major_cmd.cmd_ptr = cmd_ptr;
 			cmd_ptr->cmd_init();
 			return 0;
diff --git a/libhikptdev/src/rciep/hikpt_rciep.c b/libhikptdev/src/rciep/hikpt_rciep.c
index 75ec224..0210f3d 100644
--- a/libhikptdev/src/rciep/hikpt_rciep.c
+++ b/libhikptdev/src/rciep/hikpt_rciep.c
@@ -208,8 +208,11 @@ static int hikp_multi_round_interact(struct hikp_cmd_ret **cmd_ret, uint32_t sta
 		return -EINVAL;
 	}
 
-	p_cmd_ret = (struct hikp_cmd_ret *)malloc(sizeof(struct hikp_cmd_ret) +
-		    rsp_num * REP_DATA_BLK_SIZE);
+	/* By default, the memory is applied for based on the supported maximum length.
+	 * The memory buffer is converted into the corresponding data structure inside the module.
+	 */
+	p_cmd_ret = (struct hikp_cmd_ret *)calloc(1,
+		    (sizeof(struct hikp_cmd_ret) + HIKP_RSP_DATA_SIZE_MAX));
 	if (p_cmd_ret == NULL) {
 		printf("response memory malloc fail.\n");
 		return -ENOMEM;
@@ -509,7 +512,8 @@ out_free_iep:
 static void hikp_munmap(void)
 {
 	g_unmap_flag = 1;
-	munmap((void *)g_hikp_req, sizeof(union hikp_space_req));
+	if (munmap((void *)g_hikp_req, sizeof(union hikp_space_req)) == -1)
+		printf("failed to munmap, errno %d.\n", errno);
 	g_hikp_req = NULL;
 	g_hikp_rsp = NULL;
 }
@@ -538,7 +542,7 @@ int hikp_dev_init(void)
 
 	g_hikp_req = (union hikp_space_req *)mmap(0, sizeof(union hikp_space_req),
 		     PROT_READ | PROT_WRITE, MAP_SHARED, g_iep_fd, 0);
-	if (!g_hikp_req) {
+	if (g_hikp_req == MAP_FAILED) {
 		printf("failed to mmap %s.\n", iep);
 		ret = -errno;
 		goto out_close_fd;
diff --git a/libhikptdev/src/rciep/hikpt_rciep.h b/libhikptdev/src/rciep/hikpt_rciep.h
index 296d235..c64e4dd 100644
--- a/libhikptdev/src/rciep/hikpt_rciep.h
+++ b/libhikptdev/src/rciep/hikpt_rciep.h
@@ -43,6 +43,7 @@
 #define WAIT_CPL_MAX_MS 8000
 
 #define REP_DATA_BLK_SIZE		sizeof(uint32_t)
+#define HIKP_RSP_DATA_SIZE_MAX		(HIKP_RSP_ALL_DATA_MAX * REP_DATA_BLK_SIZE)
 
 enum {
 	HIKP_RESOURCE_DIR,
diff --git a/net/nic/nic_mac/hikp_nic_xsfp.c b/net/nic/nic_mac/hikp_nic_xsfp.c
index 70ed589..a1294a8 100644
--- a/net/nic/nic_mac/hikp_nic_xsfp.c
+++ b/net/nic/nic_mac/hikp_nic_xsfp.c
@@ -602,6 +602,14 @@ static int hikp_xsfp_get_raw_data(uint8_t *buf, uint32_t size, uint32_t blk_num)
 			return ret;
 		}
 
+		if (cmd_resp->rsp_data_num == 0) {
+			HIKP_ERROR_PRINT("get eeprom data rsp_data_num %u error\n",
+					 cmd_resp->rsp_data_num);
+			free(cmd_resp);
+			cmd_resp = NULL;
+			return -EINVAL;
+		}
+
 		len = HIKP_MIN(left_size, (cmd_resp->rsp_data_num * sizeof(uint32_t)));
 		memcpy(buf + offset, (uint8_t *)(cmd_resp->rsp_data), len);
 		left_size -= len;
diff --git a/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c b/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c
index 307d336..56b8257 100644
--- a/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c
+++ b/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c
@@ -74,7 +74,7 @@ static void hikp_nic_notify_pkt_show(const struct nic_notify_pkt_info *info)
 static void hikp_nic_notify_pkt_cmd_execute(struct major_cmd_ctrl *self)
 {
 	struct bdf_t *bdf = &g_notify_pkt_target.bdf;
-	struct nic_notify_pkt_info info;
+	struct nic_notify_pkt_info info = {0};
 
 	self->err_no = hikp_nic_notify_pkt_query(self, bdf, &info);
 	if (self->err_no)
diff --git a/net/nic/nic_ppp/hikp_nic_ppp.c b/net/nic/nic_ppp/hikp_nic_ppp.c
index 7968ac3..4dbe8d6 100644
--- a/net/nic/nic_ppp/hikp_nic_ppp.c
+++ b/net/nic/nic_ppp/hikp_nic_ppp.c
@@ -129,9 +129,9 @@ static void hikp_nic_ppp_get_overflow_mac(struct nic_mac_tbl *of_tbl, struct nic
 
 static void hikp_nic_ppp_show_key_mem(struct nic_mac_tbl *tbl, bool is_key_mem)
 {
+	char mac_str[HIKP_NIC_ETH_ADDR_FMT_SIZE] = {0};
 	struct mac_vlan_uc_tbl *uc_tbl = &tbl->uc_tbl;
 	struct mac_vlan_mc_tbl *mc_tbl = &tbl->mc_tbl;
-	char mac_str[HIKP_NIC_ETH_ADDR_FMT_SIZE];
 	struct mac_vlan_uc_entry *uc_entry;
 	struct mac_vlan_mc_entry *mc_entry;
 	uint32_t idx;
@@ -178,7 +178,7 @@ static void hikp_nic_ppp_show_key_mem(struct nic_mac_tbl *tbl, bool is_key_mem)
 static void hikp_nic_ppp_show_func_uc_mac_addr(struct mac_vlan_uc_tbl *uc_tbl,
 					       const struct bdf_t *bdf, uint16_t func_id)
 {
-	char mac_str[HIKP_NIC_ETH_ADDR_FMT_SIZE];
+	char mac_str[HIKP_NIC_ETH_ADDR_FMT_SIZE] = {0};
 	struct mac_vlan_uc_entry *uc_entry;
 	uint8_t pf_id;
 	uint8_t vf_id;
@@ -202,7 +202,7 @@ static void hikp_nic_ppp_show_func_uc_mac_addr(struct mac_vlan_uc_tbl *uc_tbl,
 static void hikp_nic_ppp_show_func_mc_mac_addr(struct mac_vlan_mc_tbl *mc_tbl,
 					       const struct bdf_t *bdf, uint16_t func_id)
 {
-	char mac_str[HIKP_NIC_ETH_ADDR_FMT_SIZE];
+	char mac_str[HIKP_NIC_ETH_ADDR_FMT_SIZE] = {0};
 	struct mac_vlan_mc_entry *mc_entry;
 	uint16_t abs_func_id;
 	uint8_t offset;
@@ -394,7 +394,7 @@ static void hikp_nic_ppp_show_vlan_tbl(const void *data)
 static void hikp_nic_ppp_show_manager_tbl(const void *data)
 {
 	struct nic_mng_tbl *tbl = (struct nic_mng_tbl *)data;
-	char mac_str[HIKP_NIC_ETH_ADDR_FMT_SIZE];
+	char mac_str[HIKP_NIC_ETH_ADDR_FMT_SIZE] = {0};
 	struct manager_entry *entry;
 	uint32_t i;
 
diff --git a/net/ub/ub_bp/hikp_ub_bp.c b/net/ub/ub_bp/hikp_ub_bp.c
index 70a9a4b..f5f50ff 100644
--- a/net/ub/ub_bp/hikp_ub_bp.c
+++ b/net/ub/ub_bp/hikp_ub_bp.c
@@ -41,7 +41,7 @@ static void hikp_ub_bp_info_show(const struct ub_bp_rsp *info)
 {
 	int bp_val_offset;
 
-	printf("%-28s : %u\n", "mac id", info->mac_id);
+	printf("%-28s : %hhu\n", "mac id", info->mac_id);
 	printf("%-28s : ", "back pressure status");
 
 	for (bp_val_offset = MAX_VL_NUM; bp_val_offset >= 0; bp_val_offset--) {
@@ -50,7 +50,6 @@ static void hikp_ub_bp_info_show(const struct ub_bp_rsp *info)
 	printf("\n");
 }
 
-
 static int hikp_ub_query_bp(const struct bdf_t *bdf)
 {
 	struct hikp_cmd_header header = { 0 };
diff --git a/net/ub/ub_crd/hikp_ub_crd.c b/net/ub/ub_crd/hikp_ub_crd.c
index 0e47b5b..91e1cb7 100644
--- a/net/ub/ub_crd/hikp_ub_crd.c
+++ b/net/ub/ub_crd/hikp_ub_crd.c
@@ -37,8 +37,8 @@ static int hikp_ub_crd_target(struct major_cmd_ctrl *self, const char *argv)
 	return 0;
 }
 
-static int hikp_ub_show_crd(uint32_t off, struct ub_crd_rsp *crd_rsp, uint32_t num_rows,
-			    char const *crds[][2])
+static uint32_t hikp_ub_show_crd(uint32_t off, struct ub_crd_rsp *crd_rsp, uint32_t num_rows,
+				 char const *crds[][2])
 {
 	int reg_index;
 	int i;
@@ -63,7 +63,7 @@ static int hikp_ub_query_crd(void)
 	struct ub_crd_req_para req_data = { 0 };
 	struct hikp_cmd_ret *cmd_ret = NULL;
 	struct ub_crd_rsp *crd_rsp = NULL;
-	int offset;
+	uint32_t offset;
 
 	char const *init_crds[][2] = {
 		{"CFG_REMOTE_ICRD", "CFG_REMOTE_LCRD"},
diff --git a/net/ub/ub_dfx/hikp_ub_dfx.c b/net/ub/ub_dfx/hikp_ub_dfx.c
index c50f555..00205fe 100644
--- a/net/ub/ub_dfx/hikp_ub_dfx.c
+++ b/net/ub/ub_dfx/hikp_ub_dfx.c
@@ -13,6 +13,7 @@
 
 #include "tool_cmd.h"
 #include "hikp_net_lib.h"
+#include "hikpt_rciep.h"
 #include "hikp_ub_dfx.h"
 
 struct ub_dfx_param g_ub_dfx_param = { 0 };
@@ -100,6 +101,7 @@ static int hikp_ub_get_first_blk_dfx(struct ub_dfx_rsp_head *rsp_head, uint32_t
 {
 	struct ub_dfx_rsp *dfx_rsp = NULL;
 	struct hikp_cmd_ret *cmd_ret;
+	uint32_t rsp_data_size;
 	int ret;
 
 	ret = hikp_ub_dfx_get_blk_data(&cmd_ret, 0, g_ub_dfx_param.sub_cmd_code);
@@ -122,11 +124,13 @@ static int hikp_ub_get_first_blk_dfx(struct ub_dfx_rsp_head *rsp_head, uint32_t
 		goto err_out;
 	}
 
-	if (rsp_head->cur_blk_size > *max_dfx_size) {
+	rsp_data_size = cmd_ret->rsp_data_num * REP_DATA_BLK_SIZE;
+	if (rsp_data_size - sizeof(dfx_rsp->rsp_head) < rsp_head->cur_blk_size ||
+	    *max_dfx_size < rsp_head->cur_blk_size) {
+		HIKP_ERROR_PRINT("blk0 reg_data copy size error, rsp data size: %u, data size: %hhu, max size: %u\n",
+				 rsp_data_size, rsp_head->cur_blk_size, *max_dfx_size);
 		free(*reg_data);
 		*reg_data = NULL;
-		HIKP_ERROR_PRINT("blk0 reg_data copy size error, data size: 0x%x, max size: 0x%x\n",
-				 rsp_head->cur_blk_size, *max_dfx_size);
 		ret = -EINVAL;
 		goto err_out;
 	}
@@ -145,6 +149,7 @@ static int hikp_ub_get_blk_dfx(struct ub_dfx_rsp_head *rsp_head, uint32_t blk_id
 {
 	struct ub_dfx_rsp *dfx_rsp = NULL;
 	struct hikp_cmd_ret *cmd_ret;
+	uint32_t rsp_data_size;
 	int ret;
 
 	ret = hikp_ub_dfx_get_blk_data(&cmd_ret, blk_id, g_ub_dfx_param.sub_cmd_code);
@@ -153,10 +158,11 @@ static int hikp_ub_get_blk_dfx(struct ub_dfx_rsp_head *rsp_head, uint32_t blk_id
 
 	dfx_rsp = (struct ub_dfx_rsp *)(cmd_ret->rsp_data);
 	*rsp_head = dfx_rsp->rsp_head;
-	if (rsp_head->cur_blk_size > *max_dfx_size) {
-		HIKP_ERROR_PRINT("blk%u reg_data copy size error, "
-				 "data size: 0x%x, max size: 0x%x\n",
-				 blk_id, rsp_head->cur_blk_size, *max_dfx_size);
+	rsp_data_size = cmd_ret->rsp_data_num * REP_DATA_BLK_SIZE;
+	if (rsp_data_size - sizeof(dfx_rsp->rsp_head) < rsp_head->cur_blk_size ||
+	    rsp_head->cur_blk_size > *max_dfx_size) {
+		HIKP_ERROR_PRINT("blk%u reg_data copy size error, rsp data size: %u, data size: %hhu, max size: %u\n",
+				 blk_id, rsp_data_size, rsp_head->cur_blk_size, *max_dfx_size);
 		ret = -EINVAL;
 		goto err_out;
 	}
@@ -194,7 +200,7 @@ static void hikp_ub_dfx_print_type_head(uint8_t type_id, uint8_t *last_type_id)
 		if (is_type_found(type_id, &index))
 			printf("type name: %s\n\n", g_dfx_type_parse[index].type_name);
 		else
-			HIKP_WARN_PRINT("type name: unknown type, type id is %u\n\n", type_id);
+			HIKP_WARN_PRINT("type name: unknown type, type id is %hhu\n\n", type_id);
 
 		*last_type_id = type_id;
 	}
@@ -244,7 +250,7 @@ static void hikp_ub_dfx_print(const struct ub_dfx_rsp_head *rsp_head, uint32_t *
 	for (i = 0; i < rsp_head->total_type_num; i++) {
 		type_head = (struct ub_dfx_type_head *)ptr;
 		if (type_head->type_id == INCORRECT_REG_TYPE) {
-			HIKP_ERROR_PRINT("No.%u type is incorrect reg type\n", i + 1u);
+			HIKP_ERROR_PRINT("No.%u type is incorrect reg type\n", (uint32_t)(i + 1u));
 			break;
 		}
 		hikp_ub_dfx_print_type_head(type_head->type_id, &last_type_id);
@@ -254,7 +260,7 @@ static void hikp_ub_dfx_print(const struct ub_dfx_rsp_head *rsp_head, uint32_t *
 		} else if (type_head->bit_width == WIDTH_64_BIT) {
 			hikp_ub_dfx_print_b64((uint32_t)type_head->reg_num, ptr);
 		} else {
-			HIKP_ERROR_PRINT("type%u's bit width error.\n", type_head->type_id);
+			HIKP_ERROR_PRINT("type%hhu's bit width error.\n", type_head->type_id);
 			break;
 		}
 		ptr += (uint32_t)type_head->reg_num * WORD_NUM_PER_REG;
diff --git a/net/ub/ub_ppp/hikp_unic_ppp.c b/net/ub/ub_ppp/hikp_unic_ppp.c
index bf0c026..2164f04 100644
--- a/net/ub/ub_ppp/hikp_unic_ppp.c
+++ b/net/ub/ub_ppp/hikp_unic_ppp.c
@@ -16,6 +16,7 @@
 #include <sys/types.h>
 #include <arpa/inet.h>
 #include <unistd.h>
+#include "hikpt_rciep.h"
 #include "hikp_unic_ppp.h"
 
 static struct hikp_unic_ppp_hw_resources g_unic_ppp_hw_res = { 0 };
@@ -86,6 +87,7 @@ static int hikp_unic_ppp_get_blk(struct hikp_cmd_header *req_header,
 {
 	struct hikp_cmd_ret *cmd_ret;
 	struct unic_ppp_rsp *rsp;
+	uint32_t rsp_data_size;
 	int ret = 0;
 
 	cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data));
@@ -95,10 +97,11 @@ static int hikp_unic_ppp_get_blk(struct hikp_cmd_header *req_header,
 	}
 
 	rsp = (struct unic_ppp_rsp *)cmd_ret->rsp_data;
-	if (rsp->rsp_head.cur_blk_size > buf_len) {
-		HIKP_ERROR_PRINT("unic_ppp block context copy size error, "
-				 "buffer size=%llu, data size=%u.\n",
-				 buf_len, rsp->rsp_head.cur_blk_size);
+	rsp_data_size = cmd_ret->rsp_data_num * REP_DATA_BLK_SIZE;
+	if (rsp_data_size - sizeof(rsp->rsp_head) < rsp->rsp_head.cur_blk_size ||
+	    buf_len < rsp->rsp_head.cur_blk_size) {
+		HIKP_ERROR_PRINT("block context copy size error, data size: %u, buffer size: %zu, blk size: %hhu.\n",
+				 rsp_data_size, buf_len, rsp->rsp_head.cur_blk_size);
 		ret = -EINVAL;
 		goto out;
 	}
@@ -123,17 +126,24 @@ static int hikp_unic_query_ppp_by_blkid(struct hikp_cmd_header *req_header, cons
 	req_data.block_id = blk_id;
 	ret = hikp_unic_ppp_get_blk(req_header, &req_data, data, len, &rsp_head);
 	if (ret != 0) {
-		HIKP_ERROR_PRINT("Fail to get block-%u context.\n", blk_id);
+		HIKP_ERROR_PRINT("Fail to get block-%hhu context.\n", blk_id);
 		return ret;
 	}
 	total_blk_size = rsp_head.cur_blk_size;
 
 	for (blk_id = 1; blk_id < rsp_head.total_blk_num; blk_id++) {
 		req_data.block_id = blk_id;
+		if (len < total_blk_size) {
+			HIKP_ERROR_PRINT("block-%hhu invalid total blk size, "
+					 "len: %zu, total blk size: %u",
+					 blk_id, len, total_blk_size);
+			return -EINVAL;
+		}
+
 		ret = hikp_unic_ppp_get_blk(req_header, &req_data, (uint8_t *)data + total_blk_size,
 					    len - total_blk_size, &rsp_head);
 		if (ret != 0) {
-			HIKP_ERROR_PRINT("Fail to get block-%u context.\n", blk_id);
+			HIKP_ERROR_PRINT("Fail to get block-%hhu context.\n", blk_id);
 			return ret;
 		}
 		total_blk_size += rsp_head.cur_blk_size;
@@ -175,7 +185,7 @@ static int hikp_unic_ppp_alloc_ip_tbl_entry(const struct hikp_unic_ppp_hw_resour
 static int hikp_unic_ppp_alloc_guid_tbl_entry(const struct hikp_unic_ppp_hw_resources *hw_res,
 					      struct unic_guid_tbl *guid_tbl)
 {
-	if (hw_res->uc_guid_tbl_size == 0 && hw_res->mc_guid_tbl_size == 0) {
+	if (hw_res->uc_guid_tbl_size == 0 || hw_res->mc_guid_tbl_size == 0) {
 		HIKP_ERROR_PRINT("guid tbl query is not supported\n");
 		return -EIO;
 	}
@@ -243,6 +253,12 @@ static int hikp_unic_query_ppp_ip_tbl(struct hikp_cmd_header *req_header, const
 	max_ip_entry_size = g_unic_ppp_hw_res.ip_max_mem_size + g_unic_ppp_hw_res.ip_overflow_size;
 	req_data.bdf = *bdf;
 	while (index < max_ip_entry_size) {
+		if (max_ip_entry_size < entry_size) {
+			HIKP_ERROR_PRINT("invalid ip table entry size, max entry size: %u, entry size: %u\n",
+					 max_ip_entry_size, entry_size);
+			return -EINVAL;
+		}
+
 		req_data.cur_entry_idx = index;
 		left_buf_len = sizeof(struct unic_ip_entry) * (max_ip_entry_size - entry_size);
 		ret = hikp_unic_ppp_get_blk(req_header, &req_data, ip_tbl->entry + entry_size,
@@ -268,15 +284,22 @@ static int hikp_unic_query_ppp_guid_tbl(struct hikp_cmd_header *req_header,
 	struct unic_ppp_req_para req_data = { 0 };
 	uint32_t entry_size = 0;
 	size_t left_buf_len = 0;
+	uint32_t guid_tbl_size;
 	uint32_t index = 0;
 	int ret = -1;
 
 	req_data.bdf = *bdf;
 	req_data.is_unicast = 1;
-	while (index < g_unic_ppp_hw_res.uc_guid_tbl_size) {
+	guid_tbl_size = g_unic_ppp_hw_res.uc_guid_tbl_size;
+	while (index < guid_tbl_size) {
+		if (guid_tbl_size < entry_size) {
+			HIKP_ERROR_PRINT("invalid uc guid table entry size, uc guid tbl size: %u, entry size: %u\n",
+					 guid_tbl_size, entry_size);
+			return -EINVAL;
+		}
+
 		req_data.cur_entry_idx = index;
-		left_buf_len = sizeof(struct unic_guid_uc_entry) *
-				     (g_unic_ppp_hw_res.uc_guid_tbl_size - entry_size);
+		left_buf_len = sizeof(struct unic_guid_uc_entry) * (guid_tbl_size - entry_size);
 		ret = hikp_unic_ppp_get_blk(req_header, &req_data,
 					    guid_tbl->uc_tbl.entry + entry_size,
 					    left_buf_len, &unic_rsp_head);
@@ -294,11 +317,16 @@ static int hikp_unic_query_ppp_guid_tbl(struct hikp_cmd_header *req_header,
 	entry_size = 0;
 	index = 0;
 	req_data.is_unicast = 0;
+	guid_tbl_size = g_unic_ppp_hw_res.mc_guid_tbl_size;
+	while (index < guid_tbl_size) {
+		if (guid_tbl_size < entry_size) {
+			HIKP_ERROR_PRINT("invalid mc guid table entry size, mc guid tbl size: %u, entry size: %u\n",
+					 guid_tbl_size, entry_size);
+			return -EINVAL;
+		}
 
-	while (index < g_unic_ppp_hw_res.mc_guid_tbl_size) {
 		req_data.cur_entry_idx = index;
-		left_buf_len = sizeof(struct unic_guid_mc_entry) *
-				     (g_unic_ppp_hw_res.mc_guid_tbl_size - entry_size);
+		left_buf_len = sizeof(struct unic_guid_mc_entry) * (guid_tbl_size - entry_size);
 		ret = hikp_unic_ppp_get_blk(req_header, &req_data,
 					    guid_tbl->mc_tbl.entry + entry_size,
 					    left_buf_len, &unic_rsp_head);
diff --git a/net/ub/ub_ppp/hikp_unic_ppp.h b/net/ub/ub_ppp/hikp_unic_ppp.h
index c25fabd..0771415 100644
--- a/net/ub/ub_ppp/hikp_unic_ppp.h
+++ b/net/ub/ub_ppp/hikp_unic_ppp.h
@@ -19,7 +19,7 @@
 #define HIKP_UNIC_IP_ADDR_FMT_SIZE	50
 #define MAX_IP_ADDR_STR_LEN		50
 #define IP_ADDR_LEN			16
-#define IP_ADDR_TBL_LEN		8
+#define IP_ADDR_TBL_LEN			8
 
 #define HIKP_UNIC_IP_ADDR_LEN		4
 #define HIKP_UNIC_GUID_BITMAP_LEN	8
diff --git a/ossl/ossl_user_linux.c b/ossl/ossl_user_linux.c
index 9dee61c..a369c68 100644
--- a/ossl/ossl_user_linux.c
+++ b/ossl/ossl_user_linux.c
@@ -26,7 +26,7 @@ int uda_access(const char *file_dir)
 {
 	char path[PATH_MAX + 1] = { 0 };
 
-	if (strlen(file_dir) > PATH_MAX || realpath(file_dir, path) == NULL)
+	if (file_dir == NULL || strlen(file_dir) > PATH_MAX || realpath(file_dir, path) == NULL)
 		return -ENOENT;
 
 	return faccessat(AT_FDCWD, path, F_OK, AT_EACCESS) ? (-ENOENT) : 0;
@@ -53,7 +53,7 @@ int uda_fcntl(const char *lock_file, uint32_t operation, int *fd)
 	if ((fd == NULL) || (lock_file == NULL))
 		return -EFAULT;
 
-	fd_t = open(lock_file, O_WRONLY | O_CREAT, 0700);
+	fd_t = open(lock_file, O_WRONLY | O_CREAT, 0600);
 	if (fd_t < 0)
 		return -errno;
 
diff --git a/pcie/func_lib/osal/os_common.c b/pcie/func_lib/osal/os_common.c
deleted file mode 100644
index 3ebf10c..0000000
--- a/pcie/func_lib/osal/os_common.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2022 Hisilicon Technologies Co., Ltd.
- * Hikptool is licensed under Mulan PSL v2.
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
- * You may obtain a copy of Mulan PSL v2 at:
- *          http://license.coscl.org.cn/MulanPSL2
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
- *
- * See the Mulan PSL v2 for more details.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-#include "os_common.h"
-
-void hilog(int pri, const char *module, const char *fun, int line, const char *fmt, ...)
-{
-	va_list ap;
-	(void)pri;
-	(void)module;
-	(void)fun;
-	(void)line;
-
-	va_start(ap, fmt);
-	(void)vprintf(fmt, ap);
-	va_end(ap);
-}
diff --git a/pcie/func_lib/osal/os_common.h b/pcie/func_lib/osal/os_common.h
index 480202c..de2a517 100644
--- a/pcie/func_lib/osal/os_common.h
+++ b/pcie/func_lib/osal/os_common.h
@@ -14,28 +14,16 @@
 #ifndef _OS_COMMON_H_
 #define _OS_COMMON_H_
 
-enum {
-	HW_LOG_TIPS = 0,
-	HW_LOG_DBG,
-	HW_LOG_INFO,
-	HW_LOG_WARN,
-	HW_LOG_ERR
-};
-
 #define LOG_PCIE "[PCIE]"
 
-void hilog(int pri, const char *module, const char *fun, int line, const char *fmt, ...);
-
-#define Log(pri, module, fmt, args...) hilog(pri, module, __func__, __LINE__, fmt, ##args)
-
-#define Err(module, fmt, args...) hilog(HW_LOG_ERR, module, __func__, __LINE__, fmt, ##args)
+#define Info(x, args...) printf(x, ##args)
 
-#define Warn(module, fmt, args...) hilog(HW_LOG_WARN, module, __func__, __LINE__, fmt, ##args)
+#define Err(x, args...) Info("[ ERROE ] " x, ##args)
 
-#define Info(module, fmt, args...) hilog(HW_LOG_INFO, module, __func__, __LINE__, fmt, ##args)
+#define Warn(x, args...) Info("[ WARN ] " x, ##args)
 
-#define Debug(module, fmt, args...) hilog(HW_LOG_DBG, module, __func__, __LINE__, fmt, ##args)
+#define Debug(x, args...) Info("[ DEBUG ] " x, ##args)
 
-#define Tips(module, fmt, args...) hilog(HW_LOG_TIPS, module, __func__, __LINE__, fmt, ##args)
+#define Tips(x, args...) Info("[ TIPS ] " x, ##args)
 
 #endif
diff --git a/pcie/func_lib/pcie_func/pcie_link_ltssm.c b/pcie/func_lib/pcie_func/pcie_link_ltssm.c
index 66226e0..5834612 100644
--- a/pcie/func_lib/pcie_func/pcie_link_ltssm.c
+++ b/pcie/func_lib/pcie_func/pcie_link_ltssm.c
@@ -81,37 +81,36 @@ static int pcie_get_ltssm_trace(uint32_t port_id, uint64_t *ltssm_status, uint32
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	ret = hikp_rsp_normal_check(cmd_ret);
 	if (ret) {
-		Err("PCIe Base", "pcie trace cmd_ret check failed, ret: %d.\n", ret);
+		Err("pcie trace cmd_ret check failed, ret: %d.\n", ret);
 		goto free_cmd_ret;
 	}
 
 	if (cmd_ret->rsp_data_num == 0) {
-		Err("PCIe Base", "without rsp data.\n");
+		Err("without rsp data.\n");
 		ret = -EINVAL;
 		goto free_cmd_ret;
 	}
 	/* 0: First uint32_t is ltssm trace num received from TF */
 	*ltssm_num = cmd_ret->rsp_data[0];
-
-	if ((cmd_ret->rsp_data_num - 1) * sizeof(uint32_t) != (*ltssm_num) * sizeof(uint64_t)) {
-		Err("PCIe Base", "rsp data number check failed, rsp_data_num: %u, ltssm_num: %u.\n",
-		    cmd_ret->rsp_data_num, *ltssm_num);
+	src_size = (*ltssm_num) * sizeof(uint64_t);
+	dst_size = TRACER_DEPTH * sizeof(uint64_t);
+	if (src_size > dst_size) {
+		Err("size check failed, %u > %u.\n", src_size, dst_size);
 		ret = -EINVAL;
 		goto free_cmd_ret;
 	}
 
-	src_size = (*ltssm_num) * sizeof(uint64_t);
-	dst_size = TRACER_DEPTH * sizeof(uint64_t);
-	if (src_size > dst_size) {
-		Err("PCIe Base", "size check failed, %u > %u.\n", src_size, dst_size);
+	if ((cmd_ret->rsp_data_num - 1) * sizeof(uint32_t) != (*ltssm_num) * sizeof(uint64_t)) {
+		Err("rsp data number check failed, rsp_data_num: %u, ltssm_num: %u.\n",
+		    cmd_ret->rsp_data_num, *ltssm_num);
 		ret = -EINVAL;
 		goto free_cmd_ret;
 	}
+
 	memcpy(ltssm_status, (cmd_ret->rsp_data + 1), src_size);
 
 free_cmd_ret:
 	free(cmd_ret);
-
 	return ret;
 }
 
@@ -184,19 +183,17 @@ static int pcie_print_ltssm_trace(const uint64_t *ltssm_input, uint32_t ltssm_nu
 	union ltssm_state_reg ltssm_val;
 
 	if (ltssm_num > TRACER_DEPTH || ltssm_num == 0) {
-		Err("PCIe Base", "ltssm_num(%u) is over range or zero\n", ltssm_num);
+		Err("ltssm_num(%u) is over range or zero\n", ltssm_num);
 		return -EINVAL;
 	}
-	Info("PCIe Base", "ltssm tracer:\n");
-	Info("PCIe Base", "\ttrace mode: %llx\n", *ltssm_input);
-	Info("PCIe Base",
-	     "\tltssm[ii]:  63:48 47:32 31 30 29 28 27 26 25 24 23 22 21:"
+	Info("ltssm tracer:\n");
+	Info("\ttrace mode: %llx\n", *ltssm_input);
+	Info("\tltssm[ii]:  63:48 47:32 31 30 29 28 27 26 25 24 23 22 21:"
 	     "20 19:12 11:10 9:6 5:0  ltssm\n");
 	for (i = 1; i < ltssm_num; i++) {
 		ltssm_val.val = ltssm_input[i];
 		ltssm_c = hisi_pcie_ltssm_string_get((uint32_t)ltssm_val.bits.ltssm_state);
-		Info("PCIe Base",
-			"\tltssm[%02u]: 0x%04x %04x   %x  %x  %x  %x  %x  %x  %x  "
+		Info("\tltssm[%02u]: 0x%04x %04x   %x  %x  %x  %x  %x  %x  %x  "
 			"%x  %x  %x  %x     %02x    %x     %x   %02x  %s\n",
 			i,
 			(uint32_t)ltssm_val.bits.txdetrx,
@@ -239,7 +236,7 @@ int pcie_ltssm_trace_show(uint32_t port_id)
 int pcie_ltssm_trace_mode_set(uint32_t port_id, uint32_t mode)
 {
 	struct hikp_cmd_header req_header;
-	struct hikp_cmd_ret *cmd_ret;
+	struct hikp_cmd_ret *cmd_ret = NULL;
 	struct pcie_trace_req_para req_data = { 0 };
 	int ret;
 
@@ -256,7 +253,7 @@ int pcie_ltssm_trace_mode_set(uint32_t port_id, uint32_t mode)
 int pcie_ltssm_trace_clear(uint32_t port_id)
 {
 	struct hikp_cmd_header req_header;
-	struct hikp_cmd_ret *cmd_ret;
+	struct hikp_cmd_ret *cmd_ret = NULL;
 	struct pcie_trace_req_para req_data = { 0 };
 	int ret;
 
@@ -273,9 +270,9 @@ int pcie_ltssm_link_status_get(uint32_t port_id)
 {
 	union pcie_link_info reg_val;
 	struct hikp_cmd_header req_header;
-	struct hikp_cmd_ret *cmd_ret;
+	struct hikp_cmd_ret *cmd_ret = NULL;
 	struct pcie_trace_req_para req_data = { 0 };
-	char *ltssm_sts;
+	char *ltssm_sts = NULL;
 	int ret;
 
 	req_data.port_id = port_id;
@@ -286,7 +283,7 @@ int pcie_ltssm_link_status_get(uint32_t port_id)
 		goto free_cmd_ret;
 
 	if (cmd_ret->rsp_data_num == 0) {
-		Err("PCIe Base", "rsp data number check failed, rsp_data_num: %u.\n",
+		Err("rsp data number check failed, rsp_data_num: %u.\n",
 			cmd_ret->rsp_data_num);
 		ret = -EINVAL;
 		goto free_cmd_ret;
@@ -294,12 +291,12 @@ int pcie_ltssm_link_status_get(uint32_t port_id)
 	reg_val.u32 = cmd_ret->rsp_data[0];
 	ltssm_sts = hisi_pcie_ltssm_string_get(reg_val.bits.mac_ltssm_st);
 
-	Info(LOG_PCIE, "Port[%u] mac link information:\n", port_id);
-	Info(LOG_PCIE, "    ltssm status: %s\n", ltssm_sts);
-	Info(LOG_PCIE, "    speed: Gen%u\n", reg_val.bits.mac_cur_link_speed);
-	Info(LOG_PCIE, "    width: X%u\n", reg_val.bits.mac_cur_link_width);
-	Info(LOG_PCIE, "    link_up: %u\n", reg_val.bits.mac_link_up);
-	Info(LOG_PCIE, "    lane_reverse: %u\n", reg_val.bits.lane_reverse);
+	Info("Port[%u] mac link information:\n", port_id);
+	Info("    ltssm status: %s\n", ltssm_sts);
+	Info("    speed: Gen%u\n", reg_val.bits.mac_cur_link_speed);
+	Info("    width: X%u\n", reg_val.bits.mac_cur_link_width);
+	Info("    link_up: %u\n", reg_val.bits.mac_link_up);
+	Info("    lane_reverse: %u\n", reg_val.bits.lane_reverse);
 free_cmd_ret:
 	free(cmd_ret);
 
@@ -319,32 +316,32 @@ static int pcie_get_pm_trace(uint32_t port_id, uint64_t *pm_status, uint32_t *pm
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	ret = hikp_rsp_normal_check(cmd_ret);
 	if (ret) {
-		Err("PCIe Base", "pcie pm trace cmd_ret check failed, ret: %d.\n", ret);
+		Err("pcie pm trace cmd_ret check failed, ret: %d.\n", ret);
 		goto free_cmd_ret;
 	}
 
 	if (cmd_ret->rsp_data_num == 0) {
-		Err("PCIe Base", "without rsp data.\n");
+		Err("without rsp data.\n");
 		ret = -EINVAL;
 		goto free_cmd_ret;
 	}
 	/* 0: First uint32_t is pm trace num received from TF */
 	*pm_num = cmd_ret->rsp_data[0];
-
-	if ((cmd_ret->rsp_data_num - 1) * sizeof(uint32_t) != (*pm_num) * sizeof(uint64_t)) {
-		Err("PCIe Base", "rsp data number check failed, rsp_data_num: %u, pm_num: %u.\n",
-		    cmd_ret->rsp_data_num, *pm_num);
+	src_size = (*pm_num) * sizeof(uint64_t);
+	dst_size = TRACER_DEPTH * sizeof(uint64_t);
+	if (src_size > dst_size) {
+		Err("size check failed, %u > %u.\n", src_size, dst_size);
 		ret = -EINVAL;
 		goto free_cmd_ret;
 	}
 
-	src_size = (*pm_num) * sizeof(uint64_t);
-	dst_size = TRACER_DEPTH * sizeof(uint64_t);
-	if (src_size > dst_size) {
-		Err("PCIe Base", "size check failed, %u > %u.\n", src_size, dst_size);
+	if ((cmd_ret->rsp_data_num - 1) * sizeof(uint32_t) != (*pm_num) * sizeof(uint64_t)) {
+		Err("rsp data number check failed, rsp_data_num: %u, pm_num: %u.\n",
+		    cmd_ret->rsp_data_num, *pm_num);
 		ret = -EINVAL;
 		goto free_cmd_ret;
 	}
+
 	memcpy(pm_status, (cmd_ret->rsp_data + 1), src_size);
 
 free_cmd_ret:
@@ -411,19 +408,17 @@ static int pcie_print_pm_trace(const uint64_t *pm_status, uint32_t pm_num)
 	union pm_state_reg pm_val;
 
 	if (pm_num > TRACER_DEPTH || pm_num == 0) {
-		Err("PCIe Base", "pm_num(%u) is over range or zero\n", pm_num);
+		Err("pm_num(%u) is over range or zero\n", pm_num);
 		return -EINVAL;
 	}
-	Info("PCIe Base", "pm tracer:\n");
-	Info("PCIe Base", "\ttrace state: %llx\n", pm_status[0]);
-	Info("PCIe Base",
-	     "\tpm[ii]: BE8: 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 "
+	Info("pm tracer:\n");
+	Info("\ttrace state: %llx\n", pm_status[0]);
+	Info("\tpm[ii]: BE8: 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 "
 	     "BD8:   23:6   5:0 :  pm state\n");
 	for (i = 1; i < pm_num; i++) {
 		pm_val.val = pm_status[i];
 		pm_c = hisi_pcie_pm_string_get((uint32_t)pm_val.bits.pm_state);
-		Info("PCIe Base",
-		     "\tpm[%02u]:\t     %x  %x  %x  %x  %x  %x %x %x %x %x %x "
+		Info("\tpm[%02u]:\t     %x  %x  %x  %x  %x  %x %x %x %x %x %x "
 		     "%x %x %x %x     0x%06x  0x%02x   %s\n",
 			i,
 			(uint32_t)pm_val.bits.pm_t_dfe_time_meet,
diff --git a/pcie/func_lib/pcie_func/pcie_reg_dump.c b/pcie/func_lib/pcie_func/pcie_reg_dump.c
index 535807c..856aebe 100644
--- a/pcie/func_lib/pcie_func/pcie_reg_dump.c
+++ b/pcie/func_lib/pcie_func/pcie_reg_dump.c
@@ -409,7 +409,7 @@ static int pcie_create_dumpreg_log_file(uint32_t port_id, uint32_t dump_level)
 	/* Add write permission to the file */
 	fd_file = open(file_name, O_RDWR | O_SYNC | O_CREAT, 0600);
 	if (fd_file < 0) {
-		Err("PCIe DUMPREG", "open %s failed.\n", file_name);
+		Err("open %s failed.\n", file_name);
 		return -EPERM;
 	}
 	g_pcie_dumpreg_fd = fd_file;
@@ -437,11 +437,11 @@ static void pcie_dumpreg_write_value_to_file(const char *reg_name, uint32_t val)
 
 	ret = snprintf(str, sizeof(str), "    %-40s : 0x%x\n", reg_name, val);
 	if (ret < 0 || ret >= sizeof(str)) {
-		Err("PCIe DUMPREG", "pcie dumpreg write info to logfile failed.\n");
+		Err("pcie dumpreg write info to logfile failed.\n");
 	} else {
 		wr_ret = write(g_pcie_dumpreg_fd, str, strlen(str));
 		if (wr_ret == -1)
-			Err("PCIe DUMPREG", "write info to logfile failed.\n");
+			Err("write info to logfile failed.\n");
 	}
 }
 
@@ -485,13 +485,13 @@ static int pcie_dumpreg_write_header_to_file(uint32_t version,
 	ret = snprintf(str, sizeof(str), "Command Version[%u], dump_level[%u], port_id[%u]\n\n",
 		version, req_data->level, req_data->port_id);
 	if (ret < 0) {
-		Err("PCIe DUMPREG", "pcie dumpreg write header to logfile failed.\n");
+		Err("pcie dumpreg write header to logfile failed.\n");
 		return -EIO;
 	}
 
 	wr_ret = write(g_pcie_dumpreg_fd, str, strlen(str));
 	if (wr_ret == -1) {
-		Err("PCIe DUMPREG", "write header to logfile failed.\n");
+		Err("write header to logfile failed.\n");
 		return -EIO;
 	}
 
@@ -506,7 +506,9 @@ static int pcie_dumpreg_save_log(uint32_t *data, uint32_t data_num,
 	uint32_t i;
 	int ret;
 
-	(void)pcie_dumpreg_write_header_to_file(version, req_data);
+	ret = pcie_dumpreg_write_header_to_file(version, req_data);
+	if (ret < 0)
+		return ret;
 
 	switch (req_data->level) {
 	case DUMP_GLOBAL_LEVEL:
@@ -520,7 +522,7 @@ static int pcie_dumpreg_save_log(uint32_t *data, uint32_t data_num,
 		}
 		break;
 	default:
-		Err("PCIe DUMPREG", "check dump level failed.\n");
+		Err("check dump level failed.\n");
 		return -EINVAL;
 	}
 
@@ -528,7 +530,7 @@ static int pcie_dumpreg_save_log(uint32_t *data, uint32_t data_num,
 		for (i = 0; i < data_num; i++) {
 			ret = snprintf(reg_name, sizeof(reg_name), "REG_%03u", i);
 			if (ret < 0)
-				Err("PCIe DUMPREG", "save log snprintf failed.\n");
+				Err("save log snprintf failed.\n");
 			pcie_dumpreg_write_value_to_file(reg_name, data[i]);
 		}
 	} else if (req_data->level == DUMP_GLOBAL_LEVEL) {
@@ -549,7 +551,7 @@ int pcie_dumpreg_do_dump(uint32_t port_id, uint32_t dump_level)
 	struct pcie_dump_req_para req_data = { 0 };
 	int ret = 0;
 
-	Info("PCIe DUMPREG", "pcie reg dump start.\n");
+	Info("pcie reg dump start.\n");
 
 	req_data.port_id = port_id;
 	req_data.level = dump_level;
@@ -567,11 +569,11 @@ int pcie_dumpreg_do_dump(uint32_t port_id, uint32_t dump_level)
 	ret = pcie_dumpreg_save_log(cmd_ret->rsp_data,
 				    cmd_ret->rsp_data_num, cmd_ret->version, &req_data);
 	if (ret) {
-		Err("PCIe DUMPREG", "pcie dump save log failed, ret: %d.\n", ret);
+		Err("pcie dump save log failed, ret: %d.\n", ret);
 		goto close_file_ret;
 	}
 
-	Info("PCIe DUMPREG", "pcie reg dump finish.\n");
+	Info("pcie reg dump finish.\n");
 close_file_ret:
 	(void)pcie_close_dumpreg_log_file();
 free_cmd_ret:
diff --git a/pcie/func_lib/pcie_func/pcie_reg_read.c b/pcie/func_lib/pcie_func/pcie_reg_read.c
index b3d4643..1578056 100644
--- a/pcie/func_lib/pcie_func/pcie_reg_read.c
+++ b/pcie/func_lib/pcie_func/pcie_reg_read.c
@@ -66,11 +66,11 @@ int pcie_read_name2module_id(const char *module_name, uint32_t *module_id)
 static int pcie_reg_read_result_show(const struct hikp_cmd_ret *cmd_ret)
 {
 	if (cmd_ret->rsp_data_num != 1) { /* 1 uint32_t data for reg read cmd */
-		Err("PCIe REGREAD", "pcie reg read data num check failed, num: %u.\n",
+		Err("pcie reg read data num check failed, num: %u.\n",
 		    cmd_ret->rsp_data_num);
 		return -EINVAL;
 	}
-	Info("PCIe REGREAD", "RIGISTER VALUE[0x%08x].\n", cmd_ret->rsp_data[0]);
+	Info("RIGISTER VALUE[0x%08x].\n", cmd_ret->rsp_data[0]);
 
 	return 0;
 }
@@ -89,7 +89,7 @@ int pcie_reg_read(uint32_t port_id, uint32_t module_id, uint32_t offset)
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	ret = hikp_rsp_normal_check(cmd_ret);
 	if (ret) {
-		Err("PCIe REGREAD", "pcie reg read cmd_ret check failed, ret: %d.\n", ret);
+		Err("pcie reg read cmd_ret check failed, ret: %d.\n", ret);
 		goto free_cmd_ret;
 	}
 	ret = pcie_reg_read_result_show(cmd_ret);
diff --git a/pcie/func_lib/pcie_func/pcie_statistics.c b/pcie/func_lib/pcie_func/pcie_statistics.c
index badf3d1..e2bfcb4 100644
--- a/pcie/func_lib/pcie_func/pcie_statistics.c
+++ b/pcie/func_lib/pcie_func/pcie_statistics.c
@@ -32,18 +32,18 @@ static const char *g_global_ndie_name[] = {
 static int port_distribution_rsp_data_check(const struct hikp_cmd_ret *cmd_ret, uint32_t *port_num)
 {
 	size_t rsp_data_size, expect_data_size;
-	struct pcie_port_info *port_info;
+	struct pcie_port_info *port_info = NULL;
 	int ret;
 
 	ret = hikp_rsp_normal_check(cmd_ret);
 	if (ret) {
-		Err("PCIe Base", "port distribution cmd_ret normal check failed, ret: %d.\n", ret);
+		Err("port distribution cmd_ret normal check failed, ret: %d.\n", ret);
 		return ret;
 	}
 	rsp_data_size = cmd_ret->rsp_data_num * sizeof(uint32_t);
 	/* Check whether enough data of a port unit */
 	if (rsp_data_size < sizeof(struct pcie_port_info)) {
-		Err("PCIe Base", "port distribution rsp check failed, size: %u.\n",
+		Err("port distribution rsp check failed, size: %u.\n",
 			rsp_data_size);
 		return -EINVAL;
 	}
@@ -53,8 +53,7 @@ static int port_distribution_rsp_data_check(const struct hikp_cmd_ret *cmd_ret,
 	expect_data_size = sizeof(struct pcie_port_info) +
 		sizeof(struct pcie_info_distribution_pair) * (*port_num);
 	if (expect_data_size > rsp_data_size) {
-		Err("PCIe Base",
-		    "port distribution data size check failed, size: %u, expect size: %u.\n",
+		Err("port distribution data size check failed, size: %u, expect size: %u.\n",
 		    rsp_data_size, expect_data_size);
 		return -EINVAL;
 	}
@@ -68,19 +67,19 @@ static int pcie_portid_serdes_relation(const struct pcie_macro_info *macro_info,
 	uint32_t i, j;
 
 	if (ndie_id >= HIKP_ARRAY_SIZE(g_global_ndie_name)) {
-		Info("PCIe Base", "ndie_id [%u]: %s\n", ndie_id, "UNKNOWN_NDIE");
+		Info("ndie_id [%u]: %s\n", ndie_id, "UNKNOWN_NDIE");
 		return -1;
 	}
 
 	if (macro_num >= MAX_MACRO_ONEPORT) {
-		Info("PCIe Base", "macro_num [%u] exceeds the maximum array length\n", macro_num);
+		Info("macro_num [%u] exceeds the maximum array length\n", macro_num);
 		return -1;
 	}
 
-	Info("PCIe Base", "\tndie_id: %s\n", g_global_ndie_name[ndie_id]);
+	Info("\tndie_id: %s\n", g_global_ndie_name[ndie_id]);
 	for (i = 0; i < macro_num; i++) {
 		for (j = macro_info[i].lane_s; j <= macro_info[i].lane_e; j++)
-			Info("PCIe Base", "\t\tmacro %d \t lane: %d\n", macro_info[i].id, j);
+			Info("\t\tmacro %d \t lane: %d\n", macro_info[i].id, j);
 	}
 	return 0;
 }
@@ -88,10 +87,10 @@ static int pcie_portid_serdes_relation(const struct pcie_macro_info *macro_info,
 int pcie_port_distribution_get(uint32_t chip_id)
 {
 	struct hikp_cmd_header req_header;
-	struct hikp_cmd_ret *cmd_ret;
+	struct hikp_cmd_ret *cmd_ret = NULL;
 	struct pcie_info_req_para req_data = { 0 };
 	uint32_t pair_num;
-	struct pcie_port_info *port_info;
+	struct pcie_port_info *port_info = NULL;
 	uint32_t i;
 	int ret;
 
@@ -104,14 +103,14 @@ int pcie_port_distribution_get(uint32_t chip_id)
 		goto free_cmd_ret;
 
 	port_info = (struct pcie_port_info *)cmd_ret->rsp_data;
-	Info("PCIe Base", "Port Distribution Info (CHIP : 0x%x)Port_id Port_width\n", chip_id);
+	Info("Port Distribution Info (CHIP : 0x%x)Port_id Port_width\n", chip_id);
 	for (i = 0; i < pair_num; i++) {
 		if (port_info->info_pair[i].port_width >= HIKP_ARRAY_SIZE(g_global_width_name)) {
-			Info("PCIe Base", "port_id[%u] %s\n", port_info->info_pair[i].port_id,
+			Info("port_id[%u] %s\n", port_info->info_pair[i].port_id,
 			"UNKNOWN_WIDTH");
 			continue;
 		}
-		Info("PCIe Base", "port_id[%u] %s\n", port_info->info_pair[i].port_id,
+		Info("port_id[%u] %s\n", port_info->info_pair[i].port_id,
 			g_global_width_name[port_info->info_pair[i].port_width]);
 		pcie_portid_serdes_relation(port_info->info_pair[i].macro_info,
 					    port_info->info_pair[i].macro_num,
@@ -130,13 +129,12 @@ static int port_err_state_rsp_data_check(struct hikp_cmd_ret *cmd_ret)
 
 	ret = hikp_rsp_normal_check(cmd_ret);
 	if (ret) {
-		Err("PCIe Base", "error state get cmd_ret normal check failed, ret: %d.\n", ret);
+		Err("error state get cmd_ret normal check failed, ret: %d.\n", ret);
 		return ret;
 	}
 	rsp_data_size = cmd_ret->rsp_data_num * sizeof(uint32_t);
 	if (rsp_data_size < sizeof(struct pcie_err_state)) {
-		Err("PCIe Base",
-		    "err state get rsp size check failed, rsp size: %u, expect size:%u.\n",
+		Err("err state get rsp size check failed, rsp size: %u, expect size:%u.\n",
 		    rsp_data_size, sizeof(struct pcie_err_state));
 		return -EINVAL;
 	}
@@ -147,9 +145,9 @@ static int port_err_state_rsp_data_check(struct hikp_cmd_ret *cmd_ret)
 int pcie_error_state_get(uint32_t port_id)
 {
 	struct hikp_cmd_header req_header;
-	struct hikp_cmd_ret *cmd_ret;
+	struct hikp_cmd_ret *cmd_ret = NULL;
 	struct pcie_info_req_para req_data = { 0 };
-	struct pcie_err_state *state;
+	struct pcie_err_state *state = NULL;
 	int ret;
 
 	req_data.interface_id = port_id;
@@ -162,17 +160,17 @@ int pcie_error_state_get(uint32_t port_id)
 
 	state = (struct pcie_err_state *)cmd_ret->rsp_data;
 
-	Info("PCIe Base", "phy_lane_err_counter = %u\n", state->test_cnt.bits.phy_lane_err_counter);
-	Info("PCIe Base", "symbol_unlock_counter = %u\n",
+	Info("phy_lane_err_counter = %u\n", state->test_cnt.bits.phy_lane_err_counter);
+	Info("symbol_unlock_counter = %u\n",
 	     state->symbol_unlock_cnt.bits.symbol_unlock_counter);
-	Info("PCIe Base", "mac_int_status = 0x%x\n", state->mac_int_status);
-	Info("PCIe Base", "loop_back_link_data_err_cnt = %u\n",
+	Info("mac_int_status = 0x%x\n", state->mac_int_status);
+	Info("loop_back_link_data_err_cnt = %u\n",
 	     state->loop_link_data_err_cnt.bits.loop_back_link_data_err_cnt);
-	Info("PCIe Base", "pcs_rx_err_cnt = %u\n", state->rx_err_cnt.bits.pcs_rx_err_cnt);
-	Info("PCIe Base", "reg_framing_err_count = %u\n",
+	Info("pcs_rx_err_cnt = %u\n", state->rx_err_cnt.bits.pcs_rx_err_cnt);
+	Info("reg_framing_err_count = %u\n",
 	     state->framing_err_cnt.bits.reg_framing_err_count);
-	Info("PCIe Base", "dl_lcrc_err_num = %u\n", state->lcrc_err_num.bits.dl_lcrc_err_num);
-	Info("PCIe Base", "dl_dcrc_err_num = %u\n", state->dcrc_err_num.bits.dl_dcrc_err_num);
+	Info("dl_lcrc_err_num = %u\n", state->lcrc_err_num.bits.dl_lcrc_err_num);
+	Info("dl_dcrc_err_num = %u\n", state->dcrc_err_num.bits.dl_dcrc_err_num);
 free_cmd_ret:
 	free(cmd_ret);
 
@@ -182,7 +180,7 @@ free_cmd_ret:
 int pcie_error_state_clear(uint32_t port_id)
 {
 	struct hikp_cmd_header req_header;
-	struct hikp_cmd_ret *cmd_ret;
+	struct hikp_cmd_ret *cmd_ret = NULL;
 	struct pcie_info_req_para req_data = { 0 };
 	int ret;
 
diff --git a/pcie/usr_cmd/cmd_analysis/pcie_cmd_dumpreg.c b/pcie/usr_cmd/cmd_analysis/pcie_cmd_dumpreg.c
index f6399b4..6d1c674 100644
--- a/pcie/usr_cmd/cmd_analysis/pcie_cmd_dumpreg.c
+++ b/pcie/usr_cmd/cmd_analysis/pcie_cmd_dumpreg.c
@@ -60,7 +60,7 @@ static int pcie_port_set(struct major_cmd_ctrl *self, const char *argv)
 
 static int dump_level_set(struct major_cmd_ctrl *self, const char *argv)
 {
-	uint32_t val;
+	uint32_t val = 0;
 	int ret;
 
 	ret = string_toui(argv, &val);
diff --git a/sas/sas_func/sas_analy_queue.c b/sas/sas_func/sas_analy_queue.c
index 8fca197..b27ba60 100644
--- a/sas/sas_func/sas_analy_queue.c
+++ b/sas/sas_func/sas_analy_queue.c
@@ -40,7 +40,7 @@ static int sas_get_res(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
 		hikp_cmd_init(&req_header, SAS_MOD, SAS_ANACQ, ANACQ_PRT);
 
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
-	if (cmd_ret == NULL || cmd_ret->status != 0) {
+	if (cmd_ret == NULL || cmd_ret->status != 0 || cmd_ret->rsp_data_num > RESP_MAX_NUM) {
 		printf("sas_analy excutes hikp_cmd_alloc err\n");
 		free(cmd_ret);
 		return -EINVAL;
@@ -57,7 +57,7 @@ static void sas_print_prt(const uint32_t *reg_save, uint32_t reg_num)
 {
 	uint32_t i;
 
-	if (reg_num == 0) {
+	if (reg_num < REG_NUM_PTR_MAX) {
 		printf("SAS get queue pointer is failed\n");
 		return;
 	}
@@ -80,7 +80,7 @@ static void sas_print_dqnum(const uint32_t *reg_save, uint32_t reg_num)
 
 static void sas_print_cqnum(const uint32_t *reg_save, uint32_t reg_num)
 {
-	if (reg_num < CQ_COAL_CNT) {
+	if (reg_num < REG_NUM_CQ_MAX) {
 		printf("SAS get cq number is failed\n");
 		return;
 	}
diff --git a/sas/sas_func/sas_analy_queue.h b/sas/sas_func/sas_analy_queue.h
index a6e2223..59100f4 100644
--- a/sas/sas_func/sas_analy_queue.h
+++ b/sas/sas_func/sas_analy_queue.h
@@ -18,6 +18,8 @@
 
 #define REG_NUM_DQ 2
 #define REG_NUM_CQ 2
+#define REG_NUM_CQ_MAX 4
+#define REG_NUM_PTR_MAX 32
 #define CQE_NUM_BYTE 0
 #define DQE_NUM_REG 2
 #define CQ_COAL 1
diff --git a/sas/sas_func/sas_common.h b/sas/sas_func/sas_common.h
index 1bace0c..c33a2fe 100644
--- a/sas/sas_func/sas_common.h
+++ b/sas/sas_func/sas_common.h
@@ -22,6 +22,10 @@
 #define IPTT_ICT_STATUS 29
 #define LINK_SPEED_OFFSET 8
 #define LINK_SPEED_WIDTH 4
+#define REG_NUM_DEV_LINK_MAX 3
+#define REG_NUM_DQE_MAX 8
+#define REG_NUM_ERR_CODE_ALL_MAX 32
+#define REG_NUM_ERR_CODE_MAX 8
 
 #define DWS_LOST 0
 #define RESET_PROB 1
diff --git a/sas/sas_func/sas_dump_reg.c b/sas/sas_func/sas_dump_reg.c
index 5736726..9a1da3a 100644
--- a/sas/sas_func/sas_dump_reg.c
+++ b/sas/sas_func/sas_dump_reg.c
@@ -32,7 +32,7 @@ static int sas_get_reg(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
 
 	hikp_cmd_init(&req_header, SAS_MOD, SAS_DUMP, cmd->sas_cmd_type);
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
-	if (cmd_ret == NULL || cmd_ret->status != 0) {
+	if (cmd_ret == NULL || cmd_ret->status != 0 || cmd_ret->rsp_data_num > RESP_MAX_NUM) {
 		printf("sas_dump excutes hikp_cmd_alloc err\n");
 		free(cmd_ret);
 		return -1;
diff --git a/sas/sas_func/sas_read_dev.c b/sas/sas_func/sas_read_dev.c
index 670e2d4..ede5d74 100644
--- a/sas/sas_func/sas_read_dev.c
+++ b/sas/sas_func/sas_read_dev.c
@@ -33,7 +33,7 @@ static int sas_get_dev(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
 
 	hikp_cmd_init(&req_header, SAS_MOD, SAS_DEV, cmd->sas_cmd_type);
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
-	if (cmd_ret == NULL || cmd_ret->status != 0) {
+	if (cmd_ret == NULL || cmd_ret->status != 0 || cmd_ret->rsp_data_num > RESP_MAX_NUM) {
 		printf("sas_dqe excutes hikp_cmd_alloc err\n");
 		free(cmd_ret);
 		return -EINVAL;
@@ -78,7 +78,7 @@ static void print_dev_link(const uint32_t *reg_save, uint32_t reg_num)
 
 static void sas_print_dev(const uint32_t *reg_save, uint32_t reg_num, uint32_t cmd_type)
 {
-	if (reg_num == 0) {
+	if (reg_num < REG_NUM_DEV_LINK_MAX) {
 		printf("SAS device is failed\n");
 		return;
 	}
diff --git a/sas/sas_func/sas_read_dqe.c b/sas/sas_func/sas_read_dqe.c
index 7d49c0a..072c1dc 100644
--- a/sas/sas_func/sas_read_dqe.c
+++ b/sas/sas_func/sas_read_dqe.c
@@ -33,7 +33,7 @@ static int sas_get_dqe(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
 
 	hikp_cmd_init(&req_header, SAS_MOD, SAS_DQE, cmd->sas_cmd_type);
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
-	if (cmd_ret == NULL || cmd_ret->status != 0) {
+	if (cmd_ret == NULL || cmd_ret->status != 0 || cmd_ret->rsp_data_num > RESP_MAX_NUM) {
 		printf("sas_dqe excutes hikp_cmd_alloc err\n");
 		free(cmd_ret);
 		return -EINVAL;
@@ -105,7 +105,7 @@ int sas_dqe(const struct tool_sas_cmd *cmd)
 	if (ret)
 		return ret;
 
-	if (reg_num == 0) {
+	if (reg_num < REG_NUM_DQE_MAX) {
 		printf("SAS dqe is failed\n");
 		return -EINVAL;
 	}
diff --git a/sas/sas_func/sas_read_errcode.c b/sas/sas_func/sas_read_errcode.c
index 6c7850e..da1157b 100644
--- a/sas/sas_func/sas_read_errcode.c
+++ b/sas/sas_func/sas_read_errcode.c
@@ -31,7 +31,7 @@ static int sas_get_errcode(const struct tool_sas_cmd *cmd, uint32_t *reg_save, u
 
 	hikp_cmd_init(&req_header, SAS_MOD, SAS_ERRCODE, cmd->sas_cmd_type);
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
-	if (cmd_ret == NULL || cmd_ret->status != 0) {
+	if (cmd_ret == NULL || cmd_ret->status != 0 || cmd_ret->rsp_data_num > RESP_MAX_NUM) {
 		printf("sas_errcode excutes hikp_cmd_alloc err\n");
 		free(cmd_ret);
 		return -EINVAL;
@@ -55,11 +55,12 @@ static void sas_print_errcode(uint32_t cmd_type, const uint32_t *reg_save, uint3
 		"OPEN_REJ"
 	};
 
-	if (reg_num == 0) {
-		printf("SAS error code read is failed\n");
-		return;
-	}
 	if (cmd_type == ERRCODE_ALL) {
+		if (reg_num < REG_NUM_ERR_CODE_ALL_MAX) {
+			printf("SAS error code read is failed\n");
+			return;
+		}
+
 		printf("       DWS_LOST  RESET_PROB  CRC_FAIL  OPEN_REJ\n");
 		for (i = 0; i < reg_num; i += SAS_ERR_NUM) {
 			printf("phy%u  0x%08x    0x%08x      0x%08x    0x%08x\n", i / SAS_ERR_NUM,
@@ -67,6 +68,11 @@ static void sas_print_errcode(uint32_t cmd_type, const uint32_t *reg_save, uint3
 			       reg_save[i + CRC_FAIL], reg_save[i + OPEN_REJ]);
 		}
 	} else {
+		if (reg_num < REG_NUM_ERR_CODE_MAX) {
+			printf("SAS error code read is failed\n");
+			return;
+		}
+
 		printf("       %s\n", errcode_type[cmd_type]);
 		for (i = 0; i < reg_num; i++)
 			printf("phy%u  0x%08x\n", i, reg_save[i]);
diff --git a/sata/sata_func/sata_dump_reg.c b/sata/sata_func/sata_dump_reg.c
index b4ff35f..691989e 100644
--- a/sata/sata_func/sata_dump_reg.c
+++ b/sata/sata_func/sata_dump_reg.c
@@ -33,7 +33,7 @@ static int sata_get_reg(const struct tool_sata_cmd *cmd, uint32_t *reg_save, uin
 
 	hikp_cmd_init(&req_header, SATA_MOD, SATA_DUMP, cmd->sata_cmd_type);
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
-	if (cmd_ret == NULL || cmd_ret->status != 0) {
+	if (cmd_ret == NULL || cmd_ret->status != 0 || cmd_ret->rsp_data_num > RESP_MAX_NUM) {
 		printf("hikp_data_proc err\n");
 		free(cmd_ret);
 		return -1;
diff --git a/tool_lib/op_logs.c b/tool_lib/op_logs.c
index 9fb91d8..b6ecc48 100644
--- a/tool_lib/op_logs.c
+++ b/tool_lib/op_logs.c
@@ -57,7 +57,7 @@ static int op_log_write_buffer(const char *log_data, const char *log_dir)
 	int ret;
 
 	sigfillset(&sigset);
-	sigprocmask(SIG_BLOCK, &sigset, NULL);
+	(void)sigprocmask(SIG_BLOCK, &sigset, NULL);
 	ret = tool_flock(OP_LOG_LOCK_NAME, UDA_FLOCK_BLOCK, &op_lock_fd, log_dir);
 	if (ret == -ENOENT) {
 		HIKP_ERROR_PRINT("Folder or file required by the operation is not exist.\n");
@@ -73,7 +73,7 @@ static int op_log_write_buffer(const char *log_data, const char *log_dir)
 	op_log_write(log_data);
 	tool_unlock(&op_lock_fd, UDA_FLOCK_BLOCK);
 	g_log_info = true;
-	sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+	(void)sigprocmask(SIG_UNBLOCK, &sigset, NULL);
 	return 0;
 }
 
@@ -104,13 +104,13 @@ static double op_log_diff_timeval(const struct timeval *now, const struct timeva
 static int op_log_add_time_to_log(char *log_base, int *offset, uint32_t flag)
 {
 	static struct timeval g_tv;
-	struct timeval tv;
-	struct tm ptm;
+	struct timeval tv = {0};
+	struct tm ptm = {0};
 	int len = 0;
 	int ret;
 
 	(void)gettimeofday(&tv, NULL);
-	localtime_r(&tv.tv_sec, &ptm);
+	(void)localtime_r(&tv.tv_sec, &ptm);
 	if (flag == LOG_FLAG_DATE_TIME) {
 		g_tv = tv;
 		len = (int)strftime(log_base + *offset, (OP_LOG_FILE_W_MAXSIZE + 1 - *offset),
@@ -186,9 +186,7 @@ static int op_log_file_rollback(const char *op_log_backup, const char *log_dir)
 	snprintf(rollback_log + offset,
 		 (uint32_t)(OP_LOG_FILE_W_MAXSIZE + 1 - offset), OP_LOG_ITEM_END);
 
-	op_log_write_buffer(rollback_log, log_dir);
-
-	return ret;
+	return op_log_write_buffer(rollback_log, log_dir);
 }
 
 static int op_log_dir_mk(const char *log_path)
diff --git a/tool_lib/tool_lib.c b/tool_lib/tool_lib.c
index 5c1a02d..4d02bdd 100644
--- a/tool_lib/tool_lib.c
+++ b/tool_lib/tool_lib.c
@@ -21,7 +21,7 @@ int string_toui(const char *nptr, uint32_t *value)
 	char *endptr = NULL;
 	int64_t tmp_value;
 
-	if (nptr == NULL)
+	if (nptr == NULL || value == NULL)
 		return -EINVAL;
 
 	tmp_value = strtol(nptr, &endptr, 0);
@@ -37,7 +37,7 @@ int string_toub(const char *nptr, uint8_t *value)
 	char *endptr = NULL;
 	int64_t tmp_value;
 
-	if (nptr == NULL)
+	if (nptr == NULL || value == NULL)
 		return -EINVAL;
 
 	tmp_value = strtol(nptr, &endptr, 0);
@@ -141,14 +141,14 @@ int check_file_access(const char *file_dir)
 
 static uint32_t get_file_size(const char *file_dir)
 {
-	char format_dir[TOOL_REAL_PATH_MAX_LEN] = {0};
+	char format_dir[PATH_MAX + 1] = {0};
 	struct stat file_stat = { 0 };
 	int ret;
 
 	if (file_dir == NULL)
 		return 0;
 
-	ret = check_file_path_dir(file_dir, format_dir, TOOL_REAL_PATH_MAX_LEN);
+	ret = check_file_path_dir(file_dir, format_dir, (PATH_MAX + 1));
 	if (ret) {
 		HIKP_ERROR_PRINT("This file path[%s] is not exist.\n", file_dir);
 		return 0;
@@ -313,7 +313,7 @@ int generate_file_name(unsigned char *file_name,
 #define RANDOM_STR_LENGTH 7
 	char str_r[RANDOM_STR_LENGTH] = {0};
 	time_t time_seconds = time(0);
-	struct tm timeinfo;
+	struct tm timeinfo = {0};
 	int ret;
 
 	ret = get_rand_str(str_r, RANDOM_STR_LENGTH);
@@ -321,7 +321,7 @@ int generate_file_name(unsigned char *file_name,
 		HIKP_ERROR_PRINT("get randrom string failed.\n");
 		return ret;
 	}
-	localtime_r(&time_seconds, &timeinfo);
+	(void)localtime_r(&time_seconds, &timeinfo);
 	ret = snprintf((char *)file_name, file_name_len, "%s_%d_%d_%d_%d_%d_%d_%s.log", prefix,
 		       timeinfo.tm_year + START_YEAR, timeinfo.tm_mon + 1, timeinfo.tm_mday,
 		       timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, str_r);
-- 
2.45.0.windows.1

