From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 8A769C31A for ; Tue, 19 May 2015 12:12:59 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP; 19 May 2015 03:12:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,457,1427785200"; d="scan'208";a="731674054" Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.221.63]) by orsmga002.jf.intel.com with SMTP; 19 May 2015 03:12:54 -0700 Received: by (sSMTP sendmail emulation); Tue, 19 May 2015 11:12:52 +0025 Date: Tue, 19 May 2015 11:12:52 +0100 From: Bruce Richardson To: Stephen Hemminger Message-ID: <20150519101252.GC11036@bricha3-MOBL3> References: <1428963071-4226-1-git-send-email-stephen@networkplumber.org> <1428963071-4226-3-git-send-email-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1428963071-4226-3-git-send-email-stephen@networkplumber.org> Organization: Intel Shannon Ltd. User-Agent: Mutt/1.5.23 (2014-03-12) Cc: dev@dpdk.org Subject: Re: [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: Tue, 19 May 2015 10:13:00 -0000 On Mon, Apr 13, 2015 at 03:11:11PM -0700, Stephen Hemminger wrote: > 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 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 >