kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@debian.org>
To: kernel-janitors@vger.kernel.org
Subject: Re: [Kernel-janitors] pci_find_* to pci_get_*
Date: Mon, 20 Sep 2004 11:39:44 +0000	[thread overview]
Message-ID: <20040920113944.GO642@parcelfarce.linux.theplanet.co.uk> (raw)
In-Reply-To: <1095662774.4052.10.camel@sfeldma-mobl2.dsl-verizon.net>

[-- Attachment #1: Type: text/plain, Size: 1987 bytes --]

On Mon, Sep 20, 2004 at 01:20:20AM -0700, Scott Feldman wrote:
> diff -Nru a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
> --- a/drivers/net/e1000/e1000_main.c	2004-09-20 00:25:03 -07:00
> +++ b/drivers/net/e1000/e1000_main.c	2004-09-20 00:25:03 -07:00
> @@ -2789,9 +2789,10 @@
>  	case SYS_DOWN:
>  	case SYS_HALT:
>  	case SYS_POWER_OFF:
> -		while((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
> +		while((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
>  			if(pci_dev_driver(pdev) == &e1000_driver)
>  				e1000_suspend(pdev, 3);
> +			pci_dev_put(pdev);
>  		}
>  	}
>  	return NOTIFY_DONE;

Ummm... there's still a race here.  Between the pci_dev_put() returning and
the invocation of pci_get_device(), the pdev can go away.  I guess you have
to do something like:

	for (;;) {
		old_pdev = pdev;
		pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, old_pdev);
		pci_dev_put(old_pdev);
		if (!pdev)
			break;
		if (pci_dev_driver(pdev) == &e1000_driver)
			e1000_suspend(pdev, 3);
	}

This seems to be quite a common idiom though.  I wonder if we can
encapsulate it into

	for_each_pci_device(PCI_ANY_ID, PCI_ANY_ID, pdev, tmp) {
		if (pci_dev_driver(pdev) == &e1000_driver)
			e1000_suspend(pdev, 3);
	}

This should do it:

#define NEXT_DEV(vendid, devid, pdev, tmp) \
	tmp = pdev, pdev = pci_get_device(vendid, devid, tmp), pci_dev_put(tmp)
#define for_each_pci_device(vendid, devid, pdev, tmp)	\
	for (NEXT_DEV(vendid, devid, pdev, tmp);	\
	     pdev;					\
	     NEXT_DEV(vendid, devid, pdev, tmp))

Comments?

-- 
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain

[-- Attachment #2: Type: text/plain, Size: 167 bytes --]

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
http://lists.osdl.org/mailman/listinfo/kernel-janitors

  parent reply	other threads:[~2004-09-20 11:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-20  6:46 [Kernel-janitors] pci_find_* to pci_get_* Scott Feldman
2004-09-20  7:03 ` Greg KH
2004-09-20  8:20 ` Scott Feldman
2004-09-20 11:39 ` Matthew Wilcox [this message]
2004-09-20 15:37 ` Greg KH
2004-09-20 15:38 ` Greg KH
2004-09-20 17:12 ` Christoph Hellwig
2004-09-20 18:16 ` Feldman, Scott
2004-09-20 18:25 ` Hanna Linder

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=20040920113944.GO642@parcelfarce.linux.theplanet.co.uk \
    --to=willy@debian.org \
    --cc=kernel-janitors@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).