From 40f0b1281cb66cbd19c7ffdab7746857a4d89409 Mon Sep 17 00:00:00 2001
From: Peiyang Wang <wangpeiyang1@huawei.com>
Date: Tue, 20 Aug 2024 16:46:41 +0800
Subject: [PATCH 12/27] hikptool: nic: return real cmd status if alloc failed
 in NIC module

return real cmd status if alloc failed

Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
---
 net/nic/nic_fec/hikp_nic_fec.c       | 11 ++++++-----
 net/nic/nic_ft/hikp_nic_port_fault.c |  9 +++++----
 net/nic/nic_gro/hikp_nic_gro.c       | 11 ++++++-----
 net/nic/nic_torus/hikp_nic_torus.c   |  9 +++++----
 4 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/net/nic/nic_fec/hikp_nic_fec.c b/net/nic/nic_fec/hikp_nic_fec.c
index 342b3eb..edea28b 100644
--- a/net/nic/nic_fec/hikp_nic_fec.c
+++ b/net/nic/nic_fec/hikp_nic_fec.c
@@ -22,19 +22,20 @@ static struct tool_target g_fec_target;
 
 static int hikp_nic_fec_err_query(const struct bdf_t *bdf, struct nic_fec_err_info *info)
 {
-	struct nic_fec_req_para req = { 0 };
 	struct hikp_cmd_header header = { 0 };
+	struct nic_fec_req_para req = { 0 };
 	struct hikp_cmd_ret *cmd_ret;
 	struct nic_fec_rsp *rsp;
+	int ret;
 
 	req.bdf = *bdf;
 	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) {
-		HIKP_ERROR_PRINT("fail to get fec info, retcode: %u\n",
-				 cmd_ret ? cmd_ret->status : EIO);
+		ret = cmd_ret ? -cmd_ret->status : -EIO;
+		HIKP_ERROR_PRINT("fail to get fec info, retcode: %d\n", ret);
 		free(cmd_ret);
-		return -EIO;
+		return ret;
 	}
 
 	rsp = (struct nic_fec_rsp *)cmd_ret->rsp_data;
@@ -111,7 +112,7 @@ static void hikp_nic_fec_err_show(const struct nic_fec_err_info *info)
 static void hikp_nic_fec_cmd_execute(struct major_cmd_ctrl *self)
 {
 	struct bdf_t *bdf = &g_fec_target.bdf;
-	struct nic_fec_err_info info;
+	struct nic_fec_err_info info = { 0 };
 	int ret;
 
 	ret = hikp_nic_fec_err_query(bdf, &info);
diff --git a/net/nic/nic_ft/hikp_nic_port_fault.c b/net/nic/nic_ft/hikp_nic_port_fault.c
index fd94214..85fa874 100644
--- a/net/nic/nic_ft/hikp_nic_port_fault.c
+++ b/net/nic/nic_ft/hikp_nic_port_fault.c
@@ -26,18 +26,19 @@ static int hikp_nic_port_fault_query(const struct bdf_t *bdf,
 	struct hikp_cmd_header header = { 0 };
 	struct nic_port_fault_rsp *rsp;
 	struct hikp_cmd_ret *cmd_ret;
+	int ret = 0;
 
 	req.bdf = *bdf;
 	hikp_cmd_init(&header, NIC_MOD, GET_PORT_FAULT_STATUS,
 		      NIC_PORT_FAULT_INFO_DUMP);
 	cmd_ret = hikp_cmd_alloc(&header, &req, sizeof(req));
 	if (cmd_ret == NULL || cmd_ret->status != 0) {
-		HIKP_ERROR_PRINT("fail to get port fault, retcode: %u\n",
-				 cmd_ret ? cmd_ret->status : EIO);
+		ret = cmd_ret ? -cmd_ret->status : -EIO;
+		HIKP_ERROR_PRINT("fail to get port fault, retcode: %d\n", ret);
 		if (cmd_ret != NULL)
 			free(cmd_ret);
 
-		return -EIO;
+		return ret;
 	}
 
 	rsp = (struct nic_port_fault_rsp *)cmd_ret->rsp_data;
@@ -83,7 +84,7 @@ static void hikp_nic_port_fault_show(struct nic_port_fault_status *info)
 static void hikp_nic_port_fault_cmd_execute(struct major_cmd_ctrl *self)
 {
 	struct bdf_t *bdf = &g_port_fault_target.bdf;
-	struct nic_port_fault_status info;
+	struct nic_port_fault_status info = { 0 };
 	int ret;
 
 	ret = hikp_nic_port_fault_query(bdf, &info);
diff --git a/net/nic/nic_gro/hikp_nic_gro.c b/net/nic/nic_gro/hikp_nic_gro.c
index 84b54c8..d897f11 100644
--- a/net/nic/nic_gro/hikp_nic_gro.c
+++ b/net/nic/nic_gro/hikp_nic_gro.c
@@ -22,19 +22,20 @@ static struct tool_target g_gro_target;
 
 static int hikp_nic_gro_query(const struct bdf_t *bdf, struct nic_gro_info *info)
 {
-	struct nic_gro_req_para req = { 0 };
 	struct hikp_cmd_header header = { 0 };
+	struct nic_gro_req_para req = { 0 };
 	struct hikp_cmd_ret *cmd_ret;
 	struct nic_gro_rsp *rsp;
+	int ret = 0;
 
 	req.bdf = *bdf;
 	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) {
-		HIKP_ERROR_PRINT("fail to get gro info, retcode: %u\n",
-				 cmd_ret ? cmd_ret->status : EIO);
+		ret = cmd_ret ? -cmd_ret->status : -EIO;
+		HIKP_ERROR_PRINT("fail to get gro info, retcode: %d\n", ret);
 		free(cmd_ret);
-		return -EIO;
+		return ret;
 	}
 
 	rsp = (struct nic_gro_rsp *)cmd_ret->rsp_data;
@@ -55,7 +56,7 @@ static void hikp_nic_gro_show(const struct nic_gro_info *info)
 static void hikp_nic_gro_cmd_execute(struct major_cmd_ctrl *self)
 {
 	struct bdf_t *bdf = &g_gro_target.bdf;
-	struct nic_gro_info info;
+	struct nic_gro_info info = { 0 };
 	int ret;
 
 	ret = hikp_nic_gro_query(bdf, &info);
diff --git a/net/nic/nic_torus/hikp_nic_torus.c b/net/nic/nic_torus/hikp_nic_torus.c
index 4baede6..9483bfe 100644
--- a/net/nic/nic_torus/hikp_nic_torus.c
+++ b/net/nic/nic_torus/hikp_nic_torus.c
@@ -27,16 +27,17 @@ static int hikp_nic_torus_query(const struct bdf_t *bdf,
 	struct hikp_cmd_header header = { 0 };
 	struct hikp_cmd_ret *cmd_ret;
 	struct nic_torus_rsp *rsp;
+	int ret = 0;
 
 	req.bdf = *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) {
-		HIKP_ERROR_PRINT("fail to get torus info, retcode: %u\n",
-				 cmd_ret ? cmd_ret->status : EIO);
+		ret = cmd_ret ? -cmd_ret->status : -EIO;
+		HIKP_ERROR_PRINT("fail to get torus info, retcode: %d\n", ret);
 		if (cmd_ret)
 			free(cmd_ret);
-		return -EIO;
+		return ret;
 	}
 
 	rsp = (struct nic_torus_rsp *)cmd_ret->rsp_data;
@@ -133,7 +134,7 @@ static void hikp_nic_torus_show(const struct nic_torus_info *info)
 static void hikp_nic_torus_cmd_execute(struct major_cmd_ctrl *self)
 {
 	struct bdf_t *bdf = &g_torus_target.bdf;
-	struct nic_torus_info info;
+	struct nic_torus_info info = { 0 };
 	int ret;
 
 	ret = hikp_nic_torus_query(bdf, &info);
-- 
2.45.0.windows.1

