Skip to content

Commit

Permalink
driver model: anti-oopsing medicine
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David Brownell authored and Greg Kroah-Hartman committed Aug 21, 2008
1 parent bf9ca69 commit 7c22503
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/base/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7c22503

Please sign in to comment.