ethdev: fix port lookup if none
authorAnatoly Burakov <anatoly.burakov@intel.com>
Sat, 19 Nov 2016 13:10:11 +0000 (13:10 +0000)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 7 Dec 2016 18:04:41 +0000 (19:04 +0100)
Aside from avoiding doing useless work, this also fixes a segfault
when calling rte_eth_dev_get_port_by_name() whenever no devices
were found yet, and therefore rte_eth_dev_data wasn't yet allocated.

Fixes: 9c5b8d8b9feb ("ethdev: clean port id retrieval when attaching")

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>
lib/librte_ether/rte_ethdev.c

index 4209ad0..1e0f206 100644 (file)
@@ -376,6 +376,9 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
                return -EINVAL;
        }
 
+       if (!nb_ports)
+               return -ENODEV;
+
        *port_id = RTE_MAX_ETHPORTS;
 
        for (i = 0; i < RTE_MAX_ETHPORTS; i++) {