[dpdk-dev,13/25] eal/pci: Prevent double registration for devargs_list
Commit Message
The patch fixes rte_eal_devargs_add() not to register same device twice.
Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
lib/librte_eal/common/eal_common_devargs.c | 32 ++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
@@ -44,6 +44,32 @@
struct rte_devargs_list devargs_list =
TAILQ_HEAD_INITIALIZER(devargs_list);
+
+/* find a entry specified by pci address or device name */
+static struct rte_devargs *
+rte_eal_devargs_find(enum rte_devtype devtype, void *args)
+{
+ struct rte_devargs *devargs;
+
+ TAILQ_FOREACH(devargs, &devargs_list, next) {
+ switch (devtype) {
+ case RTE_DEVTYPE_WHITELISTED_PCI:
+ case RTE_DEVTYPE_BLACKLISTED_PCI:
+ if (eal_compare_pci_addr(&devargs->pci.addr, args) == 0)
+ goto found;
+ break;
+ case RTE_DEVTYPE_VIRTUAL:
+ if (memcmp(&devargs->virtual.drv_name, args,
+ strlen((char *)args)) == 0)
+ goto found;
+ break;
+ }
+ }
+ return NULL;
+found:
+ return devargs;
+}
+
/* store a whitelist parameter for later parsing */
int
rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
@@ -101,6 +127,12 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
break;
}
+ /* make sure there is no same entry */
+ if (rte_eal_devargs_find(devtype, &devargs->pci.addr)) {
+ RTE_LOG(ERR, EAL, "device already registered: <%s>\n", buf);
+ return -1;
+ }
+
TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
return 0;
}