netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Hutchings <bhutchings@solarflare.com>
To: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Cc: netdev@vger.kernel.org, gospo@redhat.com,
	Mitch Williams <mitch.a.williams@intel.com>
Subject: Re: [RFC PATCH v2 2/6] net: Add netif_num_vf function
Date: Fri, 18 Dec 2009 17:37:04 +0000	[thread overview]
Message-ID: <1261157824.2769.2.camel@achroite.uk.solarflarecom.com> (raw)
In-Reply-To: <20091218013410.4510.40263.stgit@localhost.localdomain>

On Thu, 2009-12-17 at 17:34 -0800, Jeff Kirsher wrote:
> From: Williams, Mitch A <mitch.a.williams@intel.com>
> 
> Add a convenience function to determine how many VF devices are associated
> with a given PF network interface. If the device is not an SR-IOV physical
> function device, the function returns 0.
[...]
> +/**
> + *	netif_num_vf - return number of SR-IOV VFs
> + *	@dev: network device
> + *
> + *	Return the number of SR-IOV virtual function devices that are
> + *	associated with this physical function device. Returns 0 if
> + *	device is not a PF device, or if SR-IOV not enabled.
> + */
> +static inline int netif_num_vf(const struct net_device *dev)
> +{
> +	struct pci_dev *pdev;
> +	int retval = 0;
> +
> +	if (!dev)
> +		goto out;

Why should this function allow dev == NULL?

> +	if (!dev->dev.parent)
> +		goto out;
> +
> +	if (dev->dev.parent->bus == &pci_bus_type) {
> +		pdev = to_pci_dev(dev->dev.parent);
> +		retval = pci_num_vf(pdev);
> +	}
> +out:
> +	return retval;
[...]

It would be much clearer to write:

	struct pci_dev *pdev;

	if (dev && dev->dev.parent &&
	    dev->dev.parent->bus == &pci_bus_type) {
		pdev = to_pci_dev(dev->dev.parent);
		return pci_num_vf(pdev);
	} else {
		return 0;
	}

Ben.

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


  reply	other threads:[~2009-12-18 17:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-18  1:33 [RFC PATCH v2 1/6] pci: Add pci_num_vf function Jeff Kirsher
2009-12-18  1:34 ` [RFC PATCH v2 2/6] net: Add netif_num_vf function Jeff Kirsher
2009-12-18 17:37   ` Ben Hutchings [this message]
2009-12-19  4:05   ` David Miller
2009-12-21 18:34     ` Williams, Mitch A
2009-12-18  1:34 ` [RFC PATCH v2 3/6] if_link: Add SR-IOV configuration methods Jeff Kirsher
2009-12-18  1:34 ` [RFC PATCH v2 4/6] net: Add netdev ops for SR-IOV configuration Jeff Kirsher
2009-12-18 18:19   ` Ben Hutchings
2009-12-18  1:35 ` [RFC PATCH v2 5/6] rtnetlink: Add VF config code to rtnetlink Jeff Kirsher
2009-12-18  1:35 ` [RFC PATCH v2 6/6] igb: add support for VF configuration tools Jeff Kirsher

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=1261157824.2769.2.camel@achroite.uk.solarflarecom.com \
    --to=bhutchings@solarflare.com \
    --cc=gospo@redhat.com \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=mitch.a.williams@intel.com \
    --cc=netdev@vger.kernel.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).