After the framework fails to apply for memory, the memory needs to be released. The framework returns a processing failure message. The module needs to exit and release the memory.
Signed-off-by: veega zhuweijia@huawei.com --- net/nic/nic_dfx/hikp_nic_dfx.c | 17 +++++++++-------- net/nic/nic_fd/hikp_nic_fd.c | 6 ++++-- net/nic/nic_info/hikp_nic_info.c | 4 +++- net/nic/nic_log/hikp_nic_log.c | 8 ++++---- net/nic/nic_ppp/hikp_nic_ppp.c | 5 +++-- net/nic/nic_qos/hikp_nic_qos.c | 5 +++-- net/nic/nic_queue/hikp_nic_queue.c | 5 +++-- net/nic/nic_rss/hikp_nic_rss.c | 5 +++-- net/roce/roce_pkt/hikp_roce_pkt.c | 11 +++++++---- net/roce/roce_scc/hikp_roce_scc.c | 11 +++++++---- net/roce/roce_trp/hikp_roce_trp.c | 11 +++++++---- net/roce/roce_tsp/hikp_roce_tsp.c | 11 +++++++---- sas/sas_func/sas_analy_queue.c | 3 ++- sas/sas_func/sas_dump_reg.c | 3 ++- sas/sas_func/sas_read_dev.c | 3 ++- sas/sas_func/sas_read_dqe.c | 3 ++- sas/sas_func/sas_read_errcode.c | 3 ++- sata/sata_func/sata_dump_reg.c | 3 ++- serdes/hikp_serdes.c | 8 ++++---- socip/hikp_socip_dumpreg.c | 4 +++- 20 files changed, 79 insertions(+), 50 deletions(-)
diff --git a/net/nic/nic_dfx/hikp_nic_dfx.c b/net/nic/nic_dfx/hikp_nic_dfx.c index 3584493..c734ce0 100644 --- a/net/nic/nic_dfx/hikp_nic_dfx.c +++ b/net/nic/nic_dfx/hikp_nic_dfx.c @@ -123,12 +123,12 @@ static int hikp_nic_get_first_blk_dfx(struct nic_dfx_rsp_head_t *rsp_head, uint3 uint32_t *max_dfx_size, uint32_t *version) { struct nic_dfx_rsp_t *dfx_rsp = NULL; - struct hikp_cmd_ret *cmd_ret; + struct hikp_cmd_ret *cmd_ret = NULL; int ret;
ret = hikp_nic_dfx_get_blk(&cmd_ret, 0, g_dfx_param.sub_cmd_code); if (ret < 0) - return ret; + goto err_out;
dfx_rsp = (struct nic_dfx_rsp_t *)(cmd_ret->rsp_data); *version = cmd_ret->version; @@ -168,12 +168,12 @@ static int hikp_nic_get_blk_dfx(struct nic_dfx_rsp_head_t *rsp_head, uint32_t bl uint32_t *reg_data, uint32_t *max_dfx_size) { struct nic_dfx_rsp_t *dfx_rsp = NULL; - struct hikp_cmd_ret *cmd_ret; + struct hikp_cmd_ret *cmd_ret = NULL; int ret;
ret = hikp_nic_dfx_get_blk(&cmd_ret, blk_id, g_dfx_param.sub_cmd_code); if (ret < 0) - return ret; + goto err_out;
dfx_rsp = (struct nic_dfx_rsp_t *)(cmd_ret->rsp_data); *rsp_head = dfx_rsp->rsp_head; @@ -181,16 +181,17 @@ static int hikp_nic_get_blk_dfx(struct nic_dfx_rsp_head_t *rsp_head, uint32_t bl 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); - free(cmd_ret); - cmd_ret = NULL; - return -EINVAL; + ret = -EINVAL; + goto err_out; } memcpy(reg_data, dfx_rsp->reg_data, rsp_head->cur_blk_size); *max_dfx_size -= (uint32_t)rsp_head->cur_blk_size; + +err_out: free(cmd_ret); cmd_ret = NULL;
- return 0; + return ret; }
static int cmd_dfx_module_select(struct major_cmd_ctrl *self, const char *argv) diff --git a/net/nic/nic_fd/hikp_nic_fd.c b/net/nic/nic_fd/hikp_nic_fd.c index 5a87c30..57bc94b 100644 --- a/net/nic/nic_fd/hikp_nic_fd.c +++ b/net/nic/nic_fd/hikp_nic_fd.c @@ -558,8 +558,10 @@ static int hikp_nic_fd_get_blk(struct hikp_cmd_header *req_header, int ret = 0;
cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); - if (cmd_ret == NULL) - return -EIO; + if (hikp_rsp_normal_check(cmd_ret)) { + ret = -EIO; + goto out; + }
rsp = (struct nic_fd_rsp *)cmd_ret->rsp_data; if (rsp->rsp_head.cur_blk_size > buf_len) { diff --git a/net/nic/nic_info/hikp_nic_info.c b/net/nic/nic_info/hikp_nic_info.c index 1853d95..d84ca18 100644 --- a/net/nic/nic_info/hikp_nic_info.c +++ b/net/nic/nic_info/hikp_nic_info.c @@ -64,12 +64,14 @@ static int hikp_nic_get_hw_info(struct hikp_cmd_ret **cmd_ret) static int hikp_nic_get_curr_die_info(void) { struct nic_info_rsp_t *info_rsp = NULL; - struct hikp_cmd_ret *cmd_ret; + struct hikp_cmd_ret *cmd_ret = NULL; int ret;
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; return ret; } info_rsp = (struct nic_info_rsp_t *)(cmd_ret->rsp_data); diff --git a/net/nic/nic_log/hikp_nic_log.c b/net/nic/nic_log/hikp_nic_log.c index 527f9e9..5cafe4e 100644 --- a/net/nic/nic_log/hikp_nic_log.c +++ b/net/nic/nic_log/hikp_nic_log.c @@ -96,13 +96,13 @@ static int hikp_nic_get_first_blk_info(uint32_t *total_blk_num, uint32_t *cur_blk_size, uint8_t **log_data) { struct nic_log_rsp_data *log_rsp = NULL; - struct hikp_cmd_ret *cmd_ret; + struct hikp_cmd_ret *cmd_ret = NULL; uint32_t log_size; int ret;
ret = hikp_nic_get_blk_log(&cmd_ret, 0); if (ret < 0) - return ret; + goto err_out;
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)); @@ -132,12 +132,12 @@ static int hikp_nic_get_log_info(uint32_t blk_id, uint32_t *cur_blk_size, uint8_ uint32_t max_log_size, uint32_t *blk_num) { struct nic_log_rsp_data *log_rsp = NULL; - struct hikp_cmd_ret *cmd_ret; + struct hikp_cmd_ret *cmd_ret = NULL; int ret;
ret = hikp_nic_get_blk_log(&cmd_ret, blk_id); if (ret) - return ret; + goto err_out;
log_rsp = (struct nic_log_rsp_data *)(cmd_ret->rsp_data); *cur_blk_size = (uint32_t)log_rsp->cur_blk_size; diff --git a/net/nic/nic_ppp/hikp_nic_ppp.c b/net/nic/nic_ppp/hikp_nic_ppp.c index 28c867d..b71fc48 100644 --- a/net/nic/nic_ppp/hikp_nic_ppp.c +++ b/net/nic/nic_ppp/hikp_nic_ppp.c @@ -482,8 +482,9 @@ static int hikp_nic_ppp_get_blk(struct hikp_cmd_header *req_header, int ret = 0;
cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); - if (cmd_ret == NULL) - return -EIO; + ret = hikp_rsp_normal_check(cmd_ret); + if (ret) + goto out;
rsp = (struct nic_ppp_rsp *)cmd_ret->rsp_data; if (rsp->rsp_head.cur_blk_size > buf_len) { diff --git a/net/nic/nic_qos/hikp_nic_qos.c b/net/nic/nic_qos/hikp_nic_qos.c index 2d55e45..6c2db1d 100644 --- a/net/nic/nic_qos/hikp_nic_qos.c +++ b/net/nic/nic_qos/hikp_nic_qos.c @@ -143,9 +143,10 @@ static int hikp_nic_qos_get_blk(struct hikp_cmd_header *req_header, int ret = 0;
cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); - if (cmd_ret == NULL) { + ret = hikp_rsp_normal_check(cmd_ret); + if (ret) { HIKP_ERROR_PRINT("failed to get block-%u context.\n", req_data->block_id); - return -EIO; + goto out; }
rsp = (struct nic_qos_rsp *)cmd_ret->rsp_data; diff --git a/net/nic/nic_queue/hikp_nic_queue.c b/net/nic/nic_queue/hikp_nic_queue.c index 37460c0..f229e09 100644 --- a/net/nic/nic_queue/hikp_nic_queue.c +++ b/net/nic/nic_queue/hikp_nic_queue.c @@ -239,9 +239,10 @@ static int hikp_nic_queue_get_blk(struct hikp_cmd_header *req_header, int ret = 0;
cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); - if (cmd_ret == NULL) { + ret = hikp_rsp_normal_check(cmd_ret); + if (ret) { HIKP_ERROR_PRINT("failed to get block-%u context.\n", req_data->block_id); - return -EIO; + goto out; }
rsp = (struct nic_queue_rsp *)cmd_ret->rsp_data; diff --git a/net/nic/nic_rss/hikp_nic_rss.c b/net/nic/nic_rss/hikp_nic_rss.c index b785ba4..5e4d261 100644 --- a/net/nic/nic_rss/hikp_nic_rss.c +++ b/net/nic/nic_rss/hikp_nic_rss.c @@ -357,9 +357,10 @@ static int hikp_nic_rss_get_blk(struct hikp_cmd_header *req_header, int ret = 0;
cmd_ret = hikp_cmd_alloc(req_header, req_data, sizeof(*req_data)); - if (cmd_ret == NULL) { + ret = hikp_rsp_normal_check(cmd_ret); + if (ret) { HIKP_ERROR_PRINT("failed to get block-%u context.\n", req_data->block_id); - return -EIO; + goto out; }
rsp = (struct nic_rss_rsp *)cmd_ret->rsp_data; diff --git a/net/roce/roce_pkt/hikp_roce_pkt.c b/net/roce/roce_pkt/hikp_roce_pkt.c index abfc526..d3bf885 100644 --- a/net/roce/roce_pkt/hikp_roce_pkt.c +++ b/net/roce/roce_pkt/hikp_roce_pkt.c @@ -48,15 +48,18 @@ static int hikp_roce_pkt_clear_set(struct major_cmd_ctrl *self, const char *argv static int hikp_roce_pkt_get_data(struct hikp_cmd_ret **cmd_ret, struct roce_pkt_req_param req_data) { struct hikp_cmd_header req_header = { 0 }; + int ret;
hikp_cmd_init(&req_header, ROCE_MOD, GET_ROCEE_PKT_CMD, 0); *cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (*cmd_ret == NULL) { - printf("hikptool roce_pkt cmd_ret malloc failed\n"); - return -EIO; + 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; }
- return 0; + return ret; }
static void hikp_roce_pkt_print(uint32_t total_block_num, diff --git a/net/roce/roce_scc/hikp_roce_scc.c b/net/roce/roce_scc/hikp_roce_scc.c index 1011814..e8e166d 100644 --- a/net/roce/roce_scc/hikp_roce_scc.c +++ b/net/roce/roce_scc/hikp_roce_scc.c @@ -88,6 +88,7 @@ static int hikp_roce_scc_get_data(struct hikp_cmd_ret **cmd_ret, const uint32_t { struct roce_scc_req_param req_data = { 0 }; struct hikp_cmd_header req_header = { 0 }; + int ret;
req_data.block_id = *block_id; req_data.bdf = g_roce_scc_param_t.target.bdf; @@ -99,12 +100,14 @@ static int hikp_roce_scc_get_data(struct hikp_cmd_ret **cmd_ret, const uint32_t
hikp_cmd_init(&req_header, ROCE_MOD, GET_ROCEE_SCC_CMD, g_roce_scc_param_t.sub_cmd); *cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (*cmd_ret == NULL) { - printf("hikptool roce_scc cmd_ret malloc failed\n"); - return -EIO; + 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; }
- return 0; + return ret; }
static void hikp_roce_scc_reg_data_free(uint32_t **offset, uint32_t **data) diff --git a/net/roce/roce_trp/hikp_roce_trp.c b/net/roce/roce_trp/hikp_roce_trp.c index bf22484..4591a47 100644 --- a/net/roce/roce_trp/hikp_roce_trp.c +++ b/net/roce/roce_trp/hikp_roce_trp.c @@ -112,6 +112,7 @@ static int hikp_roce_trp_get_data(struct hikp_cmd_ret **cmd_ret, const uint32_t { struct roce_trp_req_param req_data = { 0 }; struct hikp_cmd_header req_header = { 0 }; + int ret;
req_data.block_id = *block_id; req_data.bdf = g_roce_trp_param_t.target.bdf; @@ -122,12 +123,14 @@ static int hikp_roce_trp_get_data(struct hikp_cmd_ret **cmd_ret, const uint32_t } hikp_cmd_init(&req_header, ROCE_MOD, GET_ROCEE_TRP_CMD, g_roce_trp_param_t.sub_cmd); *cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (*cmd_ret == NULL) { - printf("hikptool roce_trp cmd_ret malloc failed\n"); - return -EIO; + 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; }
- return 0; + return ret; }
static void hikp_roce_trp_reg_data_free(uint32_t **offset, uint32_t **data) diff --git a/net/roce/roce_tsp/hikp_roce_tsp.c b/net/roce/roce_tsp/hikp_roce_tsp.c index 5d06ede..ca3126b 100644 --- a/net/roce/roce_tsp/hikp_roce_tsp.c +++ b/net/roce/roce_tsp/hikp_roce_tsp.c @@ -122,6 +122,7 @@ static int hikp_roce_tsp_get_data(struct hikp_cmd_ret **cmd_ret, struct roce_tsp_req_param req_data, uint32_t sub_cmd_code) { struct hikp_cmd_header req_header = { 0 }; + int ret;
if (g_roce_tsp_param_t.sub_cmd_code == 0) { printf("please enter module name: -m/--modlue\n"); @@ -129,12 +130,14 @@ static int hikp_roce_tsp_get_data(struct hikp_cmd_ret **cmd_ret, } hikp_cmd_init(&req_header, ROCE_MOD, GET_ROCEE_TSP_CMD, sub_cmd_code); *cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (*cmd_ret == NULL) { - printf("hikptool roce_tsp cmd_ret malloc failed\n"); - return -EIO; + 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; }
- return 0; + return ret; }
static void hikp_roce_tsp_print(uint32_t total_block_num, diff --git a/sas/sas_func/sas_analy_queue.c b/sas/sas_func/sas_analy_queue.c index ce886b9..8fca197 100644 --- a/sas/sas_func/sas_analy_queue.c +++ b/sas/sas_func/sas_analy_queue.c @@ -40,8 +40,9 @@ 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) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("sas_analy excutes hikp_cmd_alloc err\n"); + free(cmd_ret); return -EINVAL; } *reg_num = cmd_ret->rsp_data_num; diff --git a/sas/sas_func/sas_dump_reg.c b/sas/sas_func/sas_dump_reg.c index d012aa1..5736726 100644 --- a/sas/sas_func/sas_dump_reg.c +++ b/sas/sas_func/sas_dump_reg.c @@ -32,8 +32,9 @@ 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) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("sas_dump excutes hikp_cmd_alloc err\n"); + free(cmd_ret); return -1; } *reg_num = cmd_ret->rsp_data_num; diff --git a/sas/sas_func/sas_read_dev.c b/sas/sas_func/sas_read_dev.c index d01f95f..8b9b58d 100644 --- a/sas/sas_func/sas_read_dev.c +++ b/sas/sas_func/sas_read_dev.c @@ -33,8 +33,9 @@ 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) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("sas_dqe excutes hikp_cmd_alloc err\n"); + free(cmd_ret); return -EINVAL; } *reg_num = cmd_ret->rsp_data_num; diff --git a/sas/sas_func/sas_read_dqe.c b/sas/sas_func/sas_read_dqe.c index 2f653df..dbd30f3 100644 --- a/sas/sas_func/sas_read_dqe.c +++ b/sas/sas_func/sas_read_dqe.c @@ -33,8 +33,9 @@ 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) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("sas_dqe excutes hikp_cmd_alloc err\n"); + free(cmd_ret); return -EINVAL; } *reg_num = cmd_ret->rsp_data_num; diff --git a/sas/sas_func/sas_read_errcode.c b/sas/sas_func/sas_read_errcode.c index 4f89bda..6c7850e 100644 --- a/sas/sas_func/sas_read_errcode.c +++ b/sas/sas_func/sas_read_errcode.c @@ -31,8 +31,9 @@ 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) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("sas_errcode excutes hikp_cmd_alloc err\n"); + free(cmd_ret); return -EINVAL; } *reg_num = cmd_ret->rsp_data_num; diff --git a/sata/sata_func/sata_dump_reg.c b/sata/sata_func/sata_dump_reg.c index 86f6760..b4ff35f 100644 --- a/sata/sata_func/sata_dump_reg.c +++ b/sata/sata_func/sata_dump_reg.c @@ -33,8 +33,9 @@ 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) { + if (cmd_ret == NULL || cmd_ret->status != 0) { printf("hikp_data_proc err\n"); + free(cmd_ret); return -1; } *reg_num = cmd_ret->rsp_data_num; diff --git a/serdes/hikp_serdes.c b/serdes/hikp_serdes.c index 527fd53..320ded2 100644 --- a/serdes/hikp_serdes.c +++ b/serdes/hikp_serdes.c @@ -309,10 +309,10 @@ static void hikp_serdes_info_cmd_execute(struct major_cmd_ctrl *self)
hikp_cmd_init(&req_header, SERDES_MOD, SERDES_KEY_INFO, g_serdes_param.sub_cmd); cmd_ret = hikp_cmd_alloc(&req_header, &hilink_cmd, sizeof(hilink_cmd)); - if (cmd_ret == NULL) { + if (cmd_ret == NULL || cmd_ret->status != 0) { snprintf(self->err_str, sizeof(self->err_str), "hikp_cmd_alloc err."); self->err_no = -EINVAL; - return; + goto err_out; } out_out_header_size = sizeof(out_put.str_len) + sizeof(out_put.result_offset) + sizeof(out_put.type) + sizeof(out_put.ret_val); @@ -467,10 +467,10 @@ static void hikp_serdes_dump_cmd_execute(struct major_cmd_ctrl *self)
hikp_cmd_init(&req_header, SERDES_MOD, SERDES_DUMP_REG, g_serdes_param.sub_cmd); cmd_ret = hikp_cmd_alloc(&req_header, &hilink_cmd, sizeof(hilink_cmd)); - if (cmd_ret == NULL) { + if (cmd_ret == NULL || cmd_ret->status != 0) { self->err_no = -EINVAL; snprintf(self->err_str, sizeof(self->err_str), "hikp_cmd_alloc err."); - return; + goto err_out; } out_out_header_size = sizeof(out_put.str_len) + sizeof(out_put.result_offset) + sizeof(out_put.type) + sizeof(out_put.ret_val); diff --git a/socip/hikp_socip_dumpreg.c b/socip/hikp_socip_dumpreg.c index 32325bb..0153dd9 100644 --- a/socip/hikp_socip_dumpreg.c +++ b/socip/hikp_socip_dumpreg.c @@ -141,9 +141,11 @@ static void hikp_socip_dumpreg_execute(struct major_cmd_ctrl *self) req_data.controller_id = param[CONTROLLER_ID_INDEX].val; hikp_cmd_init(&req_header, SOCIP_MOD, HIKP_SOCIP_CMD_DUMPREG, param[MODULE_ID_INDEX].val); cmd_ret = hikp_cmd_alloc(&req_header, &req_data, sizeof(req_data)); - if (!cmd_ret) { + if (!cmd_ret || cmd_ret->status != 0) { self->err_no = -EINVAL; HIKP_ERROR_PRINT("hikp_cmd_alloc\n"); + free(cmd_ret); + cmd_ret = NULL; return; }