On 10/12/2020 8:32 AM, Wei Hu (Xavier) wrote:
From: Chengchang Tang <tangchengch...@huawei.com>
This patch adds checking whether the related Tx or Rx queue has been
setupped in the queue-related API functions to avoid illegal address
access. And validity check of the queue_id is also added in the API
functions rte_eth_dev_rx_intr_enable and rte_eth_dev_rx_intr_disable.
Signed-off-by: Chengchang Tang <tangchengch...@huawei.com>
Signed-off-by: Wei Hu (Xavier) <xavier.hu...@huawei.com>
Signed-off-by: Chengwen Feng <fengcheng...@huawei.com>
---
v2 -> v3:
don't break lines in format strings.
v1 -> v2:
1. replace %"PRIu16" with %u.
2. extact two common functions which validate RXQ/TXQ ids and
whether it has been set up or not.
---
lib/librte_ethdev/rte_ethdev.c | 92 ++++++++++++++++++++++++++++++++++--------
lib/librte_ethdev/rte_ethdev.h | 3 +-
2 files changed, 78 insertions(+), 17 deletions(-)
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 892c246..34eec97 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -877,10 +877,59 @@ rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev,
uint16_t nb_queues)
return 0;
}
+static inline int
+rte_eth_dev_validate_rx_queue(uint16_t port_id, uint16_t rx_queue_id)
+{
+ struct rte_eth_dev *dev;
+
+ RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
+
+ dev = &rte_eth_devices[port_id];
+
Since these are static (internal) functions, why not get "struct rte_eth_dev
*dev" as parameter and drop the port_id validation?
Also for same reason, although there is not convention around it, what do you
think dropping the 'rte_' prefix from the funcitons names, to prevent them
confused by ethdev APIs?
<...>
@@ -4721,7 +4721,8 @@ rte_eth_rx_queue_count(uint16_t port_id, uint16_t
queue_id)
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
dev = &rte_eth_devices[port_id];
RTE_FUNC_PTR_OR_ERR_RET(*dev->rx_queue_count, -ENOTSUP);
- if (queue_id >= dev->data->nb_rx_queues)
+ if (queue_id >= dev->data->nb_rx_queues ||
+ dev->data->rx_queues[queue_id] == NULL)
return -EINVAL;
This will bring additional check for the datapath, but I guess this check is
reasonable since this is an API.