diff options
author | Thomas Monjalon <thomas@monjalon.net> | 2018-04-05 17:33:21 +0200 |
---|---|---|
committer | Thomas Monjalon <thomas@monjalon.net> | 2018-04-18 00:37:05 +0200 |
commit | a9dbe180222680edf8c49e86791f972549ce5be3 (patch) | |
tree | 24de43bfe7364653ede899a7e2a391a1c7bd65b9 /examples/vmdq_dcb/main.c | |
parent | 8728ccf37615904cf23fb8763895b05c9a3c6b0c (diff) |
fix ethdev port id validation
Some DPDK applications wrongly assume these requirements:
- no hotplug, i.e. ports are never detached
- all allocated ports are available to the application
Such application assume a valid port index is in the range [0..count[.
There are three consequences when using such wrong design:
- new ports having an index higher than the port count won't be valid
- old ports being detached (RTE_ETH_DEV_UNUSED) can be valid
Such mistake will be less common with growing hotplug awareness.
All applications and examples inside this repository - except testpmd -
must be fixed to use the function rte_eth_dev_is_valid_port.
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Diffstat (limited to 'examples/vmdq_dcb/main.c')
-rw-r--r-- | examples/vmdq_dcb/main.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/examples/vmdq_dcb/main.c b/examples/vmdq_dcb/main.c index 2016a95716..9c68ab0895 100644 --- a/examples/vmdq_dcb/main.c +++ b/examples/vmdq_dcb/main.c @@ -246,7 +246,7 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool) num_pools, queues_per_pool); } - if (port >= rte_eth_dev_count()) + if (!rte_eth_dev_is_valid_port(port)) return -1; retval = get_eth_conf(&port_conf); @@ -599,9 +599,9 @@ static unsigned check_ports_num(unsigned nb_ports) } for (portid = 0; portid < num_ports; portid++) { - if (ports[portid] >= nb_ports) { - printf("\nSpecified port ID(%u) exceeds max system port ID(%u)\n", - ports[portid], (nb_ports - 1)); + if (!rte_eth_dev_is_valid_port(ports[portid])) { + printf("\nSpecified port ID(%u) is not valid\n", + ports[portid]); ports[portid] = INVALID_PORT_ID; valid_num_ports--; } |