ethdev: add iterator to match devargs input
[dpdk.git] / lib / librte_ethdev / ethdev_private.c
index 768c8b2..acc787d 100644 (file)
@@ -5,6 +5,14 @@
 #include "rte_ethdev.h"
 #include "ethdev_private.h"
 
+uint16_t
+eth_dev_to_id(const struct rte_eth_dev *dev)
+{
+       if (dev == NULL)
+               return RTE_MAX_ETHPORTS;
+       return dev - rte_eth_devices;
+}
+
 struct rte_eth_dev *
 eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,
                const void *data)
@@ -18,7 +26,7 @@ eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,
             start > &rte_eth_devices[RTE_MAX_ETHPORTS]))
                return NULL;
        if (start != NULL)
-               idx = start - &rte_eth_devices[0] + 1;
+               idx = eth_dev_to_id(start) + 1;
        else
                idx = 0;
        for (; idx < RTE_MAX_ETHPORTS; idx++) {