From 3ba4957b2ea84b1cf93ec7e4b2e0e3c00672f6c9 Mon Sep 17 00:00:00 2001
From: Jie Hai <haijie1@huawei.com>
Date: Tue, 22 Oct 2024 12:01:13 +0800
Subject: [PATCH] net/hns3: fix pointer offset for registers

[ upstream commit 013fdd2d7b319e6a35d966f375e33ee330d9ccb5 ]

If the register values of multiple modules are obtained at a time,
the register values are incorrect because the data field to be filled
pointing to a wrong address. Update the pointer offset of data to
get the correct address.

Fixes: dd4b8bba785f ("net/hns3: support reporting names of registers")
Cc: stable@dpdk.org

Signed-off-by: Jie Hai <haijie1@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/net/hns3/hns3_regs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/hns3/hns3_regs.c b/drivers/net/hns3/hns3_regs.c
index def775a..83dda4b 100644
--- a/drivers/net/hns3/hns3_regs.c
+++ b/drivers/net/hns3/hns3_regs.c
@@ -1274,6 +1274,7 @@ hns3_get_dfx_regs(struct hns3_hw *hw, struct rte_dev_reg_info *regs, uint32_t mo
 	if (cmd_descs == NULL)
 		return -ENOMEM;
 
+	data += regs->length;
 	for (i = 0; i < opcode_num; i++) {
 		opcode = hns3_dfx_reg_opcode_list[i];
 		bd_num = bd_num_list[i];
@@ -1285,7 +1286,6 @@ hns3_get_dfx_regs(struct hns3_hw *hw, struct rte_dev_reg_info *regs, uint32_t mo
 		if (ret)
 			break;
 
-		data += regs->length;
 		regs_num = hns3_dfx_reg_fetch_data(cmd_descs, bd_num, data);
 		if (regs_num !=  hns3_reg_lists[i].entry_num) {
 			hns3_err(hw, "Query register number differ from the list for module %s!",
@@ -1294,6 +1294,7 @@ hns3_get_dfx_regs(struct hns3_hw *hw, struct rte_dev_reg_info *regs, uint32_t mo
 		}
 		hns3_fill_dfx_regs_name(hw, regs, hns3_reg_lists[i].reg_list, regs_num);
 		regs->length += regs_num;
+		data += regs_num;
 	}
 	rte_free(cmd_descs);
 
-- 
2.33.0

