DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: "Qiu, Michael" <michael.qiu@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH 2/2] pci: rearrange logic from compare loop
Date: Tue, 14 Apr 2015 10:28:35 -0700	[thread overview]
Message-ID: <CAOaVG14THBg=7fGGs3F-6U4Ad_E9B8Sy82Te3dWWP-pJ+BCTrA@mail.gmail.com> (raw)
In-Reply-To: <533710CFB86FA344BFBF2D6802E602860465255C@SHSMSX101.ccr.corp.intel.com>

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 <michael.qiu@intel.com> 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 <stephen@networkplumber.org>
> >
> > ---
> >  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);
> >       }
>
>

  reply	other threads:[~2015-04-14 17:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 22:11 [dpdk-dev] [PATCH 0/2] eal-pci: cleanups Stephen Hemminger
2015-04-13 22:11 ` [dpdk-dev] [PATCH 1/2] pci: cleanup whitespace Stephen Hemminger
2015-04-14  9:29   ` Qiu, Michael
2015-04-13 22:11 ` [dpdk-dev] [PATCH 2/2] pci: rearrange logic from compare loop Stephen Hemminger
2015-04-14  9:30   ` Qiu, Michael
2015-04-14 17:28     ` Stephen Hemminger [this message]
2015-05-19 10:12   ` Bruce Richardson
2015-08-03 16:03 ` [dpdk-dev] [PATCH 0/2] eal-pci: cleanups Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOaVG14THBg=7fGGs3F-6U4Ad_E9B8Sy82Te3dWWP-pJ+BCTrA@mail.gmail.com' \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=michael.qiu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).