From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ie0-f172.google.com (mail-ie0-f172.google.com [209.85.223.172]) by dpdk.org (Postfix) with ESMTP id EDF10C2DC for ; Tue, 14 Apr 2015 19:28:35 +0200 (CEST) Received: by iecrt8 with SMTP id rt8so8276113iec.0 for ; Tue, 14 Apr 2015 10:28:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Ce5m3yzSqR2A4XJyALygYpVBQjzzxXN3hmqw8dkTSGA=; b=e/FEQSk6wLl8MFTWKGnsJegPIaBkpAG+w1frqwbBIspJ9EuJd+gfxbLo0GJy6q2U64 7KokJmRzHLdTrQawBXwlpW6gOEj2BdhriTOkfJXpKZd6OX7ggqMKFdIhZX5s6w7tQ62l DCqWA7xFXW/xNYVb0+xJTnS5kkt8ncKU6UjttLqYyfdjj+7sq9o+1Apc2mCImuqwSIyO 7Fxmk5zaEPFlADBSS3Ocs9ZgN5Kti5oN80t6g65mjTGYfZz/VhMRItVpQT0OPqR6BK9S q53wowBuEWooSy8Vg+DnZWcSn/rT7rLapS3YAexTYvaf3dL2lv9MgpToVfXOIhzCP1IZ 5BGw== X-Gm-Message-State: ALoCoQlCgjWrFlnNnDXqXmp+7iXPL0POdwp4jC8Ax+kXRU9oK+A1zjyX8VaQu0TqcV+ObkGXvNJp MIME-Version: 1.0 X-Received: by 10.50.8.6 with SMTP id n6mr25726207iga.12.1429032515234; Tue, 14 Apr 2015 10:28:35 -0700 (PDT) Received: by 10.64.58.129 with HTTP; Tue, 14 Apr 2015 10:28:35 -0700 (PDT) In-Reply-To: <533710CFB86FA344BFBF2D6802E602860465255C@SHSMSX101.ccr.corp.intel.com> References: <1428963071-4226-1-git-send-email-stephen@networkplumber.org> <1428963071-4226-3-git-send-email-stephen@networkplumber.org> <533710CFB86FA344BFBF2D6802E602860465255C@SHSMSX101.ccr.corp.intel.com> Date: Tue, 14 Apr 2015 10:28:35 -0700 Message-ID: From: Stephen Hemminger To: "Qiu, Michael" Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 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, 14 Apr 2015 17:28:36 -0000 There is no need to initialize a variable that is only used as a loop variable. On Tue, Apr 14, 2015 at 2:30 AM, Qiu, Michael wrote: > On 4/14/2015 6:11 AM, Stephen Hemminger wrote: > > Do some cleanup of pci scan loop. > > * check errors first > > * don't initialize variables where not necessary > > Why? It should be better to initialize variables when define it. > > Thanks, > Michael > > * 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); > > } > >