DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Qiu, Michael" <michael.qiu@intel.com>
To: Stephen Hemminger <stephen@networkplumber.org>,
	"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH 2/2] pci: rearrange logic from compare loop
Date: Tue, 14 Apr 2015 09:30:32 +0000	[thread overview]
Message-ID: <533710CFB86FA344BFBF2D6802E602860465255C@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <1428963071-4226-3-git-send-email-stephen@networkplumber.org>

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  9:30 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 [this message]
2015-04-14 17:28     ` Stephen Hemminger
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=533710CFB86FA344BFBF2D6802E602860465255C@SHSMSX101.ccr.corp.intel.com \
    --to=michael.qiu@intel.com \
    --cc=dev@dpdk.org \
    --cc=stephen@networkplumber.org \
    /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).