[PATCH] net/nfp: fix the initialization of physical representors

Chaoyong He chaoyong.he at corigine.com
Tue Oct 10 08:03:12 CEST 2023


From: Zerun Fu <zerun.fu at corigine.com>

The former logic of initializing the array of physical port
representors is according to 'nfp_idx', but referencing based
on 'port_id'. This is a potential bug and will cause segment
fault when these two values are not equal. Fix it by using the
'port_id' as index at all time.

Fixes: e1124c4f8a45 ("net/nfp: add flower representor framework")
Cc: chaoyong.he at corigine.com
Cc: stable at dpdk.org

Signed-off-by: Zerun Fu <zerun.fu at corigine.com>
Reviewed-by: Long Wu <long.wu at corigine.com>
Reviewed-by: Peng Zhang <peng.zhang at corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he at corigine.com>
---
 drivers/net/nfp/flower/nfp_flower_representor.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
index 55ca3e6db0..e4c5d765e7 100644
--- a/drivers/net/nfp/flower/nfp_flower_representor.c
+++ b/drivers/net/nfp/flower/nfp_flower_representor.c
@@ -646,6 +646,7 @@ nfp_flower_repr_init(struct rte_eth_dev *eth_dev,
 		void *init_params)
 {
 	int ret;
+	uint16_t index;
 	unsigned int numa_node;
 	char ring_name[RTE_ETH_NAME_MAX_LEN];
 	struct nfp_app_fw_flower *app_fw_flower;
@@ -719,10 +720,13 @@ nfp_flower_repr_init(struct rte_eth_dev *eth_dev,
 	}
 
 	/* Add repr to correct array */
-	if (repr->repr_type == NFP_REPR_TYPE_PHYS_PORT)
-		app_fw_flower->phy_reprs[repr->nfp_idx] = repr;
-	else
-		app_fw_flower->vf_reprs[repr->vf_id] = repr;
+	if (repr->repr_type == NFP_REPR_TYPE_PHYS_PORT) {
+		index = NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM(repr->port_id);
+		app_fw_flower->phy_reprs[index] = repr;
+	} else {
+		index = repr->vf_id;
+		app_fw_flower->vf_reprs[index] = repr;
+	}
 
 	return 0;
 
-- 
2.39.1



More information about the stable mailing list