fix ethdev port id validation
[dpdk.git] / examples / kni / main.c
index d944bae..901480a 100644 (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);