From 75306ee088915446c50e5525fc657fad28ee6935 Mon Sep 17 00:00:00 2001 From: Lance Richardson Date: Thu, 18 Jul 2019 09:06:13 +0530 Subject: [PATCH] net/bnxt: fix getting statistics Avoid overrun in rte_eth_stats struct when the number of tx/rx rings in use is greater than RTE_ETHDEV_QUEUE_STAT_CNTRS. Fixes: 57d5e5bc86e4 ("net/bnxt: add statistics") Cc: stable@dpdk.org Signed-off-by: Lance Richardson Reviewed-by: Kalesh AP Reviewed-by: Ajit Khaparde --- drivers/net/bnxt/bnxt_stats.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/bnxt/bnxt_stats.c b/drivers/net/bnxt/bnxt_stats.c index 3cd5144ec1..4e74f8a279 100644 --- a/drivers/net/bnxt/bnxt_stats.c +++ b/drivers/net/bnxt/bnxt_stats.c @@ -351,6 +351,7 @@ int bnxt_stats_get_op(struct rte_eth_dev *eth_dev, int rc = 0; unsigned int i; struct bnxt *bp = eth_dev->data->dev_private; + unsigned int num_q_stats; memset(bnxt_stats, 0, sizeof(*bnxt_stats)); if (!(bp->flags & BNXT_FLAG_INIT_DONE)) { @@ -358,7 +359,10 @@ int bnxt_stats_get_op(struct rte_eth_dev *eth_dev, return -1; } - for (i = 0; i < bp->rx_cp_nr_rings; i++) { + num_q_stats = RTE_MIN(bp->rx_cp_nr_rings, + (unsigned int)RTE_ETHDEV_QUEUE_STAT_CNTRS); + + for (i = 0; i < num_q_stats; i++) { struct bnxt_rx_queue *rxq = bp->rx_queues[i]; struct bnxt_cp_ring_info *cpr = rxq->cp_ring; @@ -370,7 +374,10 @@ int bnxt_stats_get_op(struct rte_eth_dev *eth_dev, rte_atomic64_read(&rxq->rx_mbuf_alloc_fail); } - for (i = 0; i < bp->tx_cp_nr_rings; i++) { + num_q_stats = RTE_MIN(bp->tx_cp_nr_rings, + (unsigned int)RTE_ETHDEV_QUEUE_STAT_CNTRS); + + for (i = 0; i < num_q_stats; i++) { struct bnxt_tx_queue *txq = bp->tx_queues[i]; struct bnxt_cp_ring_info *cpr = txq->cp_ring; -- 2.20.1