All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Alexander Duyck <aduyck@mirantis.com>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/5] iov: Variable and loop cleanup for sriov_disable and sriov_enable
Date: Thu, 29 Oct 2015 16:43:49 -0500	[thread overview]
Message-ID: <20151029214349.GC921@localhost> (raw)
In-Reply-To: <20151027205233.14626.98836.stgit@localhost.localdomain>

Hi Alex,

On Tue, Oct 27, 2015 at 01:52:33PM -0700, Alexander Duyck wrote:
> This patch is just a minor cleanup to go through and group all of the
> variables into one declaration instead of a long string of single
> declarations for each int.  It also changes the direction for a couple
> loops as we are able to loop with less code this way as testing against 0
> can be done as a part of the decrement operation.
> 
> Signed-off-by: Alexander Duyck <aduyck@mirantis.com>
> ---
>  drivers/pci/iov.c |   13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index cecc242c1af0..c0fc88fa7c4d 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -241,15 +241,11 @@ int __weak pcibios_sriov_disable(struct pci_dev *pdev)
>  
>  static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
>  {
> -	int rc;
> -	int i;
> -	int nres;
>  	u16 offset, stride, initial;
>  	struct resource *res;
>  	struct pci_dev *pdev;
>  	struct pci_sriov *iov = dev->sriov;
> -	int bars = 0;
> -	int bus;
> +	int rc, i, nres, bars, bus;

I don't have a strong opinion on combining the declarations to one line,
and I would apply it if you wanted to do the same for the whole file
at once, in a patch by itself.

>  	if (!nr_virtfn)
>  		return 0;
> @@ -271,8 +267,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
>  	if (!offset || (nr_virtfn > 1 && !stride))
>  		return -EIO;
>  
> -	nres = 0;
> -	for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
> +	for (nres = 0, bars = 0, i = PCI_SRIOV_NUM_BARS; i--;) {

But I don't agree that this is easier to read.  I suppose it could be
a tiny bit more efficient, but I think the benefit to the reader of
the usual "for (i = 0; i < limit; i++)" loop is larger.

>  		bars |= (1 << (i + PCI_IOV_RESOURCES));
>  		res = &dev->resource[i + PCI_IOV_RESOURCES];
>  		if (res->parent)
> @@ -366,13 +361,13 @@ err_pcibios:
>  
>  static void sriov_disable(struct pci_dev *dev)
>  {
> -	int i;
>  	struct pci_sriov *iov = dev->sriov;
> +	int i = iov->num_VFs;
>  
>  	if (!iov->num_VFs)
>  		return;
>  
> -	for (i = 0; i < iov->num_VFs; i++)
> +	while (i--)
>  		virtfn_remove(dev, i, 0);

I do like the change to remove devices in the reverse order as we
added them.  But I'm really partial to the way a "for" loop keeps all
the loop control in one spot.  So I would apply a patch that made it
look like this:

  for (i = iov->num_VFs - 1; i >= 0; i--)
    virtfn_remove(dev, i, 0);

>  	pcibios_sriov_disable(dev);
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2015-10-29 21:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-27 20:52 [PATCH 0/5] Various of SR-IOV fixes and cleanup Alexander Duyck
2015-10-27 20:52 ` [PATCH 1/5] iov: Update virtfn_max_buses to validate offset and stride Alexander Duyck
2015-10-28 16:32   ` Bjorn Helgaas
2015-10-28 17:57     ` Alexander Duyck
2015-10-28 18:43     ` Bjorn Helgaas
2015-10-28 21:46       ` Alexander Duyck
2015-10-29 19:50         ` Bjorn Helgaas
2015-10-27 20:52 ` [PATCH 2/5] iov: Reset resources to 0 if totalVFs increases after enabling ARI Alexander Duyck
2015-10-28 16:37   ` Bjorn Helgaas
2015-10-28 18:32     ` Alexander Duyck
2015-10-28 19:52       ` Bjorn Helgaas
2015-10-28 21:37         ` Alexander Duyck
2015-10-27 20:52 ` [PATCH 3/5] iov: Fix sriov_enable exception handling path Alexander Duyck
2015-10-29 16:32   ` Bjorn Helgaas
2015-10-29 16:54     ` Alex Duyck
2015-10-29 20:41       ` Bjorn Helgaas
2015-10-27 20:52 ` [PATCH 4/5] iov: Variable and loop cleanup for sriov_disable and sriov_enable Alexander Duyck
2015-10-29 21:43   ` Bjorn Helgaas [this message]
2015-10-29 23:19     ` Alexander Duyck
2015-10-27 20:52 ` [PATCH 5/5] iov: Update sriov_enable to correctly handle offset and stride Alexander Duyck

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=20151029214349.GC921@localhost \
    --to=helgaas@kernel.org \
    --cc=aduyck@mirantis.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.