Commit 7c225035 authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman

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: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent bf9ca69f
...@@ -295,6 +295,12 @@ int class_for_each_device(struct class *class, struct device *start, ...@@ -295,6 +295,12 @@ int class_for_each_device(struct class *class, struct device *start,
if (!class) if (!class)
return -EINVAL; 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); mutex_lock(&class->p->class_mutex);
list_for_each_entry(dev, &class->p->class_devices, node) { list_for_each_entry(dev, &class->p->class_devices, node) {
if (start) { if (start) {
...@@ -344,6 +350,11 @@ struct device *class_find_device(struct class *class, struct device *start, ...@@ -344,6 +350,11 @@ struct device *class_find_device(struct class *class, struct device *start,
if (!class) if (!class)
return NULL; 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); mutex_lock(&class->p->class_mutex);
list_for_each_entry(dev, &class->p->class_devices, node) { list_for_each_entry(dev, &class->p->class_devices, node) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment