summaryrefslogtreecommitdiffstats
path: root/drivers/base/class.c
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2008-08-06 18:52:44 -0700
committerGreg Kroah-Hartman <gregkh@suse.de>2008-08-21 10:15:36 -0700
commit7c2250352e11bf956c4cfa20b01ae6ba72882788 (patch)
tree8ea27a86d737d80a77931f1bc4d59b6aa8eafca7 /drivers/base/class.c
parentbf9ca69fc8d19d4034391d3df4c35dccdef9d28c (diff)
downloadlinux-7c2250352e11bf956c4cfa20b01ae6ba72882788.tar.gz
linux-7c2250352e11bf956c4cfa20b01ae6ba72882788.tar.bz2
linux-7c2250352e11bf956c4cfa20b01ae6ba72882788.zip
driver model: anti-oopsing medicine
Anti-oops medicine for the class iterators ... the oops was observed when a class was implicitly referenced before it was initialized. [Modified by Greg to spit a warning back so someone knows to fix their code] Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/class.c')
-rw-r--r--drivers/base/class.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 5667c2f02c51..cc5e28c8885c 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -295,6 +295,12 @@ int class_for_each_device(struct class *class, struct device *start,
if (!class)
return -EINVAL;
+ if (!class->p) {
+ WARN(1, "%s called for class '%s' before it was initialized",
+ __func__, class->name);
+ return -EINVAL;
+ }
+
mutex_lock(&class->p->class_mutex);
list_for_each_entry(dev, &class->p->class_devices, node) {
if (start) {
@@ -344,6 +350,11 @@ struct device *class_find_device(struct class *class, struct device *start,
if (!class)
return NULL;
+ if (!class->p) {
+ WARN(1, "%s called for class '%s' before it was initialized",
+ __func__, class->name);
+ return NULL;
+ }
mutex_lock(&class->p->class_mutex);
list_for_each_entry(dev, &class->p->class_devices, node) {