netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Garzik <jgarzik@pobox.com>
To: Jiri Slaby <jirislaby@gmail.com>
Cc: Greg KH <gregkh@suse.de>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-pci@atrey.karlin.mff.cuni.cz, netdev@vger.kernel.org,
	mb@bu3sch.de, st3@riseup.net, linville@tuxdriver.com
Subject: Re: [PATCH 2/3] pci: bcm43xx avoid pci_find_device
Date: Fri, 26 May 2006 06:37:16 -0400	[thread overview]
Message-ID: <4476DA5C.9080602@pobox.com> (raw)
In-Reply-To: <4476D95B.5030601@gmail.com>

Jiri Slaby wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Jeff Garzik napsal(a):
>> Jiri Slaby wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> Jeff Garzik napsal(a):
>>>> Jiri Slaby wrote:
>>>>> bcm43xx avoid pci_find_device
>>>>>
>>>>> Change pci_find_device to safer pci_get_device with support for more
>>>>> devices.
>>>>>
>>>>> Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
>>>>>
>>>>> ---
>>>>> commit 1d3b6caf027fe53351c645523587aeac40bc3e47
>>>>> tree ae37c86b633442cdf8a7a19ac287542724081c90
>>>>> parent ab3443d79c94d0ae6a9e020daefa4d29eccff50d
>>>>> author Jiri Slaby <ku@bellona.localdomain> Fri, 26 May 2006 01:49:12
>>>>> +0159
>>>>> committer Jiri Slaby <ku@bellona.localdomain> Fri, 26 May 2006
>>>>> 01:49:12 +0159
>>>>>
>>>>>  drivers/net/wireless/bcm43xx/bcm43xx_main.c |   20
>>>>> ++++++++++++++++----
>>>>>  1 files changed, 16 insertions(+), 4 deletions(-)
>>>>>
>>>>> diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
>>>>> b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
>>>>> index b488f77..56d2fc6 100644
>>>>> --- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
>>>>> +++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
>>>>> @@ -2131,6 +2131,13 @@ out:
>>>>>      return err;
>>>>>  }
>>>>>  
>>>>> +#ifdef CONFIG_BCM947XX
>>>>> +static struct pci_device_id bcm43xx_ids[] = {
>>>>> +    { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4324) },
>>>>> +    { 0 }
>>>>> +};
> Table is here ^^^. You just add an entry, and that's it.
>>>>> +#endif
>>>>> +
>>>>>  static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm)
>>>>>  {
>>>>>      int res;
>>>>> @@ -2141,10 +2148,15 @@ static int bcm43xx_initialize_irq(struct
>>>>>  #ifdef CONFIG_BCM947XX
>>>>>      if (bcm->pci_dev->bus->number == 0) {
>>>>>          struct pci_dev *d = NULL;
>>>>> -        /* FIXME: we will probably need more device IDs here... */
>>>>> -        d = pci_find_device(PCI_VENDOR_ID_BROADCOM, 0x4324, NULL);
>>>>> -        if (d != NULL) {
>>>>> -            bcm->irq = d->irq;
>>>>> +        struct pci_device_id *id = bcm43xx_ids;
>>>>> +        while (id->vendor) {
>>>>> +            d = pci_get_device(id->vendor, id->device, NULL);
>>>>> +            if (d != NULL) {
>>>>> +                bcm->irq = d->irq;
>>>>> +                pci_dev_put(d);
>>>>> +                break;
>>>> You'll want to use pci_match_device() or pci_match_one_device()
>>>> [I forget which one]
>>> Why? Matching is done by pci_get_device() or pci_get_subsys(),
>>> respectively.
>>> [pci_match_device() is for matching dev <-> drv, you meant
>>> pci_match_one_device()]
>> The FIXME says "we will probably need more device IDs here."
> Yup.
>> Thus, if you are touching this area, it would make sense to add the
>> capability to easily add a second (and third, fourth...) PCI ID.  And
>> that means pci_match_one_device() and a pci_device_id table.
> But the while loop do the work: unless id->vendor != NULL, do the matching with
> the current raw (id) of the table, then jump to the next raw (id++).
> 
> pci_get_device returns NULL if the device with id->vendor, id->device wasn't
> found, then we try next raw, otherwise, we break the loop.
> 
> Implementations before and now do the same strangeness -- assume there is only
> one device (?shouldn't matter?, since it is embedded).

The point is that you don't need to loop over the table, 
pci_match_one_device() does that for you.

And this code, like the gt96100_eth code, is testing the existence of 
certain platform devices, to be certain that it can proceed with certain 
platform-specific duties.

Thus we don't care about matching multiple devices -- an unlikely case 
-- but we do care about making the code as small as possible by calling 
a standard PCI match function which searches through a list of PCI IDs.

	Jeff



  reply	other threads:[~2006-05-26 10:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20060526001053.D2349C7C58@atrey.karlin.mff.cuni.cz>
2006-05-26  0:35 ` [PATCH 2/3] pci: bcm43xx avoid pci_find_device Jeff Garzik
2006-05-26 10:20   ` Jiri Slaby
2006-05-26 10:22     ` Jeff Garzik
2006-05-26 10:33       ` Jiri Slaby
2006-05-26 10:37         ` Jeff Garzik [this message]
2006-05-26 10:54           ` Jiri Slaby
2006-05-26 11:09             ` Jeff Garzik
2006-05-26 11:30               ` Jiri Slaby
2006-06-05 18:56                 ` John W. Linville
2006-06-05 19:10                   ` Jiri Slaby
2006-05-26 11:49         ` Michael Buesch
2006-05-26 11:52           ` Jiri Slaby
2006-06-05 20:16 [PATCH 0/3 #3] " Jiri Slaby
     [not found] ` <20060605202007.B464FC7B73@atrey.karlin.mff.cuni.cz>
2006-06-05 20:53   ` [PATCH 2/3] pci: bcm43xx " Greg KH
2006-06-05 21:09     ` Jiri Slaby
2006-06-06  1:18     ` Jeff Garzik
2006-06-06  6:50       ` Greg KH
2006-06-06 12:58     ` Michael Buesch
     [not found] <20060605201818.1239938CE036@bu3sch.de>
2006-06-05 20:35 ` Michael Buesch
2006-06-05 20:46   ` Jiri Slaby

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=4476DA5C.9080602@pobox.com \
    --to=jgarzik@pobox.com \
    --cc=gregkh@suse.de \
    --cc=jirislaby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@atrey.karlin.mff.cuni.cz \
    --cc=linville@tuxdriver.com \
    --cc=mb@bu3sch.de \
    --cc=netdev@vger.kernel.org \
    --cc=st3@riseup.net \
    /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).