From: Ajay Sharma <sharmaa...@microsoft.com>
Date: Mon, 22 May 2023 20:24:39 -0700
Subject: [PATCH] Add checks for the port capabilties
Add checks to the values retrieved from the firmware to prevent
overflow.
Signed-off-by: Ajay Sharma <sharmaa...@microsoft.com>
---
drivers/net/mana/mana.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/net/mana/mana.c b/drivers/net/mana/mana.c
index 7630118d4f..3a7e302c86 100644
--- a/drivers/net/mana/mana.c
+++ b/drivers/net/mana/mana.c
@@ -292,8 +292,9 @@ mana_dev_info_get(struct rte_eth_dev *dev,
dev_info->min_rx_bufsize = MIN_RX_BUF_SIZE;
dev_info->max_rx_pktlen = MAX_FRAME_SIZE;
- dev_info->max_rx_queues = priv->max_rx_queues;
- dev_info->max_tx_queues = priv->max_tx_queues;
+ dev_info->max_rx_queues = RTE_MIN(priv->max_rx_queues, USHRT_MAX);
+ dev_info->max_tx_queues = RTE_MIN(priv->max_tx_queues, USHRT_MAX);
+
dev_info->max_mac_addrs = MANA_MAX_MAC_ADDR;
dev_info->max_hash_mac_addrs = 0;
@@ -334,16 +335,17 @@ mana_dev_info_get(struct rte_eth_dev *dev,
/* Buffer limits */
dev_info->rx_desc_lim.nb_min = MIN_BUFFERS_PER_QUEUE;
- dev_info->rx_desc_lim.nb_max = priv->max_rx_desc;
+ dev_info->rx_desc_lim.nb_max = RTE_MIN(priv->max_rx_desc, USHRT_MAX);
dev_info->rx_desc_lim.nb_align = MIN_BUFFERS_PER_QUEUE;
- dev_info->rx_desc_lim.nb_seg_max = priv->max_recv_sge;
- dev_info->rx_desc_lim.nb_mtu_seg_max = priv->max_recv_sge;
+ dev_info->rx_desc_lim.nb_seg_max = RTE_MIN(priv->max_recv_sge,
USHRT_MAX);
+ dev_info->rx_desc_lim.nb_mtu_seg_max = RTE_MIN(priv->max_recv_sge,
USHRT_MAX);
+
dev_info->tx_desc_lim.nb_min = MIN_BUFFERS_PER_QUEUE;
- dev_info->tx_desc_lim.nb_max = priv->max_tx_desc;
+ dev_info->tx_desc_lim.nb_max = RTE_MIN(priv->max_tx_desc, USHRT_MAX);
dev_info->tx_desc_lim.nb_align = MIN_BUFFERS_PER_QUEUE;
- dev_info->tx_desc_lim.nb_seg_max = priv->max_send_sge;
- dev_info->rx_desc_lim.nb_mtu_seg_max = priv->max_recv_sge;
+ dev_info->tx_desc_lim.nb_seg_max = RTE_MIN(priv->max_send_sge,
USHRT_MAX);
+ dev_info->rx_desc_lim.nb_mtu_seg_max = RTE_MIN(priv->max_recv_sge,
USHRT_MAX);
/* Speed */
dev_info->speed_capa = RTE_ETH_LINK_SPEED_100G;
--
2.25.1
56