[dpdk-dev] [PATCH v2 06/15] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp

Tetsuya Mukawa mukawa at igel.co.jp
Thu Mar 12 11:17:45 CET 2015


This patch changes code that maps pci resources in bsdapp.
Linuxapp has almost same code. To consolidate both, fix implementation
of bsdapp to work same as linuxapp.

Signed-off-by: Tetsuya Mukawa <mukawa at igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 7fcb15d..bd0f8cd 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -196,7 +196,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
 static int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
-	int i, j;
+	int i, map_idx;
 	char devname[PATH_MAX]; /* contains the /dev/uioX */
 	void *mapaddr;
 	uint64_t phaddr;
@@ -250,9 +250,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 	pagesz = sysconf(_SC_PAGESIZE);
 
 	maps = uio_res->maps;
-	for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
 
-		j = uio_res->nb_maps;
 		/* skip empty BAR */
 		phaddr = dev->mem_resource[i].phys_addr;
 		if (phaddr == 0)
@@ -260,22 +259,23 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
 		/* if matching map is found, then use it */
 		offset = i * pagesz;
-		maps[j].offset = offset;
-		maps[j].phaddr = dev->mem_resource[i].phys_addr;
-		maps[j].size = dev->mem_resource[i].len;
-		if (maps[j].addr != NULL ||
-		    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
-		    ) == NULL) {
+		maps[map_idx].offset = offset;
+		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
+		maps[map_idx].size = dev->mem_resource[i].len;
+		mapaddr = pci_map_resource(NULL, devname, (off_t)offset,
+					(size_t)maps[map_idx].size);
+		if ((maps[map_idx].addr != NULL) || (mapaddr == NULL)) {
 			rte_free(uio_res);
 			return -1;
 		}
 
-		maps[j].addr = mapaddr;
-		uio_res->nb_maps++;
+		maps[map_idx].addr = mapaddr;
+		map_idx++;
 		dev->mem_resource[i].addr = mapaddr;
 	}
 
+	uio_res->nb_maps = map_idx;
+
 	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
 
 	return 0;
-- 
1.9.1



More information about the dev mailing list