From e51911b2c5daa7f9d650849aaa4f389291415255 Mon Sep 17 00:00:00 2001
From: veega2022 <zhuweijia@huawei.com>
Date: Thu, 11 May 2023 09:29:48 +0800
Subject: [PATCH 14/18] Fix a resource release bug in hikp_roh_get_cam_reg_num

Fix a resource release bug in hikp_roh_get_cam_reg_num

Signed-off-by: chenke chenke54@huawei.com
---
 net/roh/hikp_roh_mac.c     | 6 +++++-
 net/roh/hikp_roh_show_bp.c | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/roh/hikp_roh_mac.c b/net/roh/hikp_roh_mac.c
index 90708b1..43f954c 100644
--- a/net/roh/hikp_roh_mac.c
+++ b/net/roh/hikp_roh_mac.c
@@ -141,6 +141,7 @@ static int hikp_roh_get_cam_reg_num(struct major_cmd_ctrl *self)
 	struct roh_mac_req_para req_data = { 0 };
 	struct hikp_cmd_header req_header = { 0 };
 	struct hikp_cmd_ret *cmd_ret = NULL;
+	uint32_t cam_reg_num;
 
 	req_data.bdf = g_roh_mac_param.target.bdf;
 	hikp_cmd_init(&req_header, ROH_MOD, HIKP_ROH_MAC, CMD_GET_CAM_REG_NUM);
@@ -153,7 +154,10 @@ static int hikp_roh_get_cam_reg_num(struct major_cmd_ctrl *self)
 		return -EIO;
 	}
 	mac_rsp = (struct roh_mac_cam_reg_num *)(cmd_ret->rsp_data);
-	return mac_rsp->cam_reg_num;
+	cam_reg_num = mac_rsp->cam_reg_num;
+	free(cmd_ret);
+	cmd_ret = NULL;
+	return cam_reg_num;
 }
 
 static int hikp_roh_build_cam(struct major_cmd_ctrl *self, struct cam_table_entry_t *cam_table)
diff --git a/net/roh/hikp_roh_show_bp.c b/net/roh/hikp_roh_show_bp.c
index c89e98b..73a53d8 100644
--- a/net/roh/hikp_roh_show_bp.c
+++ b/net/roh/hikp_roh_show_bp.c
@@ -44,7 +44,7 @@ static int hikp_roh_show_bp(struct major_cmd_ctrl *self)
 	union bp_val res;
 	uint8_t flit_bp;
 	int mac_id;
-	int ret;
+	int ret = 0;
 
 	struct hikp_cmd_ret *cmd_ret = NULL;
 	struct hikp_cmd_header req_header = { 0 };
-- 
2.25.1

