Commit ff75fb77 authored by Patrick Mochel's avatar Patrick Mochel

driver model: use list_for_each_safe in device_shutdown(), since devices can be

removed from the global list in the process.

Also, call put_device() on the last device. 

Origintally from Andrew Morton.
parent b2345583
...@@ -92,13 +92,13 @@ void device_resume(u32 level) ...@@ -92,13 +92,13 @@ void device_resume(u32 level)
*/ */
void device_shutdown(void) void device_shutdown(void)
{ {
struct list_head * node; struct list_head * node, * next;
struct device * prev = NULL; struct device * prev = NULL;
printk(KERN_EMERG "Shutting down devices\n"); printk(KERN_EMERG "Shutting down devices\n");
spin_lock(&device_lock); spin_lock(&device_lock);
list_for_each(node,&global_device_list) { list_for_each_safe(node,next,&global_device_list) {
struct device * dev = get_device_locked(to_dev(node)); struct device * dev = get_device_locked(to_dev(node));
if (dev) { if (dev) {
spin_unlock(&device_lock); spin_unlock(&device_lock);
...@@ -111,6 +111,8 @@ void device_shutdown(void) ...@@ -111,6 +111,8 @@ void device_shutdown(void)
} }
} }
spin_unlock(&device_lock); spin_unlock(&device_lock);
if (prev)
put_device(prev);
} }
EXPORT_SYMBOL(device_suspend); EXPORT_SYMBOL(device_suspend);
......
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