LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Cc: Ian McDonald <ian.mcdonald@jandi.co.nz>,
	gregkh@suse.de,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Jeff Garzik <jeff@garzik.org>
Subject: [PATCH] pci: allow multiple calls to pcim_pin_device()
Date: Tue, 20 Feb 2007 17:28:39 +0900	[thread overview]
Message-ID: <20070220082839.GN1625@htj.dyndns.org> (raw)
In-Reply-To: <200702191247.03274.bzolnier@gmail.com>

Sanity check in pcim_pin_device() was too restrictive in that it
didn't allow multiple calls to the function, which is against the
devres philosohpy of fire-and-forget.  Track pinned status separately
and allow pinning multiple times.

Signed-off-by: Tejun Heo <htejun@gmail.com>
---
It was an actual bug in pcim_pin_device() implementation.  Thanks for
spotting this.  :-)

Ian McDonald, please verify your warning goes away with this patch.

Greg, please forward this patch upstream once Ian acks it.

Thanks.

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 8b44cff..a1927ea 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -751,7 +751,8 @@ int pci_enable_device(struct pci_dev *dev)
  * when a device is enabled using managed PCI device enable interface.
  */
 struct pci_devres {
-	unsigned int disable:1;
+	unsigned int enabled:1;
+	unsigned int pinned:1;
 	unsigned int orig_intx:1;
 	unsigned int restore_intx:1;
 	u32 region_mask;
@@ -775,7 +776,7 @@ static void pcim_release(struct device *gendev, void *res)
 	if (this->restore_intx)
 		pci_intx(dev, this->orig_intx);
 
-	if (this->disable)
+	if (this->enabled && !this->pinned)
 		pci_disable_device(dev);
 }
 
@@ -814,12 +815,12 @@ int pcim_enable_device(struct pci_dev *pdev)
 	dr = get_pci_dr(pdev);
 	if (unlikely(!dr))
 		return -ENOMEM;
-	WARN_ON(!!dr->disable);
+	WARN_ON(!!dr->enabled);
 
 	rc = pci_enable_device(pdev);
 	if (!rc) {
 		pdev->is_managed = 1;
-		dr->disable = 1;
+		dr->enabled = 1;
 	}
 	return rc;
 }
@@ -837,9 +838,9 @@ void pcim_pin_device(struct pci_dev *pdev)
 	struct pci_devres *dr;
 
 	dr = find_pci_dr(pdev);
-	WARN_ON(!dr || !dr->disable);
+	WARN_ON(!dr || !dr->enabled);
 	if (dr)
-		dr->disable = 0;
+		dr->pinned = 1;
 }
 
 /**
@@ -870,7 +871,7 @@ pci_disable_device(struct pci_dev *dev)
 
 	dr = find_pci_dr(dev);
 	if (dr)
-		dr->disable = 0;
+		dr->enabled = 0;
 
 	if (atomic_sub_return(1, &dev->enable_cnt) != 0)
 		return;

  reply	other threads:[~2007-02-20  8:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-18 19:53 [BUG/WARN] Error initialising drivers in PCI Ian McDonald
2007-02-18 20:58 ` Bartlomiej Zolnierkiewicz
2007-02-19  4:00   ` Ian McDonald
2007-02-19 11:47     ` Bartlomiej Zolnierkiewicz
2007-02-20  8:28       ` Tejun Heo [this message]
2007-02-20 21:45         ` [PATCH] pci: allow multiple calls to pcim_pin_device() Ian McDonald

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=20070220082839.GN1625@htj.dyndns.org \
    --to=htejun@gmail.com \
    --cc=bzolnier@gmail.com \
    --cc=gregkh@suse.de \
    --cc=ian.mcdonald@jandi.co.nz \
    --cc=jeff@garzik.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH] pci: allow multiple calls to pcim_pin_device()' \
    /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

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).