From 15e5379c7a1e041d8ea384f55c6cf77698646ac7 Mon Sep 17 00:00:00 2001 From: Junxian Huang Date: Tue, 7 Nov 2023 15:59:27 +0800 Subject: hikptool/roce: Fix the infinite loop due to compatibility issue When a new-version hikptool sends a subcmd of caep ext registers to an old-version FW which doesn't support the query of ext registers yet, due to the lack of subcmd check in old-version FW, there will be no error and register data will still be responsed to hikptool. In the new-version hikptool, a do-while loop is used to implement a multi-round query, and the loop variable is updated based on the cur_block_num responsed from FW. Since there is no error reported, the new-version hikptool will parse the old-version data based on the new-version data structure. This may cause the parsed cur_block_num remains 0, and the loop becomes infinite. To fix this problem, add a check of the responsed cur_block_num. If it's 0, return with an error code. Fixes: 8b3b68347165 ("hikptool/roce: Add a common frame for hikptool roce register query") Signed-off-by: Junxian Huang --- net/roce/roce_ext_common/hikp_roce_ext_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3a0c1ae..5bc3ce6 100644 --- a/net/roce/roce_ext_common/hikp_roce_ext_common.c +++ b/net/roce/roce_ext_common/hikp_roce_ext_common.c @@ -131,7 +131,7 @@ static int hikp_roce_ext_get_res(enum roce_cmd_type cmd_type, } cur_size = res_head->cur_block_num * sizeof(uint32_t); - if (cur_size > max_size) { + if (!cur_size || cur_size > max_size) { printf("hikptool roce_%s log data copy size error, data size: 0x%zx, max size: 0x%zx\n", cmd_name, cur_size, max_size); ret = -EINVAL; -- 2.30.0