Synchronize code, Modify the review comments to increase the reliability of the code Signed-off-by: veega2022 <zhuweijia@huawei.com> (cherry picked from commit d2a23f9ffed0201385c7864b9cd58312fb395cb6)
483 lines
17 KiB
Diff
483 lines
17 KiB
Diff
From 90e86309519707998fa9b2b79df9734ea43f1304 Mon Sep 17 00:00:00 2001
|
||
From: veega2022 <zhuweijia@huawei.com>
|
||
Date: Tue, 12 Nov 2024 19:38:31 +0800
|
||
Subject: [PATCH 19/27] hikptool: Rectify the cleancode issue.
|
||
|
||
Rectify some cleancode alarms.Includes:
|
||
1. Add the function return value verification.
|
||
2. The logic for assigning values to output parameters of functions is optimized.
|
||
3. Use of parentheses.
|
||
4. Fix potential dead loop.
|
||
5. Fix unsigned-signed mixed use.
|
||
|
||
Signed-off-by: veega2022 <zhuweijia@huawei.com>
|
||
---
|
||
net/nic/nic_fd/hikp_nic_fd.c | 2 +-
|
||
net/nic/nic_log/hikp_nic_log.c | 7 +++--
|
||
net/nic/nic_mac/hikp_nic_xsfp.h | 4 +--
|
||
net/nic/nic_ppp/hikp_nic_ppp.c | 10 +++---
|
||
.../roce_ext_common/hikp_roce_ext_common.c | 2 +-
|
||
net/roce/roce_qmm/hikp_roce_qmm.c | 2 +-
|
||
net/roce/roce_timer/hikp_roce_timer.c | 2 +-
|
||
net/roh/hikp_roh_mac.c | 24 ++++++--------
|
||
net/roh/hikp_roh_show_bp.c | 2 +-
|
||
net/roh/hikp_roh_show_mib.c | 2 +-
|
||
net/ub/ub_crd/hikp_ub_crd.c | 4 +--
|
||
net/ub/ub_ppp/hikp_unic_ppp.c | 4 +--
|
||
ossl/ossl_user_linux.c | 10 +++---
|
||
pcie/func_lib/pcie_func/pcie_reg_dump.c | 2 +-
|
||
pcie/func_lib/pcie_func/pcie_statistics.c | 2 +-
|
||
serdes/hikp_serdes.c | 5 ++-
|
||
tool_lib/op_logs.c | 31 +++++++++++++------
|
||
17 files changed, 63 insertions(+), 52 deletions(-)
|
||
|
||
diff --git a/net/nic/nic_fd/hikp_nic_fd.c b/net/nic/nic_fd/hikp_nic_fd.c
|
||
index 7125699..d4a9678 100644
|
||
--- a/net/nic/nic_fd/hikp_nic_fd.c
|
||
+++ b/net/nic/nic_fd/hikp_nic_fd.c
|
||
@@ -630,7 +630,7 @@ static int hikp_nic_query_fd_rules(struct hikp_cmd_header *req_header, const str
|
||
uint16_t max_key_bytes;
|
||
uint32_t left_buf_len;
|
||
size_t one_rule_size;
|
||
- uint16_t idx;
|
||
+ uint32_t idx;
|
||
int ret = 0;
|
||
|
||
if (stage >= NIC_FD_STAGE_NUM) {
|
||
diff --git a/net/nic/nic_log/hikp_nic_log.c b/net/nic/nic_log/hikp_nic_log.c
|
||
index 893aef1..dc622e0 100644
|
||
--- a/net/nic/nic_log/hikp_nic_log.c
|
||
+++ b/net/nic/nic_log/hikp_nic_log.c
|
||
@@ -106,7 +106,9 @@ static int hikp_nic_get_first_blk_info(uint32_t *total_blk_num,
|
||
|
||
log_rsp = (struct nic_log_rsp_data *)(cmd_ret->rsp_data);
|
||
log_size = (uint32_t)(log_rsp->total_blk_num * MAX_LOG_DATA_NUM * sizeof(uint32_t));
|
||
- if (log_size < log_rsp->cur_blk_size) {
|
||
+ if (log_rsp->cur_blk_size == 0 ||
|
||
+ log_size < log_rsp->cur_blk_size ||
|
||
+ log_rsp->cur_blk_size > sizeof(log_rsp->log_data)) {
|
||
HIKP_ERROR_PRINT("log size must bigger than current block size.\n");
|
||
ret = -EINVAL;
|
||
goto err_out;
|
||
@@ -142,7 +144,8 @@ static int hikp_nic_get_log_info(uint32_t blk_id, uint32_t *cur_blk_size, uint8_
|
||
log_rsp = (struct nic_log_rsp_data *)(cmd_ret->rsp_data);
|
||
*cur_blk_size = (uint32_t)log_rsp->cur_blk_size;
|
||
*blk_num = (uint32_t)log_rsp->total_blk_num;
|
||
- if (max_log_size < *cur_blk_size) {
|
||
+ if (max_log_size < *cur_blk_size ||
|
||
+ *cur_blk_size > sizeof(log_rsp->log_data)) {
|
||
HIKP_ERROR_PRINT("log size must bigger than current block(%u) size.\n", blk_id);
|
||
ret = -EINVAL;
|
||
goto err_out;
|
||
diff --git a/net/nic/nic_mac/hikp_nic_xsfp.h b/net/nic/nic_mac/hikp_nic_xsfp.h
|
||
index 6f5e38f..a04ecdc 100644
|
||
--- a/net/nic/nic_mac/hikp_nic_xsfp.h
|
||
+++ b/net/nic/nic_mac/hikp_nic_xsfp.h
|
||
@@ -176,7 +176,7 @@ struct sfp_a0_page {
|
||
uint8_t rsvd_dm : 1;
|
||
};
|
||
uint8_t enhanced_options; /* reg 93: Enhanced Options */
|
||
- uint8_t Sff_8472_compliance; /* reg 94: SFF-8472 Compliance */
|
||
+ uint8_t sff_8472_compliance; /* reg 94: SFF-8472 Compliance */
|
||
uint8_t cc_ext; /* reg 95: Check code for the Extended ID Fields (addresses 64 to 94) */
|
||
|
||
/* 96~255 */
|
||
@@ -247,7 +247,7 @@ struct sfp_page_info {
|
||
#define QSFP_TRANS_OPTICAL_MAX 0x9
|
||
|
||
struct qsfp_page0_lower {
|
||
- uint8_t Identifier; /* reg 0: Identifier (1 Byte) */
|
||
+ uint8_t identifier; /* reg 0: Identifier (1 Byte) */
|
||
uint8_t revision_comp; /* reg 1: Revision Compliance */
|
||
uint8_t status_indicator; /* reg 2: Status Indicators */
|
||
uint8_t tx_rx_los; /* reg 3: Latched Tx/Rx LOS indicator */
|
||
diff --git a/net/nic/nic_ppp/hikp_nic_ppp.c b/net/nic/nic_ppp/hikp_nic_ppp.c
|
||
index 67a3be6..3f777b3 100644
|
||
--- a/net/nic/nic_ppp/hikp_nic_ppp.c
|
||
+++ b/net/nic/nic_ppp/hikp_nic_ppp.c
|
||
@@ -519,13 +519,13 @@ out:
|
||
static int hikp_nic_ppp_query_uc_mac_addr(struct hikp_cmd_header *req_header,
|
||
struct nic_ppp_req_para *req_data,
|
||
struct mac_vlan_uc_tbl *uc_tbl,
|
||
- uint16_t max_hw_entry_size)
|
||
+ uint32_t max_hw_entry_size)
|
||
{
|
||
struct mac_vlan_uc_entry *uc_entry = uc_tbl->entry;
|
||
struct nic_ppp_rsp_head rsp_head = {0};
|
||
uint32_t entry_size = 0;
|
||
size_t left_buf_len;
|
||
- uint16_t idx = 0;
|
||
+ uint32_t idx = 0;
|
||
int ret = 0;
|
||
|
||
while (idx < max_hw_entry_size) {
|
||
@@ -561,13 +561,13 @@ static int hikp_nic_ppp_query_uc_mac_addr(struct hikp_cmd_header *req_header,
|
||
static int hikp_nic_ppp_query_mc_mac_addr(struct hikp_cmd_header *req_header,
|
||
struct nic_ppp_req_para *req_data,
|
||
struct mac_vlan_mc_tbl *mc_tbl,
|
||
- uint16_t max_hw_entry_size)
|
||
+ uint32_t max_hw_entry_size)
|
||
{
|
||
struct mac_vlan_mc_entry *mc_entry = mc_tbl->entry;
|
||
struct nic_ppp_rsp_head rsp_head = {0};
|
||
uint32_t entry_size = 0;
|
||
size_t left_buf_len;
|
||
- uint16_t idx = 0;
|
||
+ uint32_t idx = 0;
|
||
int ret = 0;
|
||
|
||
while (idx < max_hw_entry_size) {
|
||
@@ -1086,7 +1086,7 @@ static int hikp_nic_check_hw_res(struct hikp_nic_ppp_hw_resources *hw_res)
|
||
return -EINVAL;
|
||
}
|
||
if (hw_res->total_func_num == 0 || hw_res->total_func_num > HIKP_NIC_MAX_FUNC_NUM) {
|
||
- HIKP_ERROR_PRINT("Total_func_num (%u)should be in [1, %u].\n",
|
||
+ HIKP_ERROR_PRINT("Total_func_num (%u) should be in [1, %u].\n",
|
||
hw_res->total_func_num, HIKP_NIC_MAX_FUNC_NUM);
|
||
return -EINVAL;
|
||
}
|
||
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 bc3b883..cc9f509 100644
|
||
--- a/net/roce/roce_ext_common/hikp_roce_ext_common.c
|
||
+++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c
|
||
@@ -169,7 +169,7 @@ static void hikp_roce_ext_print(enum roce_cmd_type cmd_type,
|
||
uint8_t arr_len = output->reg_name.arr_len;
|
||
uint32_t *offset = output->reg.offset;
|
||
uint32_t *data = output->reg.data;
|
||
- int i;
|
||
+ uint32_t i;
|
||
|
||
printf("**************%s INFO*************\n", cmd_name);
|
||
printf("%-40s[addr_offset] : reg_data\n", "reg_name");
|
||
diff --git a/net/roce/roce_qmm/hikp_roce_qmm.c b/net/roce/roce_qmm/hikp_roce_qmm.c
|
||
index 9189f88..6ab2c84 100644
|
||
--- a/net/roce/roce_qmm/hikp_roce_qmm.c
|
||
+++ b/net/roce/roce_qmm/hikp_roce_qmm.c
|
||
@@ -154,8 +154,8 @@ static const struct reg_name_info {
|
||
static void hikp_roce_qmm_print(struct roce_qmm_rsp_data *qmm_rsp)
|
||
{
|
||
const char **reg_name;
|
||
+ uint32_t index = 0;
|
||
uint8_t arr_len;
|
||
- int index = 0;
|
||
|
||
for (index = 0; index < HIKP_ARRAY_SIZE(g_qmm_reg_name_info_table); index++) {
|
||
if (g_qmm_reg_name_info_table[index].sub_cmd != g_roce_qmm_param.sub_cmd)
|
||
diff --git a/net/roce/roce_timer/hikp_roce_timer.c b/net/roce/roce_timer/hikp_roce_timer.c
|
||
index a36257e..ea35241 100644
|
||
--- a/net/roce/roce_timer/hikp_roce_timer.c
|
||
+++ b/net/roce/roce_timer/hikp_roce_timer.c
|
||
@@ -84,8 +84,8 @@ static void hikp_roce_timer_print(struct roce_timer_rsp_data *timer_rsp,
|
||
enum roce_timer_cmd_type cmd_type)
|
||
{
|
||
const char **reg_name;
|
||
+ uint32_t index = 0;
|
||
uint8_t arr_len;
|
||
- int index = 0;
|
||
|
||
if (cmd_type == TIMER_SHOW_QPC) {
|
||
reg_name = g_timer_qpc_reg_name;
|
||
diff --git a/net/roh/hikp_roh_mac.c b/net/roh/hikp_roh_mac.c
|
||
index 43f954c..4a8cf7b 100644
|
||
--- a/net/roh/hikp_roh_mac.c
|
||
+++ b/net/roh/hikp_roh_mac.c
|
||
@@ -39,34 +39,29 @@ static int hikp_roh_mac_target(struct major_cmd_ctrl *self, const char *argv)
|
||
return self->err_no;
|
||
}
|
||
|
||
-static int cmd_show_mac_type_parse(void)
|
||
+static void cmd_show_mac_type_parse(void)
|
||
{
|
||
g_roh_mac_param.flag |= CMD_SHOW_MAC_TYPE_FLAG;
|
||
- return 0;
|
||
}
|
||
|
||
-static int cmd_show_cam_parse(void)
|
||
+static void cmd_show_cam_parse(void)
|
||
{
|
||
g_roh_mac_param.flag |= CMD_SHOW_CAM_FLAG;
|
||
- return 0;
|
||
}
|
||
|
||
-static int cmd_show_credit_parse(void)
|
||
+static void cmd_show_credit_parse(void)
|
||
{
|
||
g_roh_mac_param.flag |= CMD_SHOW_CREDIT_CNT;
|
||
- return 0;
|
||
}
|
||
|
||
static int hikp_roh_mac_show_parse(struct major_cmd_ctrl *self, const char *argv)
|
||
{
|
||
- int ret;
|
||
-
|
||
if (strncmp(argv, "cam", sizeof("cam")) == 0) {
|
||
- ret = cmd_show_cam_parse();
|
||
+ cmd_show_cam_parse();
|
||
} else if (strncmp(argv, "mac_type", sizeof("mac_type")) == 0) {
|
||
- ret = cmd_show_mac_type_parse();
|
||
+ cmd_show_mac_type_parse();
|
||
} else if (strncmp(argv, "credit", sizeof("credit")) == 0) {
|
||
- ret = cmd_show_credit_parse();
|
||
+ cmd_show_credit_parse();
|
||
} else {
|
||
hikp_roh_mac_help(self, NULL);
|
||
snprintf(self->err_str, sizeof(self->err_str),
|
||
@@ -74,7 +69,7 @@ static int hikp_roh_mac_show_parse(struct major_cmd_ctrl *self, const char *argv
|
||
self->err_no = -EINVAL;
|
||
return -EINVAL;
|
||
}
|
||
- return ret;
|
||
+ return 0;
|
||
}
|
||
|
||
int hikp_roh_get_mac_type(struct major_cmd_ctrl *self, struct bdf_t bdf)
|
||
@@ -180,7 +175,7 @@ static int hikp_roh_build_cam(struct major_cmd_ctrl *self, struct cam_table_entr
|
||
|
||
for (int i = 0; i < block_num; i++) {
|
||
req_data.bdf = g_roh_mac_param.target.bdf;
|
||
- req_data.cam_block_index = i;
|
||
+ req_data.cam_block_index = (uint32_t)i;
|
||
hikp_cmd_init(&req_header, ROH_MOD, HIKP_ROH_MAC, CMD_BUILD_CAM_TABLE);
|
||
cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
|
||
if (cmd_ret == NULL || cmd_ret->status != 0) {
|
||
@@ -249,6 +244,7 @@ static int hikp_roh_query_crd(uint8_t crd_type, uint32_t num_rows, char const *c
|
||
struct roh_mac_req_para req_data = { 0 };
|
||
struct hikp_cmd_header req_header = { 0 };
|
||
struct hikp_cmd_ret *cmd_ret = NULL;
|
||
+ uint32_t i;
|
||
int ret;
|
||
|
||
hikp_cmd_init(&req_header, ROH_MOD, HIKP_ROH_MAC, CMD_SHOW_CREDIT);
|
||
@@ -262,7 +258,7 @@ static int hikp_roh_query_crd(uint8_t crd_type, uint32_t num_rows, char const *c
|
||
return ret;
|
||
}
|
||
mac_rsp = (struct roh_mac_credit_data *)(cmd_ret->rsp_data);
|
||
- for (int i = 0; i < num_rows; i++) {
|
||
+ for (i = 0; i < num_rows; i++) {
|
||
union cut_reg reg;
|
||
|
||
reg.value = (mac_rsp->cut_reg_value)[i];
|
||
diff --git a/net/roh/hikp_roh_show_bp.c b/net/roh/hikp_roh_show_bp.c
|
||
index 73a53d8..3f3f622 100644
|
||
--- a/net/roh/hikp_roh_show_bp.c
|
||
+++ b/net/roh/hikp_roh_show_bp.c
|
||
@@ -39,7 +39,7 @@ static int hikp_roh_show_bp_target(struct major_cmd_ctrl *self, const char *argv
|
||
|
||
static int hikp_roh_show_bp(struct major_cmd_ctrl *self)
|
||
{
|
||
- uint8_t pfc[8] = { 0 };
|
||
+ uint8_t pfc[BP_SIZE] = { 0 };
|
||
uint8_t egu_tx_bp;
|
||
union bp_val res;
|
||
uint8_t flit_bp;
|
||
diff --git a/net/roh/hikp_roh_show_mib.c b/net/roh/hikp_roh_show_mib.c
|
||
index 7267fe5..91e8344 100644
|
||
--- a/net/roh/hikp_roh_show_mib.c
|
||
+++ b/net/roh/hikp_roh_show_mib.c
|
||
@@ -184,7 +184,7 @@ static int hikp_roh_fill_pmu_cnt(int round)
|
||
|
||
hikp_cmd_init(&req_header, ROH_MOD, HIKP_ROH_SHOW_MIB, CMD_SHOW_MIB_FILL_CNT);
|
||
req_data.bdf = roh_show_mib_param.target.bdf;
|
||
- req_data.round = round;
|
||
+ req_data.round = (uint32_t)round;
|
||
|
||
cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
|
||
ret = hikp_rsp_normal_check(cmd_ret);
|
||
diff --git a/net/ub/ub_crd/hikp_ub_crd.c b/net/ub/ub_crd/hikp_ub_crd.c
|
||
index 91e1cb7..d564800 100644
|
||
--- a/net/ub/ub_crd/hikp_ub_crd.c
|
||
+++ b/net/ub/ub_crd/hikp_ub_crd.c
|
||
@@ -40,8 +40,8 @@ static int hikp_ub_crd_target(struct major_cmd_ctrl *self, const char *argv)
|
||
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;
|
||
+ uint32_t reg_index;
|
||
+ uint32_t i;
|
||
|
||
for (i = 0; i < num_rows; i++) {
|
||
union cut_reg reg;
|
||
diff --git a/net/ub/ub_ppp/hikp_unic_ppp.c b/net/ub/ub_ppp/hikp_unic_ppp.c
|
||
index 2164f04..105253f 100644
|
||
--- a/net/ub/ub_ppp/hikp_unic_ppp.c
|
||
+++ b/net/ub/ub_ppp/hikp_unic_ppp.c
|
||
@@ -69,7 +69,7 @@ static int hikp_unic_cmd_ppp_feature_select(struct major_cmd_ctrl *self, const c
|
||
for (i = 0; i < feat_size; i++) {
|
||
if (strncmp(argv, g_unic_ppp_feature_cmd[i].feature_name,
|
||
HIKP_UNIC_PPP_MAX_FEATURE_NAME_LEN) == 0) {
|
||
- g_unic_ppp_param.feature_idx = i;
|
||
+ g_unic_ppp_param.feature_idx = (int)i;
|
||
return 0;
|
||
}
|
||
}
|
||
@@ -348,7 +348,7 @@ static void hikp_unic_ppp_show_ip_tbl(const void *data)
|
||
struct unic_ip_tbl *ip_tbl = (struct unic_ip_tbl *)data;
|
||
struct unic_ip_entry *entry;
|
||
uint16_t *ip_addr_tbl_str;
|
||
- int i, j;
|
||
+ uint32_t i, j;
|
||
|
||
printf("ip_table_size = %u\n", ip_tbl->entry_size);
|
||
printf("index\t| func_id\t| ip_addr\n");
|
||
diff --git a/ossl/ossl_user_linux.c b/ossl/ossl_user_linux.c
|
||
index a369c68..dc682dd 100644
|
||
--- a/ossl/ossl_user_linux.c
|
||
+++ b/ossl/ossl_user_linux.c
|
||
@@ -47,7 +47,7 @@ int uda_realpath(const char *file_dir, char *format_dir)
|
||
|
||
int uda_fcntl(const char *lock_file, uint32_t operation, int *fd)
|
||
{
|
||
- int fd_t = 0;
|
||
+ int fd_t;
|
||
int ret;
|
||
|
||
if ((fd == NULL) || (lock_file == NULL))
|
||
@@ -57,15 +57,17 @@ int uda_fcntl(const char *lock_file, uint32_t operation, int *fd)
|
||
if (fd_t < 0)
|
||
return -errno;
|
||
|
||
- *fd = fd_t;
|
||
-
|
||
g_fcntl_lock.l_type = F_WRLCK;
|
||
if (operation == UDA_FLOCK_NOBLOCK)
|
||
ret = fcntl(fd_t, F_SETLK, &g_fcntl_lock);
|
||
else
|
||
ret = fcntl(fd_t, F_SETLKW, &g_fcntl_lock);
|
||
- if (ret != 0)
|
||
+ if (ret != 0) {
|
||
close(fd_t);
|
||
+ *fd = -1; /* Assignment -1 is an invalid value */
|
||
+ } else {
|
||
+ *fd = fd_t;
|
||
+ }
|
||
|
||
return ret;
|
||
}
|
||
diff --git a/pcie/func_lib/pcie_func/pcie_reg_dump.c b/pcie/func_lib/pcie_func/pcie_reg_dump.c
|
||
index 856aebe..58fcbea 100644
|
||
--- a/pcie/func_lib/pcie_func/pcie_reg_dump.c
|
||
+++ b/pcie/func_lib/pcie_func/pcie_reg_dump.c
|
||
@@ -559,7 +559,7 @@ int pcie_dumpreg_do_dump(uint32_t port_id, uint32_t dump_level)
|
||
cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data));
|
||
ret = hikp_rsp_normal_check(cmd_ret);
|
||
if (ret) {
|
||
- Err("PCIe DUMPREG", "pcie dump cmd_ret check failed, ret: %d.\n", ret);
|
||
+ Err("pcie dump cmd_ret check failed, ret: %d.\n", ret);
|
||
goto free_cmd_ret;
|
||
}
|
||
ret = pcie_create_dumpreg_log_file(port_id, dump_level);
|
||
diff --git a/pcie/func_lib/pcie_func/pcie_statistics.c b/pcie/func_lib/pcie_func/pcie_statistics.c
|
||
index e2bfcb4..6cf7a61 100644
|
||
--- a/pcie/func_lib/pcie_func/pcie_statistics.c
|
||
+++ b/pcie/func_lib/pcie_func/pcie_statistics.c
|
||
@@ -79,7 +79,7 @@ static int pcie_portid_serdes_relation(const struct pcie_macro_info *macro_info,
|
||
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("\t\tmacro %d \t lane: %d\n", macro_info[i].id, j);
|
||
+ Info("\t\tmacro %u \t lane: %u\n", macro_info[i].id, j);
|
||
}
|
||
return 0;
|
||
}
|
||
diff --git a/serdes/hikp_serdes.c b/serdes/hikp_serdes.c
|
||
index 4afcb9b..23a7946 100644
|
||
--- a/serdes/hikp_serdes.c
|
||
+++ b/serdes/hikp_serdes.c
|
||
@@ -11,7 +11,6 @@
|
||
* See the Mulan PSL v2 for more details.
|
||
*/
|
||
|
||
-#include <unistd.h>
|
||
#include <unistd.h>
|
||
#include <sys/mman.h>
|
||
#include <sys/types.h>
|
||
@@ -75,7 +74,7 @@ static int cmd_serdes_start_lane_id(struct major_cmd_ctrl *self, const char *arg
|
||
|
||
ptr++;
|
||
macro_id = strtol(ptr, &endptr, 10); /* 10:decimal */
|
||
- if (endptr <= ptr)
|
||
+ if ((endptr <= ptr) || (macro_id < 0) || (macro_id > UCHAR_MAX))
|
||
goto _START_LANE_ID_ERR_PRO_;
|
||
|
||
ptr = endptr;
|
||
@@ -87,7 +86,7 @@ static int cmd_serdes_start_lane_id(struct major_cmd_ctrl *self, const char *arg
|
||
if ((endptr <= ptr) || (*endptr != 0))
|
||
goto _START_LANE_ID_ERR_PRO_;
|
||
|
||
- if ((macro_id < 0) || (macro_id > UCHAR_MAX) || (ds_id < 0) || (ds_id > UCHAR_MAX))
|
||
+ if ((ds_id < 0) || (ds_id > UCHAR_MAX))
|
||
goto _START_LANE_ID_ERR_PRO_;
|
||
|
||
g_serdes_param.macro_id = (uint8_t)macro_id;
|
||
diff --git a/tool_lib/op_logs.c b/tool_lib/op_logs.c
|
||
index b6ecc48..6f28ecd 100644
|
||
--- a/tool_lib/op_logs.c
|
||
+++ b/tool_lib/op_logs.c
|
||
@@ -25,29 +25,38 @@ static bool g_record = true;
|
||
static bool g_log_info;
|
||
static char g_input_buf[OP_LOG_FILE_W_MAXSIZE + 1] = {0};
|
||
|
||
-static void op_log_write(const char *log_data)
|
||
+static int op_log_write(const char *log_data)
|
||
{
|
||
size_t w_size;
|
||
FILE *fd;
|
||
|
||
if (strlen(g_op_log) == 0)
|
||
- return;
|
||
+ return -EINVAL;
|
||
|
||
if (!is_file_exist(g_op_log))
|
||
- return;
|
||
+ return -EPERM;
|
||
|
||
fd = fopen(g_op_log, "a");
|
||
if (fd == NULL) {
|
||
HIKP_ERROR_PRINT("Can not open operation log file[%s], errno is %d\n",
|
||
g_op_log, errno);
|
||
- return;
|
||
+ return -errno;
|
||
}
|
||
- (void)chmod(g_op_log, 0640);
|
||
+
|
||
+ if (chmod(g_op_log, 0640)) {
|
||
+ HIKP_ERROR_PRINT("Can not chmod log file[%s], errno is %d\n", g_op_log, errno);
|
||
+ (void)fclose(fd);
|
||
+ return -errno;
|
||
+ }
|
||
+
|
||
w_size = fwrite((void *)log_data, 1U, strlen(log_data), fd);
|
||
- if (strlen(log_data) > ((uint32_t)w_size))
|
||
+ if (strlen(log_data) > ((uint32_t)w_size)) {
|
||
HIKP_ERROR_PRINT("Error data size write to file, errno is %d\n", errno);
|
||
+ (void)fclose(fd);
|
||
+ return -errno;
|
||
+ }
|
||
|
||
- (void)fclose(fd);
|
||
+ return fclose(fd);
|
||
}
|
||
|
||
static int op_log_write_buffer(const char *log_data, const char *log_dir)
|
||
@@ -70,11 +79,13 @@ static int op_log_write_buffer(const char *log_data, const char *log_dir)
|
||
return ret;
|
||
}
|
||
|
||
- op_log_write(log_data);
|
||
+ ret = op_log_write(log_data);
|
||
+ if (ret == 0)
|
||
+ g_log_info = true;
|
||
+
|
||
tool_unlock(&op_lock_fd, UDA_FLOCK_BLOCK);
|
||
- g_log_info = true;
|
||
(void)sigprocmask(SIG_UNBLOCK, &sigset, NULL);
|
||
- return 0;
|
||
+ return ret;
|
||
}
|
||
|
||
void op_log_on(void)
|
||
--
|
||
2.45.0.windows.1
|
||
|