From: Jie Liu <[email protected]>
sxe2_dev_infos_get() dereferences adapter->vsi_ctxt.main_vsi without
checking for NULL, which can crash when the main VSI has not been
created yet.
Add an early NULL check on vsi and return -EINVAL.
Fixes: d8e4e075ac ("net/sxe2: add probing skeleton")
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Jie Liu <[email protected]>
---
drivers/net/sxe2/sxe2_ethdev.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/net/sxe2/sxe2_ethdev.c b/drivers/net/sxe2/sxe2_ethdev.c
index 2e14c372f8..02f9ce3d32 100644
--- a/drivers/net/sxe2/sxe2_ethdev.c
+++ b/drivers/net/sxe2/sxe2_ethdev.c
@@ -781,6 +781,10 @@ static int32_t sxe2_dev_infos_get(struct rte_eth_dev *dev,
struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
struct sxe2_vsi *vsi = adapter->vsi_ctxt.main_vsi;
+ if (unlikely(vsi == NULL)) {
+ PMD_LOG_ERR(INIT, "main vsi is NULL");
+ return -EINVAL;
+ }
dev_info->max_rx_queues = vsi->rxqs.q_cnt;
dev_info->max_tx_queues = vsi->txqs.q_cnt;
dev_info->min_rx_bufsize = SXE2_MIN_BUF_SIZE;
--
2.52.0