Commit 86db7bfb authored by Peiyang Wang's avatar Peiyang Wang Committed by Paolo Abeni

net: hns3: void array out of bound when loop tnl_num

When query reg inf of SSU, it loops tnl_num times. However, tnl_num comes
from hardware and the length of array is a fixed value. To void array out
of bound, make sure the loop time is not greater than the length of array
Signed-off-by: default avatarPeiyang Wang <wangpeiyang1@huawei.com>
Signed-off-by: default avatarJijie Shao <shaojijie@huawei.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent be5e816d
...@@ -1598,8 +1598,7 @@ static void hclge_query_reg_info_of_ssu(struct hclge_dev *hdev) ...@@ -1598,8 +1598,7 @@ static void hclge_query_reg_info_of_ssu(struct hclge_dev *hdev)
{ {
u32 loop_para[HCLGE_MOD_MSG_PARA_ARRAY_MAX_SIZE] = {0}; u32 loop_para[HCLGE_MOD_MSG_PARA_ARRAY_MAX_SIZE] = {0};
struct hclge_mod_reg_common_msg msg; struct hclge_mod_reg_common_msg msg;
u8 i, j, num; u8 i, j, num, loop_time;
u32 loop_time;
num = ARRAY_SIZE(hclge_ssu_reg_common_msg); num = ARRAY_SIZE(hclge_ssu_reg_common_msg);
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
...@@ -1609,7 +1608,8 @@ static void hclge_query_reg_info_of_ssu(struct hclge_dev *hdev) ...@@ -1609,7 +1608,8 @@ static void hclge_query_reg_info_of_ssu(struct hclge_dev *hdev)
loop_time = 1; loop_time = 1;
loop_para[0] = 0; loop_para[0] = 0;
if (msg.need_para) { if (msg.need_para) {
loop_time = hdev->ae_dev->dev_specs.tnl_num; loop_time = min(hdev->ae_dev->dev_specs.tnl_num,
HCLGE_MOD_MSG_PARA_ARRAY_MAX_SIZE);
for (j = 0; j < loop_time; j++) for (j = 0; j < loop_time; j++)
loop_para[j] = j + 1; loop_para[j] = j + 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment