diff options
author | Shaohua Li <shaohua.li@intel.com> | 2009-04-06 22:24:29 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2009-04-07 00:02:40 -0400 |
commit | 9090589d87506c578ea1523ffd7ae7fd9424fb28 (patch) | |
tree | 215163d13dbfa514a4121594cd4c6e27fde9b911 /drivers | |
parent | d508afb437daee7cf07da085b635c44a4ebf9b38 (diff) |
ACPI: convert acpi_device_lock spinlock to mutex
Convert acpi_device_lock to a mutex to avoid
a potential race upon access to /proc/acpi/wakeup
Delete the lock entirely in wakeup.c
since it is not necessary (and can not sleep)
Found-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/acpi/proc.c | 13 | ||||
-rw-r--r-- | drivers/acpi/scan.c | 14 | ||||
-rw-r--r-- | drivers/acpi/sleep.h | 3 | ||||
-rw-r--r-- | drivers/acpi/wakeup.c | 30 |
4 files changed, 21 insertions, 39 deletions
diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c index 05dfdc96802e..d0d550d22a6d 100644 --- a/drivers/acpi/proc.c +++ b/drivers/acpi/proc.c | |||
@@ -343,9 +343,6 @@ acpi_system_write_alarm(struct file *file, | |||
343 | } | 343 | } |
344 | #endif /* HAVE_ACPI_LEGACY_ALARM */ | 344 | #endif /* HAVE_ACPI_LEGACY_ALARM */ |
345 | 345 | ||
346 | extern struct list_head acpi_wakeup_device_list; | ||
347 | extern spinlock_t acpi_device_lock; | ||
348 | |||
349 | static int | 346 | static int |
350 | acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) | 347 | acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) |
351 | { | 348 | { |
@@ -353,7 +350,7 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) | |||
353 | 350 | ||
354 | seq_printf(seq, "Device\tS-state\t Status Sysfs node\n"); | 351 | seq_printf(seq, "Device\tS-state\t Status Sysfs node\n"); |
355 | 352 | ||
356 | spin_lock(&acpi_device_lock); | 353 | mutex_lock(&acpi_device_lock); |
357 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 354 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
358 | struct acpi_device *dev = | 355 | struct acpi_device *dev = |
359 | container_of(node, struct acpi_device, wakeup_list); | 356 | container_of(node, struct acpi_device, wakeup_list); |
@@ -361,7 +358,6 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) | |||
361 | 358 | ||
362 | if (!dev->wakeup.flags.valid) | 359 | if (!dev->wakeup.flags.valid) |
363 | continue; | 360 | continue; |
364 | spin_unlock(&acpi_device_lock); | ||
365 | 361 | ||
366 | ldev = acpi_get_physical_device(dev->handle); | 362 | ldev = acpi_get_physical_device(dev->handle); |
367 | seq_printf(seq, "%s\t S%d\t%c%-8s ", | 363 | seq_printf(seq, "%s\t S%d\t%c%-8s ", |
@@ -376,9 +372,8 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) | |||
376 | seq_printf(seq, "\n"); | 372 | seq_printf(seq, "\n"); |
377 | put_device(ldev); | 373 | put_device(ldev); |
378 | 374 | ||
379 | spin_lock(&acpi_device_lock); | ||
380 | } | 375 | } |
381 | spin_unlock(&acpi_device_lock); | 376 | mutex_unlock(&acpi_device_lock); |
382 | return 0; | 377 | return 0; |
383 | } | 378 | } |
384 | 379 | ||
@@ -409,7 +404,7 @@ acpi_system_write_wakeup_device(struct file *file, | |||
409 | strbuf[len] = '\0'; | 404 | strbuf[len] = '\0'; |
410 | sscanf(strbuf, "%s", str); | 405 | sscanf(strbuf, "%s", str); |
411 | 406 | ||
412 | spin_lock(&acpi_device_lock); | 407 | mutex_lock(&acpi_device_lock); |
413 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 408 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
414 | struct acpi_device *dev = | 409 | struct acpi_device *dev = |
415 | container_of(node, struct acpi_device, wakeup_list); | 410 | container_of(node, struct acpi_device, wakeup_list); |
@@ -446,7 +441,7 @@ acpi_system_write_wakeup_device(struct file *file, | |||
446 | } | 441 | } |
447 | } | 442 | } |
448 | } | 443 | } |
449 | spin_unlock(&acpi_device_lock); | 444 | mutex_unlock(&acpi_device_lock); |
450 | return count; | 445 | return count; |
451 | } | 446 | } |
452 | 447 | ||
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 20c23c049207..e63f2febad84 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -24,7 +24,7 @@ extern struct acpi_device *acpi_root; | |||
24 | 24 | ||
25 | static LIST_HEAD(acpi_device_list); | 25 | static LIST_HEAD(acpi_device_list); |
26 | static LIST_HEAD(acpi_bus_id_list); | 26 | static LIST_HEAD(acpi_bus_id_list); |
27 | DEFINE_SPINLOCK(acpi_device_lock); | 27 | DEFINE_MUTEX(acpi_device_lock); |
28 | LIST_HEAD(acpi_wakeup_device_list); | 28 | LIST_HEAD(acpi_wakeup_device_list); |
29 | 29 | ||
30 | struct acpi_device_bus_id{ | 30 | struct acpi_device_bus_id{ |
@@ -500,7 +500,7 @@ static int acpi_device_register(struct acpi_device *device, | |||
500 | return -ENOMEM; | 500 | return -ENOMEM; |
501 | } | 501 | } |
502 | 502 | ||
503 | spin_lock(&acpi_device_lock); | 503 | mutex_lock(&acpi_device_lock); |
504 | /* | 504 | /* |
505 | * Find suitable bus_id and instance number in acpi_bus_id_list | 505 | * Find suitable bus_id and instance number in acpi_bus_id_list |
506 | * If failed, create one and link it into acpi_bus_id_list | 506 | * If failed, create one and link it into acpi_bus_id_list |
@@ -528,7 +528,7 @@ static int acpi_device_register(struct acpi_device *device, | |||
528 | list_add_tail(&device->g_list, &acpi_device_list); | 528 | list_add_tail(&device->g_list, &acpi_device_list); |
529 | if (device->wakeup.flags.valid) | 529 | if (device->wakeup.flags.valid) |
530 | list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list); | 530 | list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list); |
531 | spin_unlock(&acpi_device_lock); | 531 | mutex_unlock(&acpi_device_lock); |
532 | 532 | ||
533 | if (device->parent) | 533 | if (device->parent) |
534 | device->dev.parent = &parent->dev; | 534 | device->dev.parent = &parent->dev; |
@@ -549,20 +549,20 @@ static int acpi_device_register(struct acpi_device *device, | |||
549 | device->removal_type = ACPI_BUS_REMOVAL_NORMAL; | 549 | device->removal_type = ACPI_BUS_REMOVAL_NORMAL; |
550 | return 0; | 550 | return 0; |
551 | end: | 551 | end: |
552 | spin_lock(&acpi_device_lock); | 552 | mutex_lock(&acpi_device_lock); |
553 | if (device->parent) { | 553 | if (device->parent) { |
554 | list_del(&device->node); | 554 | list_del(&device->node); |
555 | list_del(&device->g_list); | 555 | list_del(&device->g_list); |
556 | } else | 556 | } else |
557 | list_del(&device->g_list); | 557 | list_del(&device->g_list); |
558 | list_del(&device->wakeup_list); | 558 | list_del(&device->wakeup_list); |
559 | spin_unlock(&acpi_device_lock); | 559 | mutex_unlock(&acpi_device_lock); |
560 | return result; | 560 | return result; |
561 | } | 561 | } |
562 | 562 | ||
563 | static void acpi_device_unregister(struct acpi_device *device, int type) | 563 | static void acpi_device_unregister(struct acpi_device *device, int type) |
564 | { | 564 | { |
565 | spin_lock(&acpi_device_lock); | 565 | mutex_lock(&acpi_device_lock); |
566 | if (device->parent) { | 566 | if (device->parent) { |
567 | list_del(&device->node); | 567 | list_del(&device->node); |
568 | list_del(&device->g_list); | 568 | list_del(&device->g_list); |
@@ -570,7 +570,7 @@ static void acpi_device_unregister(struct acpi_device *device, int type) | |||
570 | list_del(&device->g_list); | 570 | list_del(&device->g_list); |
571 | 571 | ||
572 | list_del(&device->wakeup_list); | 572 | list_del(&device->wakeup_list); |
573 | spin_unlock(&acpi_device_lock); | 573 | mutex_unlock(&acpi_device_lock); |
574 | 574 | ||
575 | acpi_detach_data(device->handle, acpi_bus_data_handler); | 575 | acpi_detach_data(device->handle, acpi_bus_data_handler); |
576 | 576 | ||
diff --git a/drivers/acpi/sleep.h b/drivers/acpi/sleep.h index cfaf8f5b0a14..8a8f3b3382a6 100644 --- a/drivers/acpi/sleep.h +++ b/drivers/acpi/sleep.h | |||
@@ -5,3 +5,6 @@ extern int acpi_suspend (u32 state); | |||
5 | extern void acpi_enable_wakeup_device_prep(u8 sleep_state); | 5 | extern void acpi_enable_wakeup_device_prep(u8 sleep_state); |
6 | extern void acpi_enable_wakeup_device(u8 sleep_state); | 6 | extern void acpi_enable_wakeup_device(u8 sleep_state); |
7 | extern void acpi_disable_wakeup_device(u8 sleep_state); | 7 | extern void acpi_disable_wakeup_device(u8 sleep_state); |
8 | |||
9 | extern struct list_head acpi_wakeup_device_list; | ||
10 | extern struct mutex acpi_device_lock; | ||
diff --git a/drivers/acpi/wakeup.c b/drivers/acpi/wakeup.c index 5aee8c26cc9f..88725dcdf8bc 100644 --- a/drivers/acpi/wakeup.c +++ b/drivers/acpi/wakeup.c | |||
@@ -12,12 +12,14 @@ | |||
12 | #include "internal.h" | 12 | #include "internal.h" |
13 | #include "sleep.h" | 13 | #include "sleep.h" |
14 | 14 | ||
15 | /* | ||
16 | * We didn't lock acpi_device_lock in the file, because it invokes oops in | ||
17 | * suspend/resume and isn't really required as this is called in S-state. At | ||
18 | * that time, there is no device hotplug | ||
19 | **/ | ||
15 | #define _COMPONENT ACPI_SYSTEM_COMPONENT | 20 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
16 | ACPI_MODULE_NAME("wakeup_devices") | 21 | ACPI_MODULE_NAME("wakeup_devices") |
17 | 22 | ||
18 | extern struct list_head acpi_wakeup_device_list; | ||
19 | extern spinlock_t acpi_device_lock; | ||
20 | |||
21 | /** | 23 | /** |
22 | * acpi_enable_wakeup_device_prep - prepare wakeup devices | 24 | * acpi_enable_wakeup_device_prep - prepare wakeup devices |
23 | * @sleep_state: ACPI state | 25 | * @sleep_state: ACPI state |
@@ -29,7 +31,6 @@ void acpi_enable_wakeup_device_prep(u8 sleep_state) | |||
29 | { | 31 | { |
30 | struct list_head *node, *next; | 32 | struct list_head *node, *next; |
31 | 33 | ||
32 | spin_lock(&acpi_device_lock); | ||
33 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 34 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
34 | struct acpi_device *dev = container_of(node, | 35 | struct acpi_device *dev = container_of(node, |
35 | struct acpi_device, | 36 | struct acpi_device, |
@@ -40,11 +41,8 @@ void acpi_enable_wakeup_device_prep(u8 sleep_state) | |||
40 | (sleep_state > (u32) dev->wakeup.sleep_state)) | 41 | (sleep_state > (u32) dev->wakeup.sleep_state)) |
41 | continue; | 42 | continue; |
42 | 43 | ||
43 | spin_unlock(&acpi_device_lock); | ||
44 | acpi_enable_wakeup_device_power(dev, sleep_state); | 44 | acpi_enable_wakeup_device_power(dev, sleep_state); |
45 | spin_lock(&acpi_device_lock); | ||
46 | } | 45 | } |
47 | spin_unlock(&acpi_device_lock); | ||
48 | } | 46 | } |
49 | 47 | ||
50 | /** | 48 | /** |
@@ -60,7 +58,6 @@ void acpi_enable_wakeup_device(u8 sleep_state) | |||
60 | * Caution: this routine must be invoked when interrupt is disabled | 58 | * Caution: this routine must be invoked when interrupt is disabled |
61 | * Refer ACPI2.0: P212 | 59 | * Refer ACPI2.0: P212 |
62 | */ | 60 | */ |
63 | spin_lock(&acpi_device_lock); | ||
64 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 61 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
65 | struct acpi_device *dev = | 62 | struct acpi_device *dev = |
66 | container_of(node, struct acpi_device, wakeup_list); | 63 | container_of(node, struct acpi_device, wakeup_list); |
@@ -74,22 +71,17 @@ void acpi_enable_wakeup_device(u8 sleep_state) | |||
74 | if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) | 71 | if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) |
75 | || sleep_state > (u32) dev->wakeup.sleep_state) { | 72 | || sleep_state > (u32) dev->wakeup.sleep_state) { |
76 | if (dev->wakeup.flags.run_wake) { | 73 | if (dev->wakeup.flags.run_wake) { |
77 | spin_unlock(&acpi_device_lock); | ||
78 | /* set_gpe_type will disable GPE, leave it like that */ | 74 | /* set_gpe_type will disable GPE, leave it like that */ |
79 | acpi_set_gpe_type(dev->wakeup.gpe_device, | 75 | acpi_set_gpe_type(dev->wakeup.gpe_device, |
80 | dev->wakeup.gpe_number, | 76 | dev->wakeup.gpe_number, |
81 | ACPI_GPE_TYPE_RUNTIME); | 77 | ACPI_GPE_TYPE_RUNTIME); |
82 | spin_lock(&acpi_device_lock); | ||
83 | } | 78 | } |
84 | continue; | 79 | continue; |
85 | } | 80 | } |
86 | spin_unlock(&acpi_device_lock); | ||
87 | if (!dev->wakeup.flags.run_wake) | 81 | if (!dev->wakeup.flags.run_wake) |
88 | acpi_enable_gpe(dev->wakeup.gpe_device, | 82 | acpi_enable_gpe(dev->wakeup.gpe_device, |
89 | dev->wakeup.gpe_number); | 83 | dev->wakeup.gpe_number); |
90 | spin_lock(&acpi_device_lock); | ||
91 | } | 84 | } |
92 | spin_unlock(&acpi_device_lock); | ||
93 | } | 85 | } |
94 | 86 | ||
95 | /** | 87 | /** |
@@ -101,7 +93,6 @@ void acpi_disable_wakeup_device(u8 sleep_state) | |||
101 | { | 93 | { |
102 | struct list_head *node, *next; | 94 | struct list_head *node, *next; |
103 | 95 | ||
104 | spin_lock(&acpi_device_lock); | ||
105 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 96 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
106 | struct acpi_device *dev = | 97 | struct acpi_device *dev = |
107 | container_of(node, struct acpi_device, wakeup_list); | 98 | container_of(node, struct acpi_device, wakeup_list); |
@@ -112,19 +103,16 @@ void acpi_disable_wakeup_device(u8 sleep_state) | |||
112 | if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) | 103 | if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) |
113 | || sleep_state > (u32) dev->wakeup.sleep_state) { | 104 | || sleep_state > (u32) dev->wakeup.sleep_state) { |
114 | if (dev->wakeup.flags.run_wake) { | 105 | if (dev->wakeup.flags.run_wake) { |
115 | spin_unlock(&acpi_device_lock); | ||
116 | acpi_set_gpe_type(dev->wakeup.gpe_device, | 106 | acpi_set_gpe_type(dev->wakeup.gpe_device, |
117 | dev->wakeup.gpe_number, | 107 | dev->wakeup.gpe_number, |
118 | ACPI_GPE_TYPE_WAKE_RUN); | 108 | ACPI_GPE_TYPE_WAKE_RUN); |
119 | /* Re-enable it, since set_gpe_type will disable it */ | 109 | /* Re-enable it, since set_gpe_type will disable it */ |
120 | acpi_enable_gpe(dev->wakeup.gpe_device, | 110 | acpi_enable_gpe(dev->wakeup.gpe_device, |
121 | dev->wakeup.gpe_number); | 111 | dev->wakeup.gpe_number); |
122 | spin_lock(&acpi_device_lock); | ||
123 | } | 112 | } |
124 | continue; | 113 | continue; |
125 | } | 114 | } |
126 | 115 | ||
127 | spin_unlock(&acpi_device_lock); | ||
128 | acpi_disable_wakeup_device_power(dev); | 116 | acpi_disable_wakeup_device_power(dev); |
129 | /* Never disable run-wake GPE */ | 117 | /* Never disable run-wake GPE */ |
130 | if (!dev->wakeup.flags.run_wake) { | 118 | if (!dev->wakeup.flags.run_wake) { |
@@ -133,16 +121,14 @@ void acpi_disable_wakeup_device(u8 sleep_state) | |||
133 | acpi_clear_gpe(dev->wakeup.gpe_device, | 121 | acpi_clear_gpe(dev->wakeup.gpe_device, |
134 | dev->wakeup.gpe_number, ACPI_NOT_ISR); | 122 | dev->wakeup.gpe_number, ACPI_NOT_ISR); |
135 | } | 123 | } |
136 | spin_lock(&acpi_device_lock); | ||
137 | } | 124 | } |
138 | spin_unlock(&acpi_device_lock); | ||
139 | } | 125 | } |
140 | 126 | ||
141 | int __init acpi_wakeup_device_init(void) | 127 | int __init acpi_wakeup_device_init(void) |
142 | { | 128 | { |
143 | struct list_head *node, *next; | 129 | struct list_head *node, *next; |
144 | 130 | ||
145 | spin_lock(&acpi_device_lock); | 131 | mutex_lock(&acpi_device_lock); |
146 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 132 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
147 | struct acpi_device *dev = container_of(node, | 133 | struct acpi_device *dev = container_of(node, |
148 | struct acpi_device, | 134 | struct acpi_device, |
@@ -150,15 +136,13 @@ int __init acpi_wakeup_device_init(void) | |||
150 | /* In case user doesn't load button driver */ | 136 | /* In case user doesn't load button driver */ |
151 | if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled) | 137 | if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled) |
152 | continue; | 138 | continue; |
153 | spin_unlock(&acpi_device_lock); | ||
154 | acpi_set_gpe_type(dev->wakeup.gpe_device, | 139 | acpi_set_gpe_type(dev->wakeup.gpe_device, |
155 | dev->wakeup.gpe_number, | 140 | dev->wakeup.gpe_number, |
156 | ACPI_GPE_TYPE_WAKE_RUN); | 141 | ACPI_GPE_TYPE_WAKE_RUN); |
157 | acpi_enable_gpe(dev->wakeup.gpe_device, | 142 | acpi_enable_gpe(dev->wakeup.gpe_device, |
158 | dev->wakeup.gpe_number); | 143 | dev->wakeup.gpe_number); |
159 | dev->wakeup.state.enabled = 1; | 144 | dev->wakeup.state.enabled = 1; |
160 | spin_lock(&acpi_device_lock); | ||
161 | } | 145 | } |
162 | spin_unlock(&acpi_device_lock); | 146 | mutex_unlock(&acpi_device_lock); |
163 | return 0; | 147 | return 0; |
164 | } | 148 | } |