From: Stephen Hemminger <stephen@networkplumber.org>
To: Greg KH <gregkh@linux-foundation.org>
Cc: linux-pci@vger.kernel.org
Subject: [RFC] pci: crash on pci_unregister_driver after pci_register_driver fails
Date: Tue, 3 Sep 2013 15:38:15 -0700 [thread overview]
Message-ID: <20130903153815.13638272@nehalam.linuxnetplumber.net> (raw)
While debugging another problem with a PCI driver, I noticed that if
device probe routine returns an error, the kernel will crash when module
is unloaded. It looks like pci_register_driver() sets drv->bus to be PCI
then in the module unload.
module_unload
my_device_exit_module
pci_unregister_driver
bus_remove_driver
OOPS
One way to fix this would be to have pci_register_driver clear the bus
flag (it has no reference) if an error was detected.
--- a/drivers/pci/pci-driver.c 2013-07-08 10:54:52.968241742 -0700
+++ b/drivers/pci/pci-driver.c 2013-09-03 15:34:10.112477893 -0700
@@ -1120,6 +1120,8 @@ const struct dev_pm_ops pci_dev_pm_ops =
int __pci_register_driver(struct pci_driver *drv, struct module *owner,
const char *mod_name)
{
+ int err;
+
/* initialize common driver fields */
drv->driver.name = drv->name;
drv->driver.bus = &pci_bus_type;
@@ -1130,7 +1132,11 @@ int __pci_register_driver(struct pci_dri
INIT_LIST_HEAD(&drv->dynids.list);
/* register with core */
- return driver_register(&drv->driver);
+ err = driver_register(&drv->driver);
+ if (err)
+ drv->driver.bus = NULL;
+
+ return err;
}
/**
next reply other threads:[~2013-09-03 22:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-03 22:38 Stephen Hemminger [this message]
2013-09-03 23:06 ` [RFC] pci: crash on pci_unregister_driver after pci_register_driver fails Greg KH
2013-09-04 16:13 ` Stephen Hemminger
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=20130903153815.13638272@nehalam.linuxnetplumber.net \
--to=stephen@networkplumber.org \
--cc=gregkh@linux-foundation.org \
--cc=linux-pci@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 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.