From 2dccd3b70f9b262f541147f61ffed8cd9b7a079b Mon Sep 17 00:00:00 2001
From: veega2022 <zhuweijia@huawei.com>
Date: Tue, 3 Sep 2024 20:26:16 +0800
Subject: [PATCH 21/27] hikptool: The memory release interface is added.

The memory release interface hikp_cmd_free is
added to work with hikp_cmd_alloc.

Signed-off-by: veega2022 <zhuweijia@huawei.com>
---
 cxl/func_lib/cxl_func/cxl_feature.c           | 11 +++----
 libhikptdev/include/hikptdev_plug.h           |  1 +
 libhikptdev/src/rciep/hikpt_rciep.c           |  8 +++++
 net/nic/nic_dfx/hikp_nic_dfx.c                |  6 ++--
 net/nic/nic_fd/hikp_nic_fd.c                  |  4 +--
 net/nic/nic_fec/hikp_nic_fec.c                |  7 ++--
 net/nic/nic_ft/hikp_nic_port_fault.c          |  7 ++--
 net/nic/nic_gro/hikp_nic_gro.c                |  6 ++--
 net/nic/nic_info/hikp_nic_info.c              |  6 ++--
 net/nic/nic_log/hikp_nic_log.c                |  6 ++--
 net/nic/nic_mac/hikp_nic_mac_dump.c           |  8 ++---
 net/nic/nic_mac/hikp_nic_port.c               | 32 ++++++++-----------
 net/nic/nic_mac/hikp_nic_xsfp.c               | 12 +++----
 net/nic/nic_ncsi/hikp_nic_ncsi.c              |  3 +-
 net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c  |  5 ++-
 net/nic/nic_ppp/hikp_nic_ppp.c                | 15 ++++-----
 net/nic/nic_qos/hikp_nic_qos.c                |  2 +-
 net/nic/nic_queue/hikp_nic_queue.c            |  2 +-
 net/nic/nic_rss/hikp_nic_rss.c                |  2 +-
 net/nic/nic_torus/hikp_nic_torus.c            |  7 ++--
 net/roce/roce_caep/hikp_roce_caep.c           |  3 +-
 .../roce_ext_common/hikp_roce_ext_common.c    |  8 +----
 net/roce/roce_gmv/hikp_roce_gmv.c             |  3 +-
 net/roce/roce_mdb/hikp_roce_mdb.c             |  3 +-
 net/roce/roce_pkt/hikp_roce_pkt.c             |  6 ++--
 net/roce/roce_qmm/hikp_roce_qmm.c             |  3 +-
 net/roce/roce_scc/hikp_roce_scc.c             | 17 +++-------
 net/roce/roce_timer/hikp_roce_timer.c         |  6 ++--
 net/roce/roce_trp/hikp_roce_trp.c             | 17 +++-------
 net/roce/roce_tsp/hikp_roce_tsp.c             |  6 ++--
 net/roh/hikp_roh_mac.c                        | 26 ++++++---------
 net/roh/hikp_roh_show_bp.c                    |  3 +-
 net/roh/hikp_roh_show_mib.c                   |  6 ++--
 net/ub/ub_bp/hikp_ub_bp.c                     |  6 ++--
 net/ub/ub_crd/hikp_ub_crd.c                   |  6 ++--
 net/ub/ub_dfx/hikp_ub_dfx.c                   |  6 ++--
 net/ub/ub_info/hikp_ub_info.c                 |  6 ++--
 net/ub/ub_link/hikp_ub_link.c                 |  6 ++--
 net/ub/ub_ppp/hikp_unic_ppp.c                 |  2 +-
 pcie/func_lib/pcie_func/pcie_link_ltssm.c     | 19 +++++------
 pcie/func_lib/pcie_func/pcie_reg_dump.c       |  2 +-
 pcie/func_lib/pcie_func/pcie_reg_read.c       |  2 +-
 pcie/func_lib/pcie_func/pcie_statistics.c     | 13 ++++----
 sas/sas_func/sas_analy_queue.c                |  4 +--
 sas/sas_func/sas_dump_reg.c                   |  4 +--
 sas/sas_func/sas_read_dev.c                   |  4 +--
 sas/sas_func/sas_read_dqe.c                   |  4 +--
 sas/sas_func/sas_read_errcode.c               |  4 +--
 sata/sata_func/sata_dump_reg.c                |  4 +--
 serdes/hikp_serdes.c                          |  4 +--
 socip/hikp_socip_dumpreg.c                    |  6 ++--
 51 files changed, 144 insertions(+), 215 deletions(-)

diff --git a/cxl/func_lib/cxl_func/cxl_feature.c b/cxl/func_lib/cxl_func/cxl_feature.c
index 12fadbd..afe3895 100644
--- a/cxl/func_lib/cxl_func/cxl_feature.c
+++ b/cxl/func_lib/cxl_func/cxl_feature.c
@@ -354,8 +354,7 @@ int cxl_reg_show_execute(uint32_t port_id, uint32_t mode_code, uint32_t cmd_type
 	if (ret) {
 		printf("cxl_cmd mode_code: %u cmd_type: %u, hikp_get_data_proc err, ret : %d\n",
 		       mode_code, cmd_type, ret);
-		if (cmd_ret)
-			free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		return ret;
 	}
 
@@ -363,7 +362,7 @@ int cxl_reg_show_execute(uint32_t port_id, uint32_t mode_code, uint32_t cmd_type
 		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);
+		hikp_cmd_free(&cmd_ret);
 		return -EINVAL;
 	}
 	data_head = (struct cxl_out_data *)cmd_ret->rsp_data;
@@ -371,7 +370,7 @@ int cxl_reg_show_execute(uint32_t port_id, uint32_t mode_code, uint32_t cmd_type
 
 	ret = cxl_data_unit_buf_check(data_head->data_offset, data_unit_len, cmd_ret->rsp_data_num);
 	if (ret) {
-		free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		return ret;
 	}
 
@@ -381,11 +380,11 @@ int cxl_reg_show_execute(uint32_t port_id, uint32_t mode_code, uint32_t cmd_type
 		if (mode_code == g_prtf[i].mode_code &&
 		    cmd_type == g_prtf[i].cmd_type && g_prtf[i].cxl_prt_handle) {
 			g_prtf[i].cxl_prt_handle(data_unit_buf, data_unit_len);
-			free(cmd_ret);
+			hikp_cmd_free(&cmd_ret);
 			return 0;
 		}
 	}
 
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return -EINVAL;
 }
diff --git a/libhikptdev/include/hikptdev_plug.h b/libhikptdev/include/hikptdev_plug.h
index 5ea02ca..2123935 100644
--- a/libhikptdev/include/hikptdev_plug.h
+++ b/libhikptdev/include/hikptdev_plug.h
@@ -51,6 +51,7 @@ void hikp_cmd_init(struct hikp_cmd_header *req_header, uint32_t mod_code, uint32
 		   uint32_t sub_cmd_code);
 struct hikp_cmd_ret *hikp_cmd_alloc(struct hikp_cmd_header *req_header,
 				    const void *req_data, uint32_t req_size);
+void hikp_cmd_free(struct hikp_cmd_ret **cmd_ret);
 int hikp_dev_init(void);
 void hikp_dev_uninit(void);
 int hikp_rsp_normal_check(const struct hikp_cmd_ret *cmd_ret);
diff --git a/libhikptdev/src/rciep/hikpt_rciep.c b/libhikptdev/src/rciep/hikpt_rciep.c
index 0210f3d..5a38b3b 100644
--- a/libhikptdev/src/rciep/hikpt_rciep.c
+++ b/libhikptdev/src/rciep/hikpt_rciep.c
@@ -285,6 +285,14 @@ free_req_data:
 	return cmd_ret;
 }
 
+void hikp_cmd_free(struct hikp_cmd_ret **cmd_ret)
+{
+	if (*cmd_ret) {
+		free(*cmd_ret);
+		*cmd_ret = NULL;
+	}
+}
+
 int hikp_rsp_normal_check(const struct hikp_cmd_ret *cmd_ret)
 {
 	if (cmd_ret == NULL)
diff --git a/net/nic/nic_dfx/hikp_nic_dfx.c b/net/nic/nic_dfx/hikp_nic_dfx.c
index 2cc4367..318d85f 100644
--- a/net/nic/nic_dfx/hikp_nic_dfx.c
+++ b/net/nic/nic_dfx/hikp_nic_dfx.c
@@ -161,8 +161,7 @@ static int hikp_nic_get_first_blk_dfx(struct nic_dfx_rsp_head_t *rsp_head, uint3
 
 	*max_dfx_size -= (uint32_t)rsp_head->cur_blk_size;
 err_out:
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
@@ -191,8 +190,7 @@ static int hikp_nic_get_blk_dfx(struct nic_dfx_rsp_head_t *rsp_head, uint32_t bl
 	*max_dfx_size -= (uint32_t)rsp_head->cur_blk_size;
 
 err_out:
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
diff --git a/net/nic/nic_fd/hikp_nic_fd.c b/net/nic/nic_fd/hikp_nic_fd.c
index d4a9678..fb9333a 100644
--- a/net/nic/nic_fd/hikp_nic_fd.c
+++ b/net/nic/nic_fd/hikp_nic_fd.c
@@ -579,7 +579,7 @@ static int hikp_nic_fd_get_blk(struct hikp_cmd_header *req_header,
 	rsp_head->cur_blk_entry_cnt = rsp->rsp_head.cur_blk_entry_cnt;
 
 out:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
@@ -929,7 +929,6 @@ static void hikp_nic_fd_cmd_execute(struct major_cmd_ctrl *self)
 	const struct fd_feature_cmd *fd_cmd;
 	union nic_fd_feature_info *fd_data;
 	struct hikp_cmd_header req_header = {0};
-	uint8_t stage_no;
 	int ret;
 
 	ret = hikp_nic_fd_check_input_param(self, &g_fd_param);
@@ -967,7 +966,6 @@ static void hikp_nic_fd_cmd_execute(struct major_cmd_ctrl *self)
 	/* The 'hw_info' cmd no need to input stage number,
 	 * because it queries all stages information.
 	 */
-	stage_no = fd_cmd->sub_cmd_code == NIC_FD_HW_INFO_DUMP ? 0 : g_fd_param.stage_no - 1;
 	hikp_cmd_init(&req_header, NIC_MOD, GET_FD_INFO_CMD, fd_cmd->sub_cmd_code);
 	ret = fd_cmd->query(&req_header, bdf, g_fd_param.stage_no - 1, fd_data, sizeof(*fd_data));
 	if (ret != 0) {
diff --git a/net/nic/nic_fec/hikp_nic_fec.c b/net/nic/nic_fec/hikp_nic_fec.c
index edea28b..5a34bfd 100644
--- a/net/nic/nic_fec/hikp_nic_fec.c
+++ b/net/nic/nic_fec/hikp_nic_fec.c
@@ -32,16 +32,15 @@ static int hikp_nic_fec_err_query(const struct bdf_t *bdf, struct nic_fec_err_in
 	hikp_cmd_init(&header, NIC_MOD, GET_FEC_INFO_CMD, NIC_FEC_ERR_INFO_DUMP);
 	cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
 	if (cmd_ret == NULL || cmd_ret->status != 0) {
-		ret = cmd_ret ? -cmd_ret->status : -EIO;
+		ret = cmd_ret ? (int)(-cmd_ret->status) : -EIO;
 		HIKP_ERROR_PRINT("fail to get fec info, retcode: %d\n", ret);
-		free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		return ret;
 	}
 
 	rsp = (struct nic_fec_rsp *)cmd_ret->rsp_data;
 	*info = *(struct nic_fec_err_info *)rsp->data;
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 
 	if (info->fec_mode >= NIC_FEC_MODE_BUTT) {
 		HIKP_ERROR_PRINT("unknown fec mode: %u\n", info->fec_mode);
diff --git a/net/nic/nic_ft/hikp_nic_port_fault.c b/net/nic/nic_ft/hikp_nic_port_fault.c
index 85fa874..6561e3e 100644
--- a/net/nic/nic_ft/hikp_nic_port_fault.c
+++ b/net/nic/nic_ft/hikp_nic_port_fault.c
@@ -33,17 +33,16 @@ static int hikp_nic_port_fault_query(const struct bdf_t *bdf,
 		      NIC_PORT_FAULT_INFO_DUMP);
 	cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
 	if (cmd_ret == NULL || cmd_ret->status != 0) {
-		ret = cmd_ret ? -cmd_ret->status : -EIO;
+		ret = cmd_ret ? (int)(-cmd_ret->status) : -EIO;
 		HIKP_ERROR_PRINT("fail to get port fault, retcode: %d\n", ret);
-		if (cmd_ret != NULL)
-			free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 
 		return ret;
 	}
 
 	rsp = (struct nic_port_fault_rsp *)cmd_ret->rsp_data;
 	*info = *(struct nic_port_fault_status *)rsp->data;
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return 0;
 }
diff --git a/net/nic/nic_gro/hikp_nic_gro.c b/net/nic/nic_gro/hikp_nic_gro.c
index d897f11..19395af 100644
--- a/net/nic/nic_gro/hikp_nic_gro.c
+++ b/net/nic/nic_gro/hikp_nic_gro.c
@@ -32,15 +32,15 @@ static int hikp_nic_gro_query(const struct bdf_t *bdf, struct nic_gro_info *info
 	hikp_cmd_init(&header, NIC_MOD, GET_GRO_INFO_CMD, NIC_GRO_INFO_DUMP);
 	cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
 	if (cmd_ret == NULL || cmd_ret->status != 0) {
-		ret = cmd_ret ? -cmd_ret->status : -EIO;
+		ret = cmd_ret ? (int)(-cmd_ret->status) : -EIO;
 		HIKP_ERROR_PRINT("fail to get gro info, retcode: %d\n", ret);
-		free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		return ret;
 	}
 
 	rsp = (struct nic_gro_rsp *)cmd_ret->rsp_data;
 	*info = *(struct nic_gro_info *)rsp->data;
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return 0;
 }
diff --git a/net/nic/nic_info/hikp_nic_info.c b/net/nic/nic_info/hikp_nic_info.c
index cd07b13..49f143f 100644
--- a/net/nic/nic_info/hikp_nic_info.c
+++ b/net/nic/nic_info/hikp_nic_info.c
@@ -70,14 +70,12 @@ static int hikp_nic_get_curr_die_info(void)
 	ret = hikp_nic_get_hw_info(&cmd_ret);
 	if (ret != 0) {
 		HIKP_ERROR_PRINT("Get chip info fail.\n");
-		free(cmd_ret);
-		cmd_ret = NULL;
+		hikp_cmd_free(&cmd_ret);
 		return ret;
 	}
 	info_rsp = (struct nic_info_rsp_t *)(cmd_ret->rsp_data);
 	g_info_param.info = *info_rsp;
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 
 	ret = get_revision_id_by_bdf(&g_info_param.target.bdf, g_info_param.revision_id,
 				     sizeof(g_info_param.revision_id));
diff --git a/net/nic/nic_log/hikp_nic_log.c b/net/nic/nic_log/hikp_nic_log.c
index dc622e0..f182d25 100644
--- a/net/nic/nic_log/hikp_nic_log.c
+++ b/net/nic/nic_log/hikp_nic_log.c
@@ -124,8 +124,7 @@ static int hikp_nic_get_first_blk_info(uint32_t *total_blk_num,
 	*cur_blk_size = (uint32_t)log_rsp->cur_blk_size;
 	memcpy(*log_data, log_rsp->log_data, log_rsp->cur_blk_size);
 err_out:
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
@@ -152,8 +151,7 @@ static int hikp_nic_get_log_info(uint32_t blk_id, uint32_t *cur_blk_size, uint8_
 	}
 	memcpy(log_data, log_rsp->log_data, log_rsp->cur_blk_size);
 err_out:
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
diff --git a/net/nic/nic_mac/hikp_nic_mac_dump.c b/net/nic/nic_mac/hikp_nic_mac_dump.c
index 3e818cd..5439c71 100644
--- a/net/nic/nic_mac/hikp_nic_mac_dump.c
+++ b/net/nic/nic_mac/hikp_nic_mac_dump.c
@@ -40,7 +40,7 @@ static int mac_dump_module_reg(struct major_cmd_ctrl *self, uint32_t cur_blk_id,
 		return self->err_no;
 	}
 	if (cmd_ret->status != 0) {
-		free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		self->err_no = -EINVAL;
 		return self->err_no;
 	}
@@ -53,7 +53,7 @@ static int mac_dump_module_reg(struct major_cmd_ctrl *self, uint32_t cur_blk_id,
 		rsp_data++;
 	}
 
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return 0;
 }
@@ -156,13 +156,13 @@ static int mac_cmd_get_dump_blk_num(struct major_cmd_ctrl *self)
 	if (cmd_ret->status != 0 || cmd_ret->rsp_data_num < MOD_ID_MAX) {
 		HIKP_ERROR_PRINT("nic_mac reg blk num error, rsp_num:%u\n", cmd_ret->rsp_data_num);
 		self->err_no = -EINVAL;
-		free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		return self->err_no;
 	}
 
 	memcpy(g_dump_reg_info.blk_num, cmd_ret->rsp_data, sizeof(g_dump_reg_info.blk_num));
 
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return 0;
 }
diff --git a/net/nic/nic_mac/hikp_nic_port.c b/net/nic/nic_mac/hikp_nic_port.c
index f818001..e28a040 100644
--- a/net/nic/nic_mac/hikp_nic_port.c
+++ b/net/nic/nic_mac/hikp_nic_port.c
@@ -148,8 +148,7 @@ static int mac_cmd_get_dfx_cfg(uint32_t sub_cmd, struct hikp_cmd_ret **cmd_ret)
 		return -ENOSPC;
 
 	if ((*cmd_ret)->status != 0) {
-		free(*cmd_ret);
-		*cmd_ret = NULL;
+		hikp_cmd_free(cmd_ret);
 		return -EAGAIN;
 	}
 
@@ -207,8 +206,7 @@ static void mac_cmd_show_eth_mac(struct major_cmd_ctrl *self)
 
 	mac_dfx = (struct mac_cmd_mac_dfx *)(cmd_ret->rsp_data);
 	mac_cmd_disp_eth_mac_info(mac_dfx);
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void mac_cmd_disp_roh_mac_info(const struct mac_cmd_roh_mac_dfx *mac_dfx)
@@ -240,8 +238,7 @@ static void mac_cmd_show_roh_mac(struct major_cmd_ctrl *self)
 
 	mac_dfx = (struct mac_cmd_roh_mac_dfx *)(cmd_ret->rsp_data);
 	mac_cmd_disp_roh_mac_info(mac_dfx);
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void mac_cmd_show_mac(struct major_cmd_ctrl *self)
@@ -263,8 +260,7 @@ static void mac_cmd_show_mac(struct major_cmd_ctrl *self)
 	else
 		mac_cmd_show_eth_mac(self);
 
-	free(hw_cmd_ret);
-	hw_cmd_ret = NULL;
+	hikp_cmd_free(&hw_cmd_ret);
 }
 
 static void mac_cmd_disp_link_info(struct mac_cmd_link_dfx *link_dfx)
@@ -304,7 +300,7 @@ static void mac_cmd_show_link(struct major_cmd_ctrl *self)
 
 	link_dfx = (struct mac_cmd_link_dfx *)(cmd_ret->rsp_data);
 	mac_cmd_disp_link_info(link_dfx);
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void mac_cmd_disp_phy_reg(const uint16_t *reg, uint32_t num)
@@ -372,13 +368,13 @@ static void mac_cmd_show_phy(struct major_cmd_ctrl *self)
 	if (ret != 0) {
 		printf("hikp_data_proc get phy dfx failed.\n");
 		self->err_no = -ENOSPC;
-		free(phy_cfg_ret);
+		hikp_cmd_free(&phy_cfg_ret);
 		return;
 	}
 	phy_dfx = (struct mac_cmd_phy_dfx *)(phy_dfx_ret->rsp_data);
 	mac_cmd_disp_phy_info(phy_cfg, phy_dfx);
-	free(phy_cfg_ret);
-	free(phy_dfx_ret);
+	hikp_cmd_free(&phy_cfg_ret);
+	hikp_cmd_free(&phy_dfx_ret);
 }
 
 static void mac_cmd_disp_port_param(const char *label, const struct mac_port_param *port)
@@ -442,7 +438,7 @@ static void mac_cmd_show_arb(struct major_cmd_ctrl *self)
 
 	arb_dfx = (struct mac_cmd_arb_dfx *)(cmd_ret->rsp_data);
 	mac_cmd_disp_arb_info(arb_dfx);
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void mac_cmd_show_hot_plug_card(struct major_cmd_ctrl *self)
@@ -460,7 +456,7 @@ static void mac_cmd_show_hot_plug_card(struct major_cmd_ctrl *self)
 
 	hpc_dfx = (struct cmd_hot_plug_card_info *)(cmd_ret->rsp_data);
 	mac_cmd_disp_hot_plug_card_info(hpc_dfx);
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void mac_cmd_print_cdr_dfx(struct mac_cmd_cdr_dfx *cdr_dfx, struct mac_port_cdr_dfx *info)
@@ -534,7 +530,7 @@ static void mac_cmd_show_cdr(struct major_cmd_ctrl *self)
 
 	cdr_dfx = (struct mac_cmd_cdr_dfx *)(cmd_ret->rsp_data);
 	mac_cmd_disp_cdr_info(cdr_dfx);
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void mac_cmd_show_port_dfx(struct major_cmd_ctrl *self, uint32_t mask)
@@ -568,8 +564,7 @@ static int mac_cmd_get_port_dfx_cap(uint32_t *cap)
 	if (ret == 0) {
 		dfx_cap = (struct mac_cmd_port_dfx_cap *)dfx_cap_resp->rsp_data;
 		*cap = dfx_cap->cap_bit_map;
-		free(dfx_cap_resp);
-		dfx_cap_resp = NULL;
+		hikp_cmd_free(&dfx_cap_resp);
 		return ret;
 	}
 
@@ -585,8 +580,7 @@ static int mac_cmd_get_port_dfx_cap(uint32_t *cap)
 	    port_hw->port_type == HIKP_PORT_TYPE_PHY_SDS)
 		*cap |= MAC_LSPORT_PHY;
 
-	free(hw_cmd_ret);
-	hw_cmd_ret = NULL;
+	hikp_cmd_free(&hw_cmd_ret);
 	return ret;
 }
 
diff --git a/net/nic/nic_mac/hikp_nic_xsfp.c b/net/nic/nic_mac/hikp_nic_xsfp.c
index a1294a8..573837b 100644
--- a/net/nic/nic_mac/hikp_nic_xsfp.c
+++ b/net/nic/nic_mac/hikp_nic_xsfp.c
@@ -597,16 +597,14 @@ static int hikp_xsfp_get_raw_data(uint8_t *buf, uint32_t size, uint32_t blk_num)
 		ret = hikp_xsfp_get_cmd_data(&cmd_resp, NIC_XSFP_GET_EEPROM_DATA, i);
 		if (ret != 0) {
 			HIKP_ERROR_PRINT("get optical module eeprom data failed\n");
-			free(cmd_resp);
-			cmd_resp = NULL;
+			hikp_cmd_free(&cmd_resp);
 			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;
+			hikp_cmd_free(&cmd_resp);
 			return -EINVAL;
 		}
 
@@ -616,8 +614,7 @@ static int hikp_xsfp_get_raw_data(uint8_t *buf, uint32_t size, uint32_t blk_num)
 		offset += len;
 
 		/* current cmd interaction is complete, so free cmd_buf */
-		free(cmd_resp);
-		cmd_resp = NULL;
+		hikp_cmd_free(&cmd_resp);
 	}
 
 	return 0;
@@ -700,8 +697,7 @@ static void hikp_xsfp_get_info(struct major_cmd_ctrl *self)
 	hikp_xsfp_get_eeprom_data(self, info->data_size, info->total_blk_num);
 
 ERR_OUT:
-	free(cmd_resp);
-	cmd_resp = NULL;
+	hikp_cmd_free(&cmd_resp);
 }
 
 static int hikp_xsfp_show_help(struct major_cmd_ctrl *self, const char *argv)
diff --git a/net/nic/nic_ncsi/hikp_nic_ncsi.c b/net/nic/nic_ncsi/hikp_nic_ncsi.c
index d09e16f..2e1ea11 100644
--- a/net/nic/nic_ncsi/hikp_nic_ncsi.c
+++ b/net/nic/nic_ncsi/hikp_nic_ncsi.c
@@ -72,8 +72,7 @@ static void nic_ncsi_cmd_execute(struct major_cmd_ctrl *self)
 	nic_ncsi_cmd_print_dfx_info((struct nic_ncsi_cmd_resp *)cmd_resp->rsp_data);
 
 ERR_OUT:
-	free(cmd_resp);
-	cmd_resp = NULL;
+	hikp_cmd_free(&cmd_resp);
 }
 
 static int nic_ncsi_cmd_get_port_info(struct major_cmd_ctrl *self, const char *argv)
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 56b8257..5cd8bfa 100644
--- a/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c
+++ b/net/nic/nic_notify_pkt/hikp_nic_notify_pkt.c
@@ -33,14 +33,13 @@ static int hikp_nic_notify_pkt_query(struct major_cmd_ctrl *self, const struct b
 	self->err_no = hikp_rsp_normal_check(cmd_resp);
 	if (self->err_no) {
 		snprintf(self->err_str, sizeof(self->err_str), "get notify pkt failed.");
-		if (cmd_resp)
-			free(cmd_resp);
+		hikp_cmd_free(&cmd_resp);
 		return self->err_no;
 	}
 
 	rsp = (struct nic_notify_pkt_rsp *)cmd_resp->rsp_data;
 	*info = *(struct nic_notify_pkt_info *)rsp->data;
-	free(cmd_resp);
+	hikp_cmd_free(&cmd_resp);
 
 	return 0;
 }
diff --git a/net/nic/nic_ppp/hikp_nic_ppp.c b/net/nic/nic_ppp/hikp_nic_ppp.c
index 3f777b3..aa63f12 100644
--- a/net/nic/nic_ppp/hikp_nic_ppp.c
+++ b/net/nic/nic_ppp/hikp_nic_ppp.c
@@ -512,7 +512,7 @@ static int hikp_nic_ppp_get_blk(struct hikp_cmd_header *req_header,
 	rsp_head->cur_blk_entry_cnt = rsp->rsp_head.cur_blk_entry_cnt;
 
 out:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
@@ -545,7 +545,7 @@ static int hikp_nic_ppp_query_uc_mac_addr(struct hikp_cmd_header *req_header,
 			return -EINVAL;
 		}
 		if (entry_size + rsp_head.cur_blk_entry_cnt > max_hw_entry_size) {
-			HIKP_ERROR_PRINT("The sum of entry number (%lu) after block-%u "
+			HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u "
 					 "is over the maximum entry nubmer (%u) of unicast MAC table.\n",
 					 entry_size + rsp_head.cur_blk_entry_cnt, idx, max_hw_entry_size);
 			return -EINVAL;
@@ -587,7 +587,7 @@ static int hikp_nic_ppp_query_mc_mac_addr(struct hikp_cmd_header *req_header,
 			return -EINVAL;
 		}
 		if (entry_size + rsp_head.cur_blk_entry_cnt > max_hw_entry_size) {
-			HIKP_ERROR_PRINT("The sum of entry number (%lu) after block-%u "
+			HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u "
 					 "is over the maximum entry nubmer (%u) of multicast MAC table.\n",
 					 entry_size + rsp_head.cur_blk_entry_cnt, idx, max_hw_entry_size);
 			return -EINVAL;
@@ -658,7 +658,7 @@ static int hikp_nic_ppp_query_vf_vlan_tbl(struct hikp_cmd_header *req_header,
 			return -EINVAL;
 		}
 		if (entry_size + rsp_head.cur_blk_entry_cnt > hw_entry_size) {
-			HIKP_ERROR_PRINT("The sum of entry number (%lu) after block-%u "
+			HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u "
 					 "is over the maximum entry nubmer (%u) of VF VLAN table.\n",
 					 entry_size + rsp_head.cur_blk_entry_cnt, idx, hw_entry_size);
 			return -EINVAL;
@@ -699,7 +699,7 @@ static int hikp_nic_ppp_query_port_vlan_tbl(struct hikp_cmd_header *req_header,
 			return -EINVAL;
 		}
 		if (entry_size + rsp_head.cur_blk_entry_cnt > hw_entry_size) {
-			HIKP_ERROR_PRINT("The sum of entry number (%lu) after block-%u "
+			HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u "
 					 "is over the maximum entry nubmer (%u) of port VLAN table.\n",
 					 entry_size + rsp_head.cur_blk_entry_cnt, idx, hw_entry_size);
 			return -EINVAL;
@@ -761,7 +761,7 @@ static int hikp_nic_query_mng_tbl(struct hikp_cmd_header *req_header,
 			return -EINVAL;
 		}
 		if (entry_size + rsp_head.cur_blk_entry_cnt > g_ppp_hw_res.mng_tbl_size) {
-			HIKP_ERROR_PRINT("The sum of entry number (%lu) after block-%u "
+			HIKP_ERROR_PRINT("The sum of entry number (%u) after block-%u "
 					 "is over the maximum entry nubmer (%u) of manager table.\n",
 					 entry_size + rsp_head.cur_blk_entry_cnt, idx, g_ppp_hw_res.mng_tbl_size);
 			return -EINVAL;
@@ -1044,7 +1044,6 @@ static int hikp_nic_ppp_check_input_param(struct major_cmd_ctrl *self,
 }
 
 static int hikp_nic_check_func_id_valid(struct major_cmd_ctrl *self,
-					const struct ppp_feature_cmd *ppp_cmd,
 					const struct nic_ppp_param *ppp_param,
 					const struct hikp_nic_ppp_hw_resources *hw_res)
 {
@@ -1128,7 +1127,7 @@ static void hikp_nic_ppp_cmd_execute(struct major_cmd_ctrl *self)
 	}
 
 	ppp_cmd = &g_ppp_feature_cmd[g_ppp_param.feature_idx];
-	ret = hikp_nic_check_func_id_valid(self, ppp_cmd, &g_ppp_param, &g_ppp_hw_res);
+	ret = hikp_nic_check_func_id_valid(self, &g_ppp_param, &g_ppp_hw_res);
 	if (ret != 0)
 		return;
 
diff --git a/net/nic/nic_qos/hikp_nic_qos.c b/net/nic/nic_qos/hikp_nic_qos.c
index 2de0972..81eb0ba 100644
--- a/net/nic/nic_qos/hikp_nic_qos.c
+++ b/net/nic/nic_qos/hikp_nic_qos.c
@@ -187,7 +187,7 @@ static int hikp_nic_qos_get_blk(struct hikp_cmd_header *req_header,
 	rsp_head->cur_blk_size = rsp->rsp_head.cur_blk_size;
 
 out:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
diff --git a/net/nic/nic_queue/hikp_nic_queue.c b/net/nic/nic_queue/hikp_nic_queue.c
index c73c8f7..dafa05e 100644
--- a/net/nic/nic_queue/hikp_nic_queue.c
+++ b/net/nic/nic_queue/hikp_nic_queue.c
@@ -260,7 +260,7 @@ static int hikp_nic_queue_get_blk(struct hikp_cmd_header *req_header,
 	rsp_head->cur_blk_size = rsp->rsp_head.cur_blk_size;
 
 out:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
diff --git a/net/nic/nic_rss/hikp_nic_rss.c b/net/nic/nic_rss/hikp_nic_rss.c
index 558f931..65336ff 100644
--- a/net/nic/nic_rss/hikp_nic_rss.c
+++ b/net/nic/nic_rss/hikp_nic_rss.c
@@ -378,7 +378,7 @@ static int hikp_nic_rss_get_blk(struct hikp_cmd_header *req_header,
 	rsp_head->cur_blk_size = rsp->rsp_head.cur_blk_size;
 
 out:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
diff --git a/net/nic/nic_torus/hikp_nic_torus.c b/net/nic/nic_torus/hikp_nic_torus.c
index 9483bfe..5208bdc 100644
--- a/net/nic/nic_torus/hikp_nic_torus.c
+++ b/net/nic/nic_torus/hikp_nic_torus.c
@@ -33,16 +33,15 @@ static int hikp_nic_torus_query(const struct bdf_t *bdf,
 	hikp_cmd_init(&header, NIC_MOD, GET_TORUS_INFO_CMD, NIC_TORUS_INFO_DUMP);
 	cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
 	if (cmd_ret == NULL || cmd_ret->status != 0) {
-		ret = cmd_ret ? -cmd_ret->status : -EIO;
+		ret = cmd_ret ? (int)(-cmd_ret->status) : -EIO;
 		HIKP_ERROR_PRINT("fail to get torus info, retcode: %d\n", ret);
-		if (cmd_ret)
-			free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		return ret;
 	}
 
 	rsp = (struct nic_torus_rsp *)cmd_ret->rsp_data;
 	*info = *(struct nic_torus_info *)rsp->data;
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return 0;
 }
diff --git a/net/roce/roce_caep/hikp_roce_caep.c b/net/roce/roce_caep/hikp_roce_caep.c
index 0453bc4..a52cd54 100644
--- a/net/roce/roce_caep/hikp_roce_caep.c
+++ b/net/roce/roce_caep/hikp_roce_caep.c
@@ -99,8 +99,7 @@ static void hikp_roce_caep_execute_origin(struct major_cmd_ctrl *self)
 			     roce_caep_res->reg_data.data);
 
 exec_error:
-	if (cmd_ret)
-		free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void hikp_roce_caep_execute(struct major_cmd_ctrl *self)
diff --git a/net/roce/roce_ext_common/hikp_roce_ext_common.c b/net/roce/roce_ext_common/hikp_roce_ext_common.c
index cc9f509..9c844f4 100644
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.c
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c
@@ -26,12 +26,6 @@ static void hikp_roce_ext_reg_data_free(struct reg_data *reg)
 	}
 }
 
-static void hikp_roce_ext_cmd_ret_free(struct hikp_cmd_ret *cmd_ret)
-{
-	if (cmd_ret)
-		free(cmd_ret);
-}
-
 static const struct cmd_type_info {
 	enum roce_cmd_type cmd_type;
 	const char *cmd_name;
@@ -156,7 +150,7 @@ static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type,
 	       (uint32_t *)&roce_ext_res->reg_data + reg_array_length, cur_size);
 
 get_data_error:
-	hikp_roce_ext_cmd_ret_free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
diff --git a/net/roce/roce_gmv/hikp_roce_gmv.c b/net/roce/roce_gmv/hikp_roce_gmv.c
index bc01ccf..1b7db32 100644
--- a/net/roce/roce_gmv/hikp_roce_gmv.c
+++ b/net/roce/roce_gmv/hikp_roce_gmv.c
@@ -113,8 +113,7 @@ static void hikp_roce_gmv_execute(struct major_cmd_ctrl *self)
 	gmv_rsp = (struct roce_gmv_rsp_data *)(cmd_ret->rsp_data);
 	hikp_roce_gmv_print(reg_num, gmv_rsp);
 exec_error:
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void cmd_roce_gmv_init(void)
diff --git a/net/roce/roce_mdb/hikp_roce_mdb.c b/net/roce/roce_mdb/hikp_roce_mdb.c
index e811bec..a578c87 100644
--- a/net/roce/roce_mdb/hikp_roce_mdb.c
+++ b/net/roce/roce_mdb/hikp_roce_mdb.c
@@ -152,8 +152,7 @@ static void hikp_roce_mdb_execute_origin(struct major_cmd_ctrl *self)
 	hikp_roce_mdb_print(reg_num, mdb_rsp);
 
 exec_error:
-	if (cmd_ret)
-		free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void hikp_roce_mdb_execute(struct major_cmd_ctrl *self)
diff --git a/net/roce/roce_pkt/hikp_roce_pkt.c b/net/roce/roce_pkt/hikp_roce_pkt.c
index 74294c6..81bdae6 100644
--- a/net/roce/roce_pkt/hikp_roce_pkt.c
+++ b/net/roce/roce_pkt/hikp_roce_pkt.c
@@ -55,8 +55,7 @@ static int hikp_roce_pkt_get_data(struct hikp_cmd_ret **cmd_ret, struct roce_pkt
 	ret = hikp_rsp_normal_check(*cmd_ret);
 	if (ret) {
 		printf("hikptool roce_pkt get cmd data failed, ret: %d\n", ret);
-		free(*cmd_ret);
-		*cmd_ret = NULL;
+		hikp_cmd_free(cmd_ret);
 	}
 
 	return ret;
@@ -122,8 +121,7 @@ static void hikp_roce_pkt_execute(struct major_cmd_ctrl *self)
 	hikp_roce_pkt_print(roce_pkt_res->total_block_num,
 			    roce_pkt_res->reg_data.offset, roce_pkt_res->reg_data.data);
 
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void cmd_roce_pkt_init(void)
diff --git a/net/roce/roce_qmm/hikp_roce_qmm.c b/net/roce/roce_qmm/hikp_roce_qmm.c
index 6ab2c84..8140080 100644
--- a/net/roce/roce_qmm/hikp_roce_qmm.c
+++ b/net/roce/roce_qmm/hikp_roce_qmm.c
@@ -246,8 +246,7 @@ static void hikp_roce_qmm_execute_origin(struct major_cmd_ctrl *self)
 	hikp_roce_qmm_print(roce_qmm_res);
 
 exec_error:
-	if (cmd_ret)
-		free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void hikp_roce_qmm_execute(struct major_cmd_ctrl *self)
diff --git a/net/roce/roce_scc/hikp_roce_scc.c b/net/roce/roce_scc/hikp_roce_scc.c
index 0ecb8cf..f330e97 100644
--- a/net/roce/roce_scc/hikp_roce_scc.c
+++ b/net/roce/roce_scc/hikp_roce_scc.c
@@ -103,8 +103,7 @@ static int hikp_roce_scc_get_data(struct hikp_cmd_ret **cmd_ret, const uint32_t
 	ret = hikp_rsp_normal_check(*cmd_ret);
 	if (ret) {
 		printf("hikptool roce_scc get cmd data failed, ret: %d\n", ret);
-		free(*cmd_ret);
-		*cmd_ret = NULL;
+		hikp_cmd_free(cmd_ret);
 	}
 
 	return ret;
@@ -122,14 +121,6 @@ static void hikp_roce_scc_reg_data_free(uint32_t **offset, uint32_t **data)
 	}
 }
 
-static void hikp_roce_scc_cmd_ret_free(struct hikp_cmd_ret **cmd_ret)
-{
-	if (*cmd_ret) {
-		free(*cmd_ret);
-		*cmd_ret = NULL;
-	}
-}
-
 static int hikp_roce_scc_get_total_data_num(struct roce_scc_head *res_head,
 					    uint32_t **offset, uint32_t **data, uint32_t *block_id)
 {
@@ -176,7 +167,7 @@ static int hikp_roce_scc_get_total_data_num(struct roce_scc_head *res_head,
 	ret = 0;
 
 get_data_error:
-	hikp_roce_scc_cmd_ret_free(&cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
@@ -198,7 +189,7 @@ static int hikp_roce_scc_get_next_data(struct roce_scc_head *res_head,
 	roce_scc_res = (struct roce_scc_res_param *)cmd_ret->rsp_data;
 	cur_size = roce_scc_res->head.cur_block_num * sizeof(uint32_t);
 	if (cur_size > data_size) {
-		hikp_roce_scc_cmd_ret_free(&cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		printf("hikptool roce_scc next log data copy size error, "
 		       "data size: 0x%zx, max size: 0x%zx\n", cur_size, data_size);
 		return -EINVAL;
@@ -209,7 +200,7 @@ static int hikp_roce_scc_get_next_data(struct roce_scc_head *res_head,
 	*block_id = roce_scc_res->block_id;
 	res_head->cur_block_num = roce_scc_res->head.cur_block_num;
 	res_head->total_block_num = res_head->total_block_num - roce_scc_res->head.cur_block_num;
-	hikp_roce_scc_cmd_ret_free(&cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return 0;
 }
diff --git a/net/roce/roce_timer/hikp_roce_timer.c b/net/roce/roce_timer/hikp_roce_timer.c
index ea35241..962127b 100644
--- a/net/roce/roce_timer/hikp_roce_timer.c
+++ b/net/roce/roce_timer/hikp_roce_timer.c
@@ -135,8 +135,7 @@ static int hikp_roce_timer_show_qpc(struct major_cmd_ctrl *self)
 	printf("**************QPC TIMER INFO*************\n");
 	hikp_roce_timer_print(timer_rsp, TIMER_SHOW_QPC);
 out:
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
@@ -169,8 +168,7 @@ static int hikp_roce_timer_show_cqc(struct major_cmd_ctrl *self)
 	printf("**************CQC TIMER INFO*************\n");
 	hikp_roce_timer_print(timer_rsp, TIMER_SHOW_CQC);
 out:
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
diff --git a/net/roce/roce_trp/hikp_roce_trp.c b/net/roce/roce_trp/hikp_roce_trp.c
index 486bbe3..68c4cf2 100644
--- a/net/roce/roce_trp/hikp_roce_trp.c
+++ b/net/roce/roce_trp/hikp_roce_trp.c
@@ -123,8 +123,7 @@ static int hikp_roce_trp_get_data(struct hikp_cmd_ret **cmd_ret, const uint32_t
 	ret = hikp_rsp_normal_check(*cmd_ret);
 	if (ret) {
 		printf("hikptool roce_trp get cmd data failed, ret: %d\n", ret);
-		free(*cmd_ret);
-		*cmd_ret = NULL;
+		hikp_cmd_free(cmd_ret);
 	}
 
 	return ret;
@@ -142,14 +141,6 @@ static void hikp_roce_trp_reg_data_free(uint32_t **offset, uint32_t **data)
 	}
 }
 
-static void hikp_roce_trp_cmd_ret_free(struct hikp_cmd_ret **cmd_ret)
-{
-	if (*cmd_ret) {
-		free(*cmd_ret);
-		*cmd_ret = NULL;
-	}
-}
-
 static int hikp_roce_trp_get_total_data_num(struct roce_trp_head *res_head,
 					    uint32_t **offset, uint32_t **data, uint32_t *block_id)
 {
@@ -198,7 +189,7 @@ static int hikp_roce_trp_get_total_data_num(struct roce_trp_head *res_head,
 	ret = 0;
 
 get_data_error:
-	hikp_roce_trp_cmd_ret_free(&cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
@@ -221,7 +212,7 @@ static int hikp_roce_trp_get_next_data(struct roce_trp_head *res_head,
 	cur_size = roce_trp_res->head.cur_block_num * sizeof(uint32_t);
 
 	if (cur_size > data_size) {
-		hikp_roce_trp_cmd_ret_free(&cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		printf("hikptool roce_trp next log data copy size error, "
 		       "data size: 0x%zx, max size: 0x%zx\n", cur_size, data_size);
 		return -EINVAL;
@@ -232,7 +223,7 @@ static int hikp_roce_trp_get_next_data(struct roce_trp_head *res_head,
 	*block_id = roce_trp_res->block_id;
 	res_head->cur_block_num = roce_trp_res->head.cur_block_num;
 	res_head->total_block_num = res_head->total_block_num - roce_trp_res->head.cur_block_num;
-	hikp_roce_trp_cmd_ret_free(&cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return 0;
 }
diff --git a/net/roce/roce_tsp/hikp_roce_tsp.c b/net/roce/roce_tsp/hikp_roce_tsp.c
index b16f0a4..9dd7956 100644
--- a/net/roce/roce_tsp/hikp_roce_tsp.c
+++ b/net/roce/roce_tsp/hikp_roce_tsp.c
@@ -130,8 +130,7 @@ static int hikp_roce_tsp_get_data(struct hikp_cmd_ret **cmd_ret,
 	ret = hikp_rsp_normal_check(*cmd_ret);
 	if (ret) {
 		printf("hikptool roce_tsp get cmd data failed, ret: %d\n", ret);
-		free(*cmd_ret);
-		*cmd_ret = NULL;
+		hikp_cmd_free(cmd_ret);
 	}
 
 	return ret;
@@ -272,8 +271,7 @@ static void hikp_roce_tsp_execute(struct major_cmd_ctrl *self)
 	hikp_roce_tsp_print(roce_tsp_res->total_block_num,
 			    roce_tsp_res->reg_data.offset, roce_tsp_res->reg_data.data);
 
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void cmd_roce_tsp_init(void)
diff --git a/net/roh/hikp_roh_mac.c b/net/roh/hikp_roh_mac.c
index 4a8cf7b..aa13f92 100644
--- a/net/roh/hikp_roh_mac.c
+++ b/net/roh/hikp_roh_mac.c
@@ -87,13 +87,12 @@ int hikp_roh_get_mac_type(struct major_cmd_ctrl *self, struct bdf_t bdf)
 		HIKP_ERROR_PRINT("failed to get roh info, retcode: %u\n",
 				 cmd_ret ? cmd_ret->status : EIO);
 		self->err_no = -EIO;
-		free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		return -EIO;
 	}
 	mac_rsp = (struct roh_mac_get_type *)(cmd_ret->rsp_data);
 	is_roh = mac_rsp->mac_type;
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return is_roh;
 }
 
@@ -145,13 +144,12 @@ static int hikp_roh_get_cam_reg_num(struct major_cmd_ctrl *self)
 		HIKP_ERROR_PRINT("fail to get cam reg num, retcode: %u\n",
 				 cmd_ret ? cmd_ret->status : EIO);
 		self->err_no = -EIO;
-		free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		return -EIO;
 	}
 	mac_rsp = (struct roh_mac_cam_reg_num *)(cmd_ret->rsp_data);
 	cam_reg_num = mac_rsp->cam_reg_num;
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return cam_reg_num;
 }
 
@@ -182,7 +180,7 @@ static int hikp_roh_build_cam(struct major_cmd_ctrl *self, struct cam_table_entr
 			HIKP_ERROR_PRINT("fail to get cam table info, retcode: %u\n",
 					 cmd_ret ? cmd_ret->status : EIO);
 			self->err_no = -EIO;
-			free(cmd_ret);
+			hikp_cmd_free(&cmd_ret);
 			return -EIO;
 		}
 		mac_rsp = (struct roh_mac_cam_table *)(cmd_ret->rsp_data);
@@ -198,8 +196,7 @@ static int hikp_roh_build_cam(struct major_cmd_ctrl *self, struct cam_table_entr
 						(unsigned long)(mac_rsp->cam_mac_high16[j])) <<
 						ROH_MAC_CAM_OFFSET);
 		}
-		free(cmd_ret);
-		cmd_ret = NULL;
+		hikp_cmd_free(&cmd_ret);
 	}
 	return 0;
 }
@@ -222,14 +219,13 @@ static void hikp_roh_show_cam(struct major_cmd_ctrl *self)
 		HIKP_ERROR_PRINT("fail to get cam info, retcode: %u\n",
 				 cmd_ret ? cmd_ret->status : EIO);
 		self->err_no = -EIO;
-		free(cmd_ret);
+		hikp_cmd_free(&cmd_ret);
 		return;
 	}
 	mac_rsp = (struct roh_mac_cam_caps *)cmd_ret->rsp_data;
 	convert_enable = mac_rsp->convert_enable;
 	cam_convert_enable = mac_rsp->cam_convert_enable;
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 
 	ret = hikp_roh_build_cam(self, cam_table);
 	if (ret != 0)
@@ -253,8 +249,7 @@ static int hikp_roh_query_crd(uint8_t crd_type, uint32_t num_rows, char const *c
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	ret = hikp_rsp_normal_check(cmd_ret);
 	if (ret != 0) {
-		free(cmd_ret);
-		cmd_ret = NULL;
+		hikp_cmd_free(&cmd_ret);
 		return ret;
 	}
 	mac_rsp = (struct roh_mac_credit_data *)(cmd_ret->rsp_data);
@@ -268,8 +263,7 @@ static int hikp_roh_query_crd(uint8_t crd_type, uint32_t num_rows, char const *c
 		if ((strcmp(crds[i][1], "NULL") != 0) && (reg.cut)[1] != 0)
 			printf("%-28s : %#x\n", crds[i][1], (reg.cut)[1]);
 	}
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/net/roh/hikp_roh_show_bp.c b/net/roh/hikp_roh_show_bp.c
index 3f3f622..0b53eda 100644
--- a/net/roh/hikp_roh_show_bp.c
+++ b/net/roh/hikp_roh_show_bp.c
@@ -86,8 +86,7 @@ static int hikp_roh_show_bp(struct major_cmd_ctrl *self)
 	printf("MAC%d_flit_bp : 0x%x\n", mac_id, flit_bp);
 
 out:
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
diff --git a/net/roh/hikp_roh_show_mib.c b/net/roh/hikp_roh_show_mib.c
index 91e8344..5f03355 100644
--- a/net/roh/hikp_roh_show_mib.c
+++ b/net/roh/hikp_roh_show_mib.c
@@ -189,8 +189,7 @@ static int hikp_roh_fill_pmu_cnt(int round)
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	ret = hikp_rsp_normal_check(cmd_ret);
 	if (ret != 0) {
-		free(cmd_ret);
-		cmd_ret = NULL;
+		hikp_cmd_free(&cmd_ret);
 		return ret;
 	}
 	mib_rsp = (struct roh_show_mib_rsp_t *)(cmd_ret->rsp_data);
@@ -207,8 +206,7 @@ static int hikp_roh_fill_pmu_cnt(int round)
 		if (mac2_pmu_cnt)
 			printf("MAC2_%-28s : 0x%lx\n", g_roh_mac_mib_name[index], mac2_pmu_cnt);
 	}
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
diff --git a/net/ub/ub_bp/hikp_ub_bp.c b/net/ub/ub_bp/hikp_ub_bp.c
index f5f50ff..179aa22 100644
--- a/net/ub/ub_bp/hikp_ub_bp.c
+++ b/net/ub/ub_bp/hikp_ub_bp.c
@@ -61,16 +61,14 @@ static int hikp_ub_query_bp(const struct bdf_t *bdf)
 	hikp_cmd_init(&header, UB_MOD, GET_UB_BP_INFO_CMD, UB_BP_INFO_DUMP);
 	cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
 	if (cmd_ret == NULL || cmd_ret->status != 0) {
-		free(cmd_ret);
-		cmd_ret = NULL;
+		hikp_cmd_free(&cmd_ret);
 		return -EIO;
 	}
 
 	rsp = (struct ub_bp_rsp *)cmd_ret->rsp_data;
 	hikp_ub_bp_info_show(rsp);
 
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/net/ub/ub_crd/hikp_ub_crd.c b/net/ub/ub_crd/hikp_ub_crd.c
index d564800..6d2ba21 100644
--- a/net/ub/ub_crd/hikp_ub_crd.c
+++ b/net/ub/ub_crd/hikp_ub_crd.c
@@ -85,8 +85,7 @@ static int hikp_ub_query_crd(void)
 	req_data.bdf = g_ub_crd_param.target.bdf;
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	if (cmd_ret == NULL || cmd_ret->status != 0) {
-		free(cmd_ret);
-		cmd_ret = NULL;
+		hikp_cmd_free(&cmd_ret);
 		return -EIO;
 	}
 
@@ -101,8 +100,7 @@ static int hikp_ub_query_crd(void)
 	printf("-------------------  TEMP CREDIT END  --------------------\n");
 	printf("********************* CREDIT CNT END *********************\n");
 
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/net/ub/ub_dfx/hikp_ub_dfx.c b/net/ub/ub_dfx/hikp_ub_dfx.c
index 00205fe..dd3a713 100644
--- a/net/ub/ub_dfx/hikp_ub_dfx.c
+++ b/net/ub/ub_dfx/hikp_ub_dfx.c
@@ -138,8 +138,7 @@ static int hikp_ub_get_first_blk_dfx(struct ub_dfx_rsp_head *rsp_head, uint32_t
 
 	*max_dfx_size -= (uint32_t)rsp_head->cur_blk_size;
 err_out:
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
@@ -170,8 +169,7 @@ static int hikp_ub_get_blk_dfx(struct ub_dfx_rsp_head *rsp_head, uint32_t blk_id
 	*max_dfx_size -= (uint32_t)rsp_head->cur_blk_size;
 
 err_out:
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
diff --git a/net/ub/ub_info/hikp_ub_info.c b/net/ub/ub_info/hikp_ub_info.c
index 3b354dd..d113f7c 100644
--- a/net/ub/ub_info/hikp_ub_info.c
+++ b/net/ub/ub_info/hikp_ub_info.c
@@ -56,16 +56,14 @@ static int hikp_ub_query_basic_info(const struct bdf_t *bdf)
 	hikp_cmd_init(&header, UB_MOD, GET_UB_BASIC_INFO_CMD, UB_BASIC_INFO_DUMP);
 	cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
 	if (cmd_ret == NULL || cmd_ret->status != 0) {
-		free(cmd_ret);
-		cmd_ret = NULL;
+		hikp_cmd_free(&cmd_ret);
 		return -EIO;
 	}
 
 	rsp = (struct ub_info_rsp *)cmd_ret->rsp_data;
 	hikp_ub_basic_info_show(rsp);
 
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/net/ub/ub_link/hikp_ub_link.c b/net/ub/ub_link/hikp_ub_link.c
index b6353f7..1cc1879 100644
--- a/net/ub/ub_link/hikp_ub_link.c
+++ b/net/ub/ub_link/hikp_ub_link.c
@@ -58,16 +58,14 @@ static int hikp_ub_query_link_info(const struct bdf_t *bdf)
 	hikp_cmd_init(&header, UB_MOD, GET_UB_LINK_INFO_CMD, UB_LINK_INFO_DUMP);
 	cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
 	if (cmd_ret == NULL || cmd_ret->status != 0) {
-		free(cmd_ret);
-		cmd_ret = NULL;
+		hikp_cmd_free(&cmd_ret);
 		return -EIO;
 	}
 
 	rsp = (struct ub_link_rsp *)cmd_ret->rsp_data;
 	hikp_ub_link_info_show(rsp);
 
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/net/ub/ub_ppp/hikp_unic_ppp.c b/net/ub/ub_ppp/hikp_unic_ppp.c
index 105253f..01c1624 100644
--- a/net/ub/ub_ppp/hikp_unic_ppp.c
+++ b/net/ub/ub_ppp/hikp_unic_ppp.c
@@ -109,7 +109,7 @@ static int hikp_unic_ppp_get_blk(struct hikp_cmd_header *req_header,
 	memcpy(rsp_head, &rsp->rsp_head, sizeof(struct unic_ppp_rsp_head));
 
 out:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
diff --git a/pcie/func_lib/pcie_func/pcie_link_ltssm.c b/pcie/func_lib/pcie_func/pcie_link_ltssm.c
index 5834612..1bc2edb 100644
--- a/pcie/func_lib/pcie_func/pcie_link_ltssm.c
+++ b/pcie/func_lib/pcie_func/pcie_link_ltssm.c
@@ -15,6 +15,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <inttypes.h>
 #include "os_common.h"
 #include "pcie_common.h"
 #include "hikptdev_plug.h"
@@ -95,7 +96,7 @@ static int pcie_get_ltssm_trace(uint32_t port_id, uint64_t *ltssm_status, uint32
 	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);
+		Err("size check failed, %zu > %zu.\n", src_size, dst_size);
 		ret = -EINVAL;
 		goto free_cmd_ret;
 	}
@@ -110,7 +111,7 @@ static int pcie_get_ltssm_trace(uint32_t port_id, uint64_t *ltssm_status, uint32
 	memcpy(ltssm_status, (cmd_ret->rsp_data + 1), src_size);
 
 free_cmd_ret:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
@@ -187,7 +188,7 @@ static int pcie_print_ltssm_trace(const uint64_t *ltssm_input, uint32_t ltssm_nu
 		return -EINVAL;
 	}
 	Info("ltssm tracer:\n");
-	Info("\ttrace mode: %llx\n", *ltssm_input);
+	Info("\ttrace mode: %" PRIx64 "\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++) {
@@ -245,7 +246,7 @@ int pcie_ltssm_trace_mode_set(uint32_t port_id, uint32_t mode)
 	hikp_cmd_init(&req_header, PCIE_MOD, PCIE_TRACE, TRACE_MODE);
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	ret = hikp_rsp_normal_check(cmd_ret);
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
@@ -261,7 +262,7 @@ int pcie_ltssm_trace_clear(uint32_t port_id)
 	hikp_cmd_init(&req_header, PCIE_MOD, PCIE_TRACE, TRACE_CLEAR);
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	ret = hikp_rsp_normal_check(cmd_ret);
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
@@ -298,7 +299,7 @@ int pcie_ltssm_link_status_get(uint32_t port_id)
 	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);
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
@@ -330,7 +331,7 @@ static int pcie_get_pm_trace(uint32_t port_id, uint64_t *pm_status, uint32_t *pm
 	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);
+		Err("size check failed, %zu > %zu.\n", src_size, dst_size);
 		ret = -EINVAL;
 		goto free_cmd_ret;
 	}
@@ -345,7 +346,7 @@ static int pcie_get_pm_trace(uint32_t port_id, uint64_t *pm_status, uint32_t *pm
 	memcpy(pm_status, (cmd_ret->rsp_data + 1), src_size);
 
 free_cmd_ret:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return ret;
 }
 
@@ -412,7 +413,7 @@ static int pcie_print_pm_trace(const uint64_t *pm_status, uint32_t pm_num)
 		return -EINVAL;
 	}
 	Info("pm tracer:\n");
-	Info("\ttrace state: %llx\n", pm_status[0]);
+	Info("\ttrace state: %" PRIx64 "\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++) {
diff --git a/pcie/func_lib/pcie_func/pcie_reg_dump.c b/pcie/func_lib/pcie_func/pcie_reg_dump.c
index 58fcbea..9444f64 100644
--- a/pcie/func_lib/pcie_func/pcie_reg_dump.c
+++ b/pcie/func_lib/pcie_func/pcie_reg_dump.c
@@ -577,7 +577,7 @@ int pcie_dumpreg_do_dump(uint32_t port_id, uint32_t dump_level)
 close_file_ret:
 	(void)pcie_close_dumpreg_log_file();
 free_cmd_ret:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
diff --git a/pcie/func_lib/pcie_func/pcie_reg_read.c b/pcie/func_lib/pcie_func/pcie_reg_read.c
index 1578056..c04c3d9 100644
--- a/pcie/func_lib/pcie_func/pcie_reg_read.c
+++ b/pcie/func_lib/pcie_func/pcie_reg_read.c
@@ -95,7 +95,7 @@ int pcie_reg_read(uint32_t port_id, uint32_t module_id, uint32_t offset)
 	ret = pcie_reg_read_result_show(cmd_ret);
 
 free_cmd_ret:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
diff --git a/pcie/func_lib/pcie_func/pcie_statistics.c b/pcie/func_lib/pcie_func/pcie_statistics.c
index 6cf7a61..54d4edb 100644
--- a/pcie/func_lib/pcie_func/pcie_statistics.c
+++ b/pcie/func_lib/pcie_func/pcie_statistics.c
@@ -43,8 +43,7 @@ static int port_distribution_rsp_data_check(const struct hikp_cmd_ret *cmd_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("port distribution rsp check failed, size: %u.\n",
-			rsp_data_size);
+		Err("port distribution rsp check failed, size: %zu.\n", rsp_data_size);
 		return -EINVAL;
 	}
 	/* Check whether enough data of n pairs */
@@ -53,7 +52,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("port distribution data size check failed, size: %u, expect size: %u.\n",
+		Err("port distribution data size check failed, size: %zu, expect size: %zu.\n",
 		    rsp_data_size, expect_data_size);
 		return -EINVAL;
 	}
@@ -117,7 +116,7 @@ int pcie_port_distribution_get(uint32_t chip_id)
 					    port_info->info_pair[i].ndie_id);
 	}
 free_cmd_ret:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
@@ -134,7 +133,7 @@ static int port_err_state_rsp_data_check(struct hikp_cmd_ret *cmd_ret)
 	}
 	rsp_data_size = cmd_ret->rsp_data_num * sizeof(uint32_t);
 	if (rsp_data_size < sizeof(struct pcie_err_state)) {
-		Err("err state get rsp size check failed, rsp size: %u, expect size:%u.\n",
+		Err("err state get rsp size check failed, rsp size: %zu, expect size:%zu.\n",
 		    rsp_data_size, sizeof(struct pcie_err_state));
 		return -EINVAL;
 	}
@@ -172,7 +171,7 @@ int pcie_error_state_get(uint32_t port_id)
 	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);
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
@@ -188,7 +187,7 @@ int pcie_error_state_clear(uint32_t port_id)
 	hikp_cmd_init(&req_header, PCIE_MOD, PCIE_INFO, INFO_ERR_STATE_CLEAR);
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	ret = hikp_rsp_normal_check(cmd_ret);
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 
 	return ret;
 }
diff --git a/sas/sas_func/sas_analy_queue.c b/sas/sas_func/sas_analy_queue.c
index b27ba60..f1d2e7e 100644
--- a/sas/sas_func/sas_analy_queue.c
+++ b/sas/sas_func/sas_analy_queue.c
@@ -42,14 +42,14 @@ static int sas_get_res(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	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);
+		hikp_cmd_free(&cmd_ret);
 		return -EINVAL;
 	}
 	*reg_num = cmd_ret->rsp_data_num;
 	for (int i = 0; i < *reg_num; i++)
 		reg_save[i] = cmd_ret->rsp_data[i];
 
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/sas/sas_func/sas_dump_reg.c b/sas/sas_func/sas_dump_reg.c
index 9a1da3a..39fa5ed 100644
--- a/sas/sas_func/sas_dump_reg.c
+++ b/sas/sas_func/sas_dump_reg.c
@@ -34,14 +34,14 @@ static int sas_get_reg(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	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);
+		hikp_cmd_free(&cmd_ret);
 		return -1;
 	}
 	*reg_num = cmd_ret->rsp_data_num;
 	for (int i = 0; i < *reg_num; i++)
 		reg_save[i] = cmd_ret->rsp_data[i];
 
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/sas/sas_func/sas_read_dev.c b/sas/sas_func/sas_read_dev.c
index ede5d74..b5d7e18 100644
--- a/sas/sas_func/sas_read_dev.c
+++ b/sas/sas_func/sas_read_dev.c
@@ -35,14 +35,14 @@ static int sas_get_dev(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	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);
+		hikp_cmd_free(&cmd_ret);
 		return -EINVAL;
 	}
 	*reg_num = cmd_ret->rsp_data_num;
 	for (i = 0; i < *reg_num; i++)
 		reg_save[i] = cmd_ret->rsp_data[i];
 
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/sas/sas_func/sas_read_dqe.c b/sas/sas_func/sas_read_dqe.c
index 072c1dc..dac2546 100644
--- a/sas/sas_func/sas_read_dqe.c
+++ b/sas/sas_func/sas_read_dqe.c
@@ -35,14 +35,14 @@ static int sas_get_dqe(const struct tool_sas_cmd *cmd, uint32_t *reg_save, uint3
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	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);
+		hikp_cmd_free(&cmd_ret);
 		return -EINVAL;
 	}
 	*reg_num = cmd_ret->rsp_data_num;
 	for (int i = 0; i < *reg_num; i++)
 		reg_save[i] = cmd_ret->rsp_data[i];
 
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/sas/sas_func/sas_read_errcode.c b/sas/sas_func/sas_read_errcode.c
index da1157b..d451a98 100644
--- a/sas/sas_func/sas_read_errcode.c
+++ b/sas/sas_func/sas_read_errcode.c
@@ -33,14 +33,14 @@ static int sas_get_errcode(const struct tool_sas_cmd *cmd, uint32_t *reg_save, u
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	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);
+		hikp_cmd_free(&cmd_ret);
 		return -EINVAL;
 	}
 	*reg_num = cmd_ret->rsp_data_num;
 	for (int i = 0; i < *reg_num; i++)
 		reg_save[i] = cmd_ret->rsp_data[i];
 
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/sata/sata_func/sata_dump_reg.c b/sata/sata_func/sata_dump_reg.c
index 691989e..d63a14b 100644
--- a/sata/sata_func/sata_dump_reg.c
+++ b/sata/sata_func/sata_dump_reg.c
@@ -35,14 +35,14 @@ static int sata_get_reg(const struct tool_sata_cmd *cmd, uint32_t *reg_save, uin
 	cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
 	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);
+		hikp_cmd_free(&cmd_ret);
 		return -1;
 	}
 	*reg_num = cmd_ret->rsp_data_num;
 	for (i = 0; i < *reg_num; i++)
 		reg_save[i] = cmd_ret->rsp_data[i];
 
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 	return 0;
 }
 
diff --git a/serdes/hikp_serdes.c b/serdes/hikp_serdes.c
index 23a7946..92e380e 100644
--- a/serdes/hikp_serdes.c
+++ b/serdes/hikp_serdes.c
@@ -342,7 +342,7 @@ static void hikp_serdes_info_cmd_execute(struct major_cmd_ctrl *self)
 	}
 
 err_out:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void cmd_serdes_maininfo_init(void)
@@ -496,7 +496,7 @@ static void hikp_serdes_dump_cmd_execute(struct major_cmd_ctrl *self)
 	dump_data = (uint32_t *)out_put.out_str;
 	hikp_serdes_dump_print(self, dump_data, out_put.result_offset / sizeof(uint32_t));
 err_out:
-	free(cmd_ret);
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void cmd_serdes_dump_init(void)
diff --git a/socip/hikp_socip_dumpreg.c b/socip/hikp_socip_dumpreg.c
index 7b11523..4b6b70c 100644
--- a/socip/hikp_socip_dumpreg.c
+++ b/socip/hikp_socip_dumpreg.c
@@ -143,14 +143,12 @@ static void hikp_socip_dumpreg_execute(struct major_cmd_ctrl *self)
 	if (!cmd_ret || cmd_ret->status != 0) {
 		self->err_no = -EINVAL;
 		HIKP_ERROR_PRINT("hikp_cmd_alloc\n");
-		free(cmd_ret);
-		cmd_ret = NULL;
+		hikp_cmd_free(&cmd_ret);
 		return;
 	}
 
 	dump_reg_info(&cmd_ret->rsp_data[0], cmd_ret->rsp_data_num);
-	free(cmd_ret);
-	cmd_ret = NULL;
+	hikp_cmd_free(&cmd_ret);
 }
 
 static void cmd_socip_dump_reg_init(void)
-- 
2.45.0.windows.1

