netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tilman Schmidt <tilman@imap.cc>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Andi Kleen <andi@firstfloor.org>, Greg KH <gregkh@suse.de>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	LKML <linux-kernel@vger.kernel.org>,
	netdev@vger.kernel.org, Karsten Keil <isdn@linux-pingi.de>,
	isdn4linux@listserv.isdn4linux.de
Subject: Re: Can we remove pci_find_device() yet?
Date: Wed, 20 Jan 2010 16:11:08 +0100 (CET)	[thread overview]
Message-ID: <20100120151109.29FA240109@xenon.ts.pxnet.com> (raw)
In-Reply-To: 20100114110214.37d7ffc9@lxorguk.ukuu.org.uk

On Thu, Jan 14, 2010 at 11:02:14AM +0000, Alan Cox wrote:
> > e.g. set some global variable that forbids device removal
> > and warn in the kernel log. In theory this could be also
> > done per device, but I guess that would be more effort.
> 
> There is a simpler way to do that, which is to just leak a reference in
> the hisax_find_pci_device hack. The pci_dev won't be going anywhere then.

Something like this? (On top of my previous patch introducing
hisax_find_pci_device in the first place.)

Subject: [PATCH RFC] isdn/hisax: intentionally leak a reference in hisax_find_pci_device

Take a reference to the returned pci_dev which will never be released.
Until the HiSax drivers are fixed for proper PCI hotplug support,
this appears as the lesser evil compared to the danger of the
structure being freed without the caller knowing it.

Impact: replacing a bug by another, less consequential one
Signed-off-by: Tilman Schmidt <tilman@imap.cc>
---
 drivers/isdn/hisax/hisax.h |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/isdn/hisax/hisax.h b/drivers/isdn/hisax/hisax.h
index 832a878..e459502 100644
--- a/drivers/isdn/hisax/hisax.h
+++ b/drivers/isdn/hisax/hisax.h
@@ -1328,21 +1328,18 @@ void TeiFree(void);
 
 #include <linux/pci.h>
 
-/* adaptation wrapper for old usage
- * WARNING! This is unfit for use in a PCI hotplug environment,
- * as the returned PCI device can disappear at any moment in time.
+/* This function replaces the former function pci_find_device().
+ * Unlike the latter, it takes a reference on the returned pci_dev,
+ * resulting in a reference leak. This is intentional and serves to
+ * prevent an untimely release of the PCI device structure.
  * Callers should be converted to use pci_get_device() instead.
  */
 static inline struct pci_dev *hisax_find_pci_device(unsigned int vendor,
 						    unsigned int device,
 						    struct pci_dev *from)
 {
-	struct pci_dev *pdev;
-
 	pci_dev_get(from);
-	pdev = pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
-	pci_dev_put(pdev);
-	return pdev;
+	return pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
 }
 
 #endif
-- 
1.6.5.3.298.g39add


      parent reply	other threads:[~2010-01-20 15:19 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-08  0:22 Can we remove pci_find_device() yet? Stephen Rothwell
2010-01-08  4:46 ` Greg KH
2010-01-11 19:46   ` Tilman Schmidt
2010-01-11 20:01     ` Greg KH
2010-01-12  0:21       ` Stephen Rothwell
2010-01-12  0:46         ` Greg KH
2010-01-12 16:42       ` Tilman Schmidt
2010-01-12 17:39         ` Greg KH
2010-01-13  9:02           ` Tilman Schmidt
2010-01-12 20:34       ` Krzysztof Halasa
2010-01-12 20:53         ` Ben Hutchings
2010-01-12 21:18           ` Greg KH
2010-01-13 15:09             ` Krzysztof Halasa
2010-01-13 14:23       ` [PATCH] pci: push deprecated pci_find_device() function to last user Tilman Schmidt
2010-01-14  4:33         ` David Miller
2010-01-14  4:43           ` Greg KH
2010-01-14  8:12             ` David Miller
2010-01-14 16:28               ` Jesse Barnes
2010-01-14 22:18                 ` [PATCH/REPOST] " Tilman Schmidt
2010-01-15 18:08                   ` Jesse Barnes
2010-01-16 11:17                     ` Stephen Rothwell
2010-01-18 16:24                 ` [PATCH/v2] " Tilman Schmidt
2010-01-14 10:18       ` Can we remove pci_find_device() yet? Andi Kleen
2010-01-14 11:02         ` Alan Cox
2010-01-14 11:03           ` Andi Kleen
2010-01-14 12:39             ` Tilman Schmidt
2010-01-20 15:11           ` Tilman Schmidt [this message]

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=20100120151109.29FA240109@xenon.ts.pxnet.com \
    --to=tilman@imap.cc \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=andi@firstfloor.org \
    --cc=gregkh@suse.de \
    --cc=isdn4linux@listserv.isdn4linux.de \
    --cc=isdn@linux-pingi.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    /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).