From c07f42ec0bfbc52f47c178a5adfc8937689095e3 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 13 Apr 2015 15:11:11 -0700 Subject: [PATCH] pci: cleanup scan loop Do some cleanup of pci scan loop. * check errors first * don't initialize variables where not necessary * cuddle else (follow existing style) * chop off conditional after return Signed-off-by: Stephen Hemminger Acked-by: Bruce Richardson --- lib/librte_eal/linuxapp/eal/eal_pci.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 0e62f65eea..01e2855d3e 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -346,6 +346,12 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, /* parse driver */ snprintf(filename, sizeof(filename), "%s/driver", dirname); ret = pci_get_kernel_driver_by_path(filename, driver); + if (ret < 0) { + RTE_LOG(ERR, EAL, "Fail to get kernel driver\n"); + free(dev); + return -1; + } + if (!ret) { if (!strcmp(driver, "vfio-pci")) dev->kdrv = RTE_KDRV_VFIO; @@ -355,37 +361,31 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, dev->kdrv = RTE_KDRV_UIO_GENERIC; else dev->kdrv = RTE_KDRV_UNKNOWN; - } else if (ret < 0) { - RTE_LOG(ERR, EAL, "Fail to get kernel driver\n"); - free(dev); - return -1; } else dev->kdrv = RTE_KDRV_UNKNOWN; /* device is valid, add in list (sorted) */ if (TAILQ_EMPTY(&pci_device_list)) { TAILQ_INSERT_TAIL(&pci_device_list, dev, next); - } - else { - struct rte_pci_device *dev2 = NULL; + } else { + struct rte_pci_device *dev2; int ret; TAILQ_FOREACH(dev2, &pci_device_list, next) { ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr); if (ret > 0) continue; - else if (ret < 0) { + + if (ret < 0) { TAILQ_INSERT_BEFORE(dev2, dev, next); - return 0; } else { /* already registered */ dev2->kdrv = dev->kdrv; dev2->max_vfs = dev->max_vfs; - memmove(dev2->mem_resource, - dev->mem_resource, + memmove(dev2->mem_resource, dev->mem_resource, sizeof(dev->mem_resource)); free(dev); - return 0; } + return 0; } TAILQ_INSERT_TAIL(&pci_device_list, dev, next); } -- 2.20.1