All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bhelgaas@google.com>
To: Wei Yang <weiyang@linux.vnet.ibm.com>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>
Subject: Re: [PATCH V2 4/4] PCI: consolidate return value check for pci_find_(ext_)capability
Date: Tue, 14 Jul 2015 21:11:54 -0500	[thread overview]
Message-ID: <CAErSpo4o4z+OHdoLjhzEY4QwTN4dZkbjw5ot4sdUmOx8bFxyjA@mail.gmail.com> (raw)
In-Reply-To: <20150715020206.GC6525@richard>

On Tue, Jul 14, 2015 at 9:02 PM, Wei Yang <weiyang@linux.vnet.ibm.com> wrote:
> On Tue, Jul 14, 2015 at 05:00:21PM -0500, Bjorn Helgaas wrote:
>>On Tue, Jun 30, 2015 at 09:16:44AM +0800, Wei Yang wrote:
>>> The return value of the pci_find_(ext_)capability is the position of this
>>> Cap.  After previous two patches clean up, the position returned is an
>>> unsigned value. Only 0 indicates the Cap is not presented.
>>>
>>> This patch consolidates the form of check from (pos <= 0)to (!pos).
>>>
>>> Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
>>
>>Applied to pci/misc with changelog as below.
>>
>>It seems pretty clear to me that pci_find_capability() returns either 0 or
>>a u8 value.  pci_find_ext_capability() does return an int.  It looks to me
>>like it can never be negative, but if you wanted it to be even more clear,
>>you could easily change just pci_find_next_ext_capability() to use a u16
>>for "pos".  That would be very simple and wouldn't change any interfaces.
>
> pci_find_capability() will return either 0 or a u8 value, while in the code
> the return value is an "int" type. So for the first sight, it may not that
> immediate. The same as pci_find_ext_capability().
>
> This is the reason for patch 2/3. The purpose is to make the return type
> reflect the value it will return.
>
> Patch 3 does exactly what you said, use a u16 for "pos" in
> pci_find_next_ext_capability().

Yes.  Patch 3 contains this hunk:

@@ -272,11 +272,11 @@ EXPORT_SYMBOL(pci_bus_find_capability);
  * not support it.  Some capabilities can occur several times, e.g., the
  * vendor-specific capability, and this provides a way to find them all.
  */
-int pci_find_next_ext_capability(struct pci_dev *dev, int start, int cap)
+u16 pci_find_next_ext_capability(struct pci_dev *dev, int start, u16 cap)
 {
        u32 header;
        int ttl;
-       int pos = PCI_CFG_SPACE_SIZE;
+       u16 pos = PCI_CFG_SPACE_SIZE;

        /* minimum 8 bytes per capability */
        ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8;

I think the second piece (changing "pos" from int to u16) is enough to
make it easy to analyze, and it only affects this function, so that
seems obviously fine.

The first piece (changing the return type) changes the signature of an
exported interface.  That is more work, e.g., it's more of a hassle
for distros to backport if they want to preserve interfaces, so it's
not quite as obvious that it's worthwhile.

Bjorn

  reply	other threads:[~2015-07-15  2:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-30  1:16 [PATCH V2 0/4] PCI: code clean up on pci configuration space Wei Yang
2015-06-30  1:16 ` [PATCH V2 1/4] PCI: move PCI_FIND_CAP_TTL to pci.h and use it in quirks Wei Yang
2015-07-14 21:57   ` Bjorn Helgaas
2015-06-30  1:16 ` [PATCH V2 2/4] PCI: use u8 to represent pci configuration space pos and cap Wei Yang
2015-06-30  1:16 ` [PATCH V2 3/4] PCI: use u16 to represent pci express extended capabilities " Wei Yang
2015-06-30  1:16 ` [PATCH V2 4/4] PCI: consolidate return value check for pci_find_(ext_)capability Wei Yang
2015-07-14 22:00   ` Bjorn Helgaas
2015-07-15  2:02     ` Wei Yang
2015-07-15  2:11       ` Bjorn Helgaas [this message]
2015-07-15  5:46         ` Wei Yang
2015-07-14 21:37 ` [PATCH V2 0/4] PCI: code clean up on pci configuration space Bjorn Helgaas
2015-07-15  2:08   ` Wei Yang

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=CAErSpo4o4z+OHdoLjhzEY4QwTN4dZkbjw5ot4sdUmOx8bFxyjA@mail.gmail.com \
    --to=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=weiyang@linux.vnet.ibm.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 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.