From: Greg KH <greg@kroah.com>
To: Linux Kernel List <linux-kernel@vger.kernel.org>,
Patrick Mochel <mochel@osdl.org>,
Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
Jeff Garzik <jgarzik@pobox.com>,
Rusty Russell <rusty@rustcorp.com.au>
Subject: Re: PCI driver module unload race?
Date: Sat, 8 Mar 2003 11:12:37 -0800 [thread overview]
Message-ID: <20030308191237.GA26374@kroah.com> (raw)
In-Reply-To: <20030308104749.A29145@flint.arm.linux.org.uk>
On Sat, Mar 08, 2003 at 10:47:49AM +0000, Russell King wrote:
> Hi,
>
> What prevents the following scenario from happening? It's purely
> theoretical - I haven't seen this occuring.
>
> - Load PCI driver.
>
> - PCI driver registers using pci_module_init(), and adds itself to sysfs.
>
> - Hot-plugin a PCI device which uses this driver. sysfs matches the PCI
> driver, and calls the PCI drivers probe function.
Ugh, yes you are correct, I can't believe I missed this before.
How does this patch look?
thanks,
greg k-h
===== drivers/pci/pci-driver.c 1.17 vs edited =====
--- 1.17/drivers/pci/pci-driver.c Sat Nov 23 13:23:03 2002
+++ edited/drivers/pci/pci-driver.c Sat Mar 8 11:21:06 2003
@@ -48,6 +48,12 @@
if (!pci_dev->driver && drv->probe) {
const struct pci_device_id *id;
+ if (!try_module_get(drv->owner)) {
+ dev_err(dev, "Can't get a module reference for %s\n",
+ drv->name);
+ error = -ENODEV;
+ goto exit;
+ }
id = pci_match_device(drv->id_table, pci_dev);
if (id)
error = drv->probe(pci_dev, id);
@@ -55,7 +61,9 @@
pci_dev->driver = drv;
error = 0;
}
+ module_put(drv->owner);
}
+exit:
return error;
}
@@ -66,7 +74,10 @@
if (drv) {
if (drv->remove)
- drv->remove(pci_dev);
+ if (try_module_get(drv->owner)) {
+ drv->remove(pci_dev);
+ module_put(drv->owner);
+ }
pci_dev->driver = NULL;
}
return 0;
===== include/linux/pci.h 1.36 vs edited =====
--- 1.36/include/linux/pci.h Tue Mar 4 21:09:58 2003
+++ edited/include/linux/pci.h Sat Mar 8 11:20:15 2003
@@ -493,6 +493,7 @@
struct pci_driver {
struct list_head node;
+ struct module *owner;
char *name;
const struct pci_device_id *id_table; /* NULL if wants all devices */
int (*probe) (struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
next prev parent reply other threads:[~2003-03-08 19:12 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-08 10:47 PCI driver module unload race? Russell King
2003-03-08 19:12 ` Greg KH [this message]
2003-03-08 19:47 ` Petr Vandrovec
2003-03-08 19:51 ` Greg KH
2003-03-09 2:33 ` Petr Vandrovec
2003-03-08 20:03 ` Russell King
2003-03-08 20:09 ` Russell King
2003-03-08 20:21 ` Greg KH
2003-03-10 21:44 ` Greg KH
2003-03-10 23:48 ` Oliver Neukum
2003-03-10 23:51 ` Greg KH
2003-03-11 1:04 ` Roman Zippel
2003-03-11 1:15 ` Greg KH
2003-03-11 9:00 ` Oliver Neukum
2003-03-11 15:06 ` Patrick Mochel
2003-03-11 16:07 ` Oliver Neukum
2003-03-16 13:13 ` Rusty Russell
2003-03-11 11:05 ` Roman Zippel
2003-03-11 15:27 ` Patrick Mochel
2003-03-11 20:09 ` Roman Zippel
2003-03-11 19:15 ` Patrick Mochel
2003-03-12 2:28 ` Roman Zippel
2003-03-16 13:05 ` Rusty Russell
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=20030308191237.GA26374@kroah.com \
--to=greg@kroah.com \
--cc=ink@jurassic.park.msu.ru \
--cc=jgarzik@pobox.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mochel@osdl.org \
--cc=rusty@rustcorp.com.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 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.