From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 14BF55A40 for ; Tue, 14 Apr 2015 11:30:36 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 14 Apr 2015 02:30:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,575,1422950400"; d="scan'208";a="480646011" Received: from pgsmsx103.gar.corp.intel.com ([10.221.44.82]) by FMSMGA003.fm.intel.com with ESMTP; 14 Apr 2015 02:30:35 -0700 Received: from kmsmsx154.gar.corp.intel.com (172.21.73.14) by PGSMSX103.gar.corp.intel.com (10.221.44.82) with Microsoft SMTP Server (TLS) id 14.3.224.2; Tue, 14 Apr 2015 17:30:34 +0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by KMSMSX154.gar.corp.intel.com (172.21.73.14) with Microsoft SMTP Server (TLS) id 14.3.224.2; Tue, 14 Apr 2015 17:30:33 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.24]) by shsmsx102.ccr.corp.intel.com ([169.254.2.223]) with mapi id 14.03.0224.002; Tue, 14 Apr 2015 17:30:32 +0800 From: "Qiu, Michael" To: Stephen Hemminger , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH 2/2] pci: rearrange logic from compare loop Thread-Index: AQHQdjbSwxo/0KTwkUK7ctdg89KQ5A== Date: Tue, 14 Apr 2015 09:30:32 +0000 Message-ID: <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> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 09:30:37 -0000 On 4/14/2015 6:11 AM, Stephen Hemminger wrote:=0A= > Do some cleanup of pci scan loop.=0A= > * check errors first=0A= > * don't initialize variables where not necessary=0A= =0A= Why? It should be better to initialize variables when define it.=0A= =0A= Thanks,=0A= Michael=0A= > * cuddle else (follow existing style)=0A= > * chop off conditional after return=0A= >=0A= > Signed-off-by: Stephen Hemminger =0A= >=0A= > ---=0A= > lib/librte_eal/linuxapp/eal/eal_pci.c | 24 ++++++++++++------------=0A= > 1 file changed, 12 insertions(+), 12 deletions(-)=0A= >=0A= > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linux= app/eal/eal_pci.c=0A= > index c98a778..d96b1c4 100644=0A= > --- a/lib/librte_eal/linuxapp/eal/eal_pci.c=0A= > +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c=0A= > @@ -337,6 +337,12 @@ pci_scan_one(const char *dirname, uint16_t domain, u= int8_t bus,=0A= > /* parse driver */=0A= > snprintf(filename, sizeof(filename), "%s/driver", dirname);=0A= > ret =3D pci_get_kernel_driver_by_path(filename, driver);=0A= > + if (ret < 0) {=0A= > + RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");=0A= > + free(dev);=0A= > + return -1;=0A= > + }=0A= > +=0A= > if (!ret) {=0A= > if (!strcmp(driver, "vfio-pci"))=0A= > dev->kdrv =3D RTE_KDRV_VFIO;=0A= > @@ -346,37 +352,31 @@ pci_scan_one(const char *dirname, uint16_t domain, = uint8_t bus,=0A= > dev->kdrv =3D RTE_KDRV_UIO_GENERIC;=0A= > else=0A= > dev->kdrv =3D RTE_KDRV_UNKNOWN;=0A= > - } else if (ret < 0) {=0A= > - RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");=0A= > - free(dev);=0A= > - return -1;=0A= > } else=0A= > dev->kdrv =3D RTE_KDRV_UNKNOWN;=0A= > =0A= > /* device is valid, add in list (sorted) */=0A= > if (TAILQ_EMPTY(&pci_device_list)) {=0A= > TAILQ_INSERT_TAIL(&pci_device_list, dev, next);=0A= > - }=0A= > - else {=0A= > - struct rte_pci_device *dev2 =3D NULL;=0A= > + } else {=0A= > + struct rte_pci_device *dev2;=0A= > int ret;=0A= > =0A= > TAILQ_FOREACH(dev2, &pci_device_list, next) {=0A= > ret =3D rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);=0A= > if (ret > 0)=0A= > continue;=0A= > - else if (ret < 0) {=0A= > +=0A= > + if (ret < 0) {=0A= > TAILQ_INSERT_BEFORE(dev2, dev, next);=0A= > - return 0;=0A= > } else { /* already registered */=0A= > dev2->kdrv =3D dev->kdrv;=0A= > dev2->max_vfs =3D dev->max_vfs;=0A= > - memmove(dev2->mem_resource,=0A= > - dev->mem_resource,=0A= > + memmove(dev2->mem_resource, dev->mem_resource,=0A= > sizeof(dev->mem_resource));=0A= > free(dev);=0A= > - return 0;=0A= > }=0A= > + return 0;=0A= > }=0A= > TAILQ_INSERT_TAIL(&pci_device_list, dev, next);=0A= > }=0A= =0A=