With current implementation, we are not checking for queue_id range
and stat_idx range in stats mapping function. This patch will add
check for queue_id and stat_idx range.

Fixes: 5de201df892 ("ethdev: add stats per queue")

Signed-off-by: Kiran Kumar <kkokkilaga...@caviumnetworks.com>
Acked-by: Andrew Rybchenko <arybche...@solarflare.com>
---
 v2 changes:
 - changed summery

 lib/librte_ethdev/rte_ethdev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index a9977df..0849016 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -2457,6 +2457,16 @@ set_queue_stats_mapping(uint16_t port_id, uint16_t 
queue_id, uint8_t stat_idx,
        dev = &rte_eth_devices[port_id];

        RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, 
-ENOTSUP);
+
+       if (is_rx && (queue_id >= dev->data->nb_rx_queues))
+               return -EINVAL;
+
+       if (!is_rx && (queue_id >= dev->data->nb_tx_queues))
+               return -EINVAL;
+
+       if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
+               return -EINVAL;
+
        return (*dev->dev_ops->queue_stats_mapping_set)
                        (dev, queue_id, stat_idx, is_rx);
 }
--
2.7.4

Reply via email to