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>
This commit is contained in:
Thomas Monjalon 2018-04-05 17:33:21 +02:00
parent 8728ccf376
commit a9dbe18022
36 changed files with 61 additions and 148 deletions

View File

@ -553,11 +553,10 @@ configure_vdev(uint16_t port_id)
{
struct ether_addr addr;
const uint16_t rxRings = 0, txRings = 1;
const uint8_t nb_ports = rte_eth_dev_count();
int ret;
uint16_t q;
if (port_id > nb_ports)
if (!rte_eth_dev_is_valid_port(port_id))
return -1;
ret = rte_eth_dev_configure(port_id, rxRings, txRings,

View File

@ -5655,11 +5655,6 @@ static void cmd_set_bond_mon_period_parsed(void *parsed_result,
struct cmd_set_bond_mon_period_result *res = parsed_result;
int ret;
if (res->port_num >= nb_ports) {
printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
return;
}
ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
/* check the return value and print it if is < 0 */
@ -5716,12 +5711,6 @@ cmd_set_bonding_agg_mode(void *parsed_result,
struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
uint8_t policy = AGG_BANDWIDTH;
if (res->port_num >= nb_ports) {
printf("Port id %d must be less than %d\n",
res->port_num, nb_ports);
return;
}
if (!strcmp(res->policy, "bandwidth"))
policy = AGG_BANDWIDTH;
else if (!strcmp(res->policy, "stable"))
@ -10869,11 +10858,6 @@ cmd_flow_director_mask_parsed(void *parsed_result,
struct rte_eth_fdir_masks *mask;
struct rte_port *port;
if (res->port_id > nb_ports) {
printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
return;
}
port = &ports[res->port_id];
/** Check if the port is not started **/
if (port->port_status != RTE_PORT_STOPPED) {
@ -11070,11 +11054,6 @@ cmd_flow_director_flex_mask_parsed(void *parsed_result,
uint16_t i;
int ret;
if (res->port_id > nb_ports) {
printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
return;
}
port = &ports[res->port_id];
/** Check if the port is not started **/
if (port->port_status != RTE_PORT_STOPPED) {
@ -11226,11 +11205,6 @@ cmd_flow_director_flxpld_parsed(void *parsed_result,
struct rte_port *port;
int ret = 0;
if (res->port_id > nb_ports) {
printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
return;
}
port = &ports[res->port_id];
/** Check if the port is not started **/
if (port->port_status != RTE_PORT_STOPPED) {
@ -14611,11 +14585,6 @@ cmd_ddp_add_parsed(
int file_num;
int ret = -ENOTSUP;
if (res->port_id > nb_ports) {
printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
return;
}
if (!all_ports_stopped()) {
printf("Please stop all ports first\n");
return;
@ -14693,11 +14662,6 @@ cmd_ddp_del_parsed(
uint32_t size;
int ret = -ENOTSUP;
if (res->port_id > nb_ports) {
printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
return;
}
if (!all_ports_stopped()) {
printf("Please stop all ports first\n");
return;
@ -15008,11 +14972,6 @@ cmd_ddp_get_list_parsed(
#endif
int ret = -ENOTSUP;
if (res->port_id > nb_ports) {
printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
return;
}
#ifdef RTE_LIBRTE_I40E_PMD
size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
@ -15086,11 +15045,6 @@ cmd_cfg_input_set_parsed(
#endif
int ret = -ENOTSUP;
if (res->port_id > nb_ports) {
printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
return;
}
if (!all_ports_stopped()) {
printf("Please stop all ports first\n");
return;
@ -15214,11 +15168,6 @@ cmd_clear_input_set_parsed(
#endif
int ret = -ENOTSUP;
if (res->port_id > nb_ports) {
printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
return;
}
if (!all_ports_stopped()) {
printf("Please stop all ports first\n");
return;

View File

@ -279,9 +279,6 @@ Forwarding application is shown below:
int retval;
uint16_t q;
if (port >= rte_eth_dev_count())
return -1;
/* Configure the Ethernet device. */
retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
if (retval != 0)

View File

@ -511,11 +511,6 @@ Application may choose to not implement following callbacks:
int ret;
struct rte_eth_conf conf;
if (port_id >= rte_eth_dev_count()) {
RTE_LOG(ERR, APP, "Invalid port id %d\n", port_id);
return -EINVAL;
}
RTE_LOG(INFO, APP, "Change MTU of port %d to %u\n", port_id, new_mtu);
/* Stop specific port */
@ -559,11 +554,6 @@ Application may choose to not implement following callbacks:
{
int ret = 0;
if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) {
RTE_LOG(ERR, APP, "Invalid port id %d\n", port_id);
return -EINVAL;
}
RTE_LOG(INFO, APP, "Configure network interface of %d %s\n",
port_id, if_up ? "up" : "down");

View File

@ -178,11 +178,6 @@ in the *DPDK Programmer's Guide* and the *DPDK API Reference*.
.. code-block:: c
nb_ports = rte_eth_dev_count();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
/* reset l2fwd_dst_ports */
for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++)

View File

@ -197,11 +197,6 @@ in the *DPDK Programmer's Guide* - Rel 1.4 EAR and the *DPDK API Reference*.
if (rte_pci_probe() < 0)
rte_exit(EXIT_FAILURE, "Cannot probe PCI\n");
nb_ports = rte_eth_dev_count();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
/* reset l2fwd_dst_ports */
for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++)

View File

@ -91,10 +91,6 @@ To fully understand this code, it is recommended to study the chapters that rela
if (rte_pci_probe() < 0)
rte_exit(EXIT_FAILURE, "Cannot probe PCI\n");
nb_ports = rte_eth_dev_count();
if (nb_ports == 0)
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
/*
* Each logical core is assigned a dedicated TX queue on each port.
*/

View File

@ -83,9 +83,6 @@ comments:
int retval;
uint16_t q;
if (port >= rte_eth_dev_count())
return -1;
/* Configure the Ethernet device. */
retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
if (retval != 0)

View File

@ -119,7 +119,7 @@ Forwarding application is shown below:
int retval;
uint16_t q;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
/* Configure the Ethernet device. */
@ -192,7 +192,6 @@ looks like the following:
static __attribute__((noreturn)) void
lcore_main(void)
{
const uint16_t nb_ports = rte_eth_dev_count();
uint16_t port;
/*

View File

@ -1017,7 +1017,7 @@ int
main(int argc, char **argv)
{
int ret;
unsigned int nb_bbdevs, nb_ports, flags, lcore_id;
unsigned int nb_bbdevs, flags, lcore_id;
void *sigret;
struct app_config_params app_params = def_app_config;
struct rte_mempool *ethdev_mbuf_mempool, *bbdev_mbuf_mempool;
@ -1079,12 +1079,10 @@ main(int argc, char **argv)
nb_bbdevs, app_params.bbdev_id);
printf("Number of bbdevs detected: %d\n", nb_bbdevs);
/* Get the number of available ethdev devices */
nb_ports = rte_eth_dev_count();
if (nb_ports <= app_params.port_id)
if (!rte_eth_dev_is_valid_port(app_params.port_id))
rte_exit(EXIT_FAILURE,
"%u ports detected, cannot use port with ID %u!\n",
nb_ports, app_params.port_id);
"cannot use port with ID %u!\n",
app_params.port_id);
/* create the mbuf mempool for ethdev pkts */
ethdev_mbuf_mempool = rte_pktmbuf_pool_create("ethdev_mbuf_pool",

View File

@ -147,7 +147,7 @@ slave_port_init(uint16_t portid, struct rte_mempool *mbuf_pool)
struct rte_eth_txconf txq_conf;
struct rte_eth_conf local_port_conf = port_conf;
if (portid >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(portid))
rte_exit(EXIT_FAILURE, "Invalid port\n");
rte_eth_dev_info_get(portid, &dev_info);

View File

@ -116,7 +116,7 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
struct rte_eth_dev_info dev_info;
struct rte_eth_txconf txconf;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
rte_eth_dev_info_get(port, &dev_info);

View File

@ -285,7 +285,7 @@ port_init(uint8_t port, struct rte_mempool *mbuf_pool)
struct rte_eth_dev_info dev_info;
struct rte_eth_txconf txconf;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
rte_eth_dev_info_get(port, &dev_info);

View File

@ -200,7 +200,7 @@ port_init(uint8_t port, struct rte_mempool *mbuf_pool)
struct rte_eth_dev_info dev_info;
struct rte_eth_txconf txconf;
if (port >= rte_eth_dev_count())
if (rte_eth_dev_is_valid_port(port))
return -1;
rte_eth_dev_info_get(port, &dev_info);

View File

@ -67,7 +67,7 @@ kni_config_network_interface(uint16_t port_id, uint8_t if_up)
{
int ret = 0;
if (port_id >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port_id))
return -EINVAL;
ret = (if_up) ?
@ -82,7 +82,7 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu)
{
int ret;
if (port_id >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port_id))
return -EINVAL;
if (new_mtu > ETHER_MAX_LEN)

View File

@ -848,7 +848,7 @@ static int32_t
check_params(void)
{
uint8_t lcore;
uint16_t portid, nb_ports;
uint16_t portid;
uint16_t i;
int32_t socket_id;
@ -857,8 +857,6 @@ check_params(void)
return -1;
}
nb_ports = rte_eth_dev_count();
for (i = 0; i < nb_lcore_params; ++i) {
lcore = lcore_params[i].lcore_id;
if (!rte_lcore_is_enabled(lcore)) {
@ -877,7 +875,7 @@ check_params(void)
printf("port %u is not enabled in port mask\n", portid);
return -1;
}
if (portid >= nb_ports) {
if (!rte_eth_dev_is_valid_port(portid)) {
printf("port %u is not present on the board\n", portid);
return -1;
}

View File

@ -689,7 +689,7 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu)
struct rte_eth_dev_info dev_info;
struct rte_eth_rxconf rxq_conf;
if (port_id >= rte_eth_dev_count()) {
if (!rte_eth_dev_is_valid_port(port_id)) {
RTE_LOG(ERR, APP, "Invalid port id %d\n", port_id);
return -EINVAL;
}
@ -748,7 +748,7 @@ kni_config_network_interface(uint16_t port_id, uint8_t if_up)
{
int ret = 0;
if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) {
if (!rte_eth_dev_is_valid_port(port_id)) {
RTE_LOG(ERR, APP, "Invalid port id %d\n", port_id);
return -EINVAL;
}
@ -782,7 +782,7 @@ kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[])
{
int ret = 0;
if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) {
if (!rte_eth_dev_is_valid_port(port_id)) {
RTE_LOG(ERR, APP, "Invalid port id %d\n", port_id);
return -EINVAL;
}
@ -932,7 +932,7 @@ main(int argc, char** argv)
/* Check if the configured port ID is valid */
for (i = 0; i < RTE_MAX_ETHPORTS; i++)
if (kni_port_params_array[i] && i >= nb_sys_ports)
if (kni_port_params_array[i] && !rte_eth_dev_is_valid_port(i))
rte_exit(EXIT_FAILURE, "Configured invalid "
"port ID %u\n", i);

View File

@ -39,7 +39,7 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
uint16_t nb_rxd = RX_RING_SIZE;
uint16_t nb_txd = TX_RING_SIZE;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
/* Configure the Ethernet device. */

View File

@ -1452,7 +1452,7 @@ check_lcore_params(void)
}
static int
check_port_config(const unsigned nb_ports)
check_port_config(void)
{
unsigned portid;
uint16_t i;
@ -1464,7 +1464,7 @@ check_port_config(const unsigned nb_ports)
printf("port %u is not enabled in port mask\n", portid);
return -1;
}
if (portid >= nb_ports) {
if (!rte_eth_dev_is_valid_port(portid)) {
printf("port %u is not present on the board\n", portid);
return -1;
}
@ -1893,7 +1893,7 @@ main(int argc, char **argv)
nb_ports = rte_eth_dev_count();
if (check_port_config(nb_ports) < 0)
if (check_port_config() < 0)
rte_exit(EXIT_FAILURE, "check_port_config failed\n");
/* Add ACL rules and route entries, build trie */

View File

@ -1056,7 +1056,7 @@ check_lcore_params(void)
}
static int
check_port_config(const unsigned nb_ports)
check_port_config(void)
{
unsigned portid;
uint16_t i;
@ -1068,7 +1068,7 @@ check_port_config(const unsigned nb_ports)
portid);
return -1;
}
if (portid >= nb_ports) {
if (!rte_eth_dev_is_valid_port(portid)) {
printf("port %u is not present on the board\n",
portid);
return -1;
@ -1652,7 +1652,7 @@ main(int argc, char **argv)
nb_ports = rte_eth_dev_count();
if (check_port_config(nb_ports) < 0)
if (check_port_config() < 0)
rte_exit(EXIT_FAILURE, "check_port_config failed\n");
nb_lcores = rte_lcore_count();

View File

@ -575,7 +575,7 @@ check_lcore_params(void)
}
static int
check_port_config(const unsigned nb_ports)
check_port_config(void)
{
unsigned portid;
uint16_t i;
@ -586,7 +586,7 @@ check_port_config(const unsigned nb_ports)
printf("port %u is not enabled in port mask\n", portid);
return -1;
}
if (portid >= nb_ports) {
if (!rte_eth_dev_is_valid_port(portid)) {
printf("port %u is not present on the board\n", portid);
return -1;
}
@ -951,7 +951,7 @@ main(int argc, char **argv)
nb_ports = rte_eth_dev_count();
if (check_port_config(nb_ports) < 0)
if (check_port_config() < 0)
rte_exit(EXIT_FAILURE, "check_port_config failed\n");
nb_lcores = rte_lcore_count();

View File

@ -210,7 +210,7 @@ check_lcore_params(void)
}
static int
check_port_config(const unsigned nb_ports)
check_port_config(void)
{
uint16_t portid;
uint16_t i;
@ -221,7 +221,7 @@ check_port_config(const unsigned nb_ports)
printf("port %u is not enabled in port mask\n", portid);
return -1;
}
if (portid >= nb_ports) {
if (!rte_eth_dev_is_valid_port(portid)) {
printf("port %u is not present on the board\n", portid);
return -1;
}
@ -828,7 +828,7 @@ main(int argc, char **argv)
nb_ports = rte_eth_dev_count();
if (check_port_config(nb_ports) < 0)
if (check_port_config() < 0)
rte_exit(EXIT_FAILURE, "check_port_config failed\n");
nb_lcores = rte_lcore_count();

View File

@ -204,7 +204,7 @@ smp_port_init(uint16_t port, struct rte_mempool *mbuf_pool,
if (rte_eal_process_type() == RTE_PROC_SECONDARY)
return 0;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
printf("# Initialising port %u... ", port);

View File

@ -261,7 +261,6 @@ configure_eth_port(uint16_t port_id)
{
struct ether_addr addr;
const uint16_t rxRings = 1, txRings = 1;
const uint8_t nb_ports = rte_eth_dev_count();
int ret;
uint16_t q;
uint16_t nb_rxd = RX_DESC_PER_QUEUE;
@ -270,7 +269,7 @@ configure_eth_port(uint16_t port_id)
struct rte_eth_txconf txconf;
struct rte_eth_conf port_conf = port_conf_default;
if (port_id > nb_ports)
if (!rte_eth_dev_is_valid_port(port_id))
return -1;
rte_eth_dev_info_get(port_id, &dev_info);

View File

@ -2491,7 +2491,7 @@ check_lcore_params(void)
}
static int
check_port_config(const unsigned nb_ports)
check_port_config(void)
{
unsigned portid;
uint16_t i;
@ -2502,7 +2502,7 @@ check_port_config(const unsigned nb_ports)
printf("port %u is not enabled in port mask\n", portid);
return -1;
}
if (portid >= nb_ports) {
if (!rte_eth_dev_is_valid_port(portid)) {
printf("port %u is not present on the board\n", portid);
return -1;
}
@ -3516,7 +3516,7 @@ main(int argc, char **argv)
nb_ports = rte_eth_dev_count();
if (check_port_config(nb_ports) < 0)
if (check_port_config() < 0)
rte_exit(EXIT_FAILURE, "check_port_config failed\n");
nb_lcores = rte_lcore_count();

View File

@ -187,7 +187,7 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
uint16_t nb_rxd = RX_RING_SIZE;
uint16_t nb_txd = TX_RING_SIZE;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
rte_eth_dev_info_get(port, &dev_info);

View File

@ -80,7 +80,7 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
struct rte_eth_dev_info dev_info;
struct rte_eth_txconf txconf;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
rte_eth_dev_info_get(port, &dev_info);

View File

@ -42,7 +42,7 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
struct rte_eth_dev_info dev_info;
struct rte_eth_txconf txconf;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
rte_eth_dev_info_get(port, &dev_info);

View File

@ -515,11 +515,10 @@ check_ports_num(unsigned max_nb_ports)
}
for (portid = 0; portid < nb_ports; portid++) {
if (ports[portid] >= max_nb_ports) {
if (!rte_eth_dev_is_valid_port(ports[portid])) {
RTE_LOG(INFO, VHOST_PORT,
"\nSpecified port ID(%u) exceeds max "
" system port ID(%u)\n",
ports[portid], (max_nb_ports - 1));
"\nSpecified port ID(%u) is not valid\n",
ports[portid]);
ports[portid] = INVALID_PORT_ID;
valid_nb_ports--;
}

View File

@ -133,7 +133,7 @@ vxlan_port_init(uint16_t port, struct rte_mempool *mbuf_pool)
txconf = &dev_info.default_txconf;
txconf->txq_flags = ETH_TXQ_FLAGS_IGNORE;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
rx_rings = nb_devices;

View File

@ -294,7 +294,8 @@ port_init(uint16_t port)
printf("pf queue num: %u, configured vmdq pool num: %u, each vmdq pool has %u queues\n",
num_pf_queues, num_devices, queues_per_pool);
if (port >= rte_eth_dev_count()) return -1;
if (!rte_eth_dev_is_valid_port(port))
return -1;
rx_rings = (uint16_t)dev_info.max_rx_queues;
if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
@ -667,9 +668,10 @@ static unsigned check_ports_num(unsigned nb_ports)
}
for (portid = 0; portid < num_ports; portid ++) {
if (ports[portid] >= nb_ports) {
RTE_LOG(INFO, VHOST_PORT, "\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])) {
RTE_LOG(INFO, VHOST_PORT,
"\nSpecified port ID(%u) is not valid\n",
ports[portid]);
ports[portid] = INVALID_PORT_ID;
valid_num_ports--;
}

View File

@ -61,7 +61,7 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
struct rte_eth_dev_info dev_info;
struct rte_eth_txconf txq_conf;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
rte_eth_dev_info_get(port, &dev_info);

View File

@ -201,7 +201,7 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
num_pf_queues, num_pools, queues_per_pool);
printf("vmdq queue base: %d pool base %d\n",
vmdq_queue_base, vmdq_pool_base);
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
/*
@ -539,9 +539,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--;
}

View File

@ -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--;
}

View File

@ -510,7 +510,7 @@ kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[])
{
int ret = 0;
if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) {
if (!rte_eth_dev_is_valid_port(port_id)) {
RTE_LOG(ERR, KNI, "Invalid port id %d\n", port_id);
return -EINVAL;
}
@ -530,7 +530,7 @@ kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[])
static int
kni_config_promiscusity(uint16_t port_id, uint8_t to_on)
{
if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) {
if (!rte_eth_dev_is_valid_port(port_id)) {
RTE_LOG(ERR, KNI, "Invalid port id %d\n", port_id);
return -EINVAL;
}

View File

@ -51,7 +51,7 @@ port_init(uint8_t port, struct rte_mempool *mp)
uint16_t q;
struct rte_eth_dev_info dev_info;
if (port >= rte_eth_dev_count())
if (!rte_eth_dev_is_valid_port(port))
return -1;
retval = rte_eth_dev_configure(port, 0, 0, &port_conf);