[dpdk-dev] [PATCH v5 06/10] app/test: use linked list to store PCI drivers

Jan Viktorin viktorin at rehivetech.com
Mon Jun 13 17:07:41 CEST 2016


The test unregisters all drivers before start. The drivers were stored
into a fixed-sized array. This is inflexible. This patch change this to
utilize a linked list for the same purpose.

Signed-off-by: Jan Viktorin <viktorin at rehivetech.com>
---
v3:
* fixed commit message
* used "backup" to describe the real_pci_driver_list
---
 app/test/test_pci.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/app/test/test_pci.c b/app/test/test_pci.c
index 0ed357e..8b7c8bb 100644
--- a/app/test/test_pci.c
+++ b/app/test/test_pci.c
@@ -144,21 +144,24 @@ static void free_devargs_list(void)
 	}
 }
 
+/* backup real drivers (not used for testing) */
+struct pci_driver_list real_pci_driver_list =
+	TAILQ_HEAD_INITIALIZER(real_pci_driver_list);
+
 int
 test_pci(void)
 {
 	struct rte_devargs_list save_devargs_list;
 	struct rte_pci_driver *dr = NULL;
-	struct rte_pci_driver *save_pci_driver_list[NUM_MAX_DRIVERS];
-	unsigned i, num_drivers = 0;
 
 	printf("Dump all devices\n");
 	rte_eal_pci_dump(stdout);
 
 	/* Unregister all previous drivers */
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
+	while (!TAILQ_EMPTY(&pci_driver_list)) {
+		dr = TAILQ_FIRST(&pci_driver_list);
 		rte_eal_pci_unregister(dr);
-		save_pci_driver_list[num_drivers++] = dr;
+		TAILQ_INSERT_TAIL(&real_pci_driver_list, dr, next);
 	}
 
 	rte_eal_pci_register(&my_driver);
@@ -197,8 +200,11 @@ test_pci(void)
 	rte_eal_pci_unregister(&my_driver2);
 
 	/* Restore original driver list */
-	for (i = 0; i < num_drivers; i++)
-		rte_eal_pci_register(save_pci_driver_list[i]);
+	while (!TAILQ_EMPTY(&real_pci_driver_list)) {
+		dr = TAILQ_FIRST(&real_pci_driver_list);
+		TAILQ_REMOVE(&real_pci_driver_list, dr, next);
+		rte_eal_pci_register(dr);
+	}
 
 	return 0;
 }
-- 
2.8.0



More information about the dev mailing list