From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f47.google.com (mail-pa0-f47.google.com [209.85.220.47]) by dpdk.org (Postfix) with ESMTP id BE358C506 for ; Tue, 14 Apr 2015 00:11:09 +0200 (CEST) Received: by pacyx8 with SMTP id yx8so115882996pac.1 for ; Mon, 13 Apr 2015 15:11:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GJsgTyt18IOP1wqCzw5YfMg1FJac/MOpNr1lRznWpQQ=; b=Asx0/+VMobwZd9T9jpKOHK6umMFUaIaA/ourDp7GAQmtCGZjKLBPWI5nU0BYdhMgAp q6q5a5GWw7wM1kBv/PapbcT4gF+Ei0wnEJtWUEegcFErFOp2PfBM5cULjVn2Or1qKWW5 +3XLMSWElL5VdFWKuBvLTeGZPO4UKysDXE/PP+vVMFyPN+eDF9d/RHWSQUP6/X5yJWil Bt0HGSDEadyJ9GrgZBlQIdtBs9JLlYbC6lXYkDKl0wzMhrsuf5FkoFcq3pQqfCIXPmK+ AMSedoUlRy5Q87H5p+bCf2KbG9W5gqkw1BeJz8+qhBG8itv6Nj1bhhH7h0rIFsmb15hu 2Kow== X-Gm-Message-State: ALoCoQkKmmrVQHFKIg3Xhw2X8NM+eJ2VGMIhrkvOfMrr5WIO6YcXnc6GyYH9i7MtqdIC8kKLxEIz X-Received: by 10.68.69.47 with SMTP id b15mr5869216pbu.117.1428963069175; Mon, 13 Apr 2015 15:11:09 -0700 (PDT) Received: from urahara.home.lan (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by mx.google.com with ESMTPSA id dk5sm8255847pdb.88.2015.04.13.15.11.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Apr 2015 15:11:08 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Date: Mon, 13 Apr 2015 15:11:11 -0700 Message-Id: <1428963071-4226-3-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1428963071-4226-1-git-send-email-stephen@networkplumber.org> References: <1428963071-4226-1-git-send-email-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH 2/2] pci: rearrange logic from compare loop X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Apr 2015 22:11:10 -0000 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 --- 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 c98a778..d96b1c4 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -337,6 +337,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; @@ -346,37 +352,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.1.4