aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/power
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@osdl.org>2006-12-06 23:34:35 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-07 11:39:28 -0500
commita6d70980602e6f1869ebcdcbfaf55a0a5941583e (patch)
treeb7e9b5f457eb7fe91fbbdbe978a50493da862cf2 /kernel/power
parent3eb1b3a40722cbb46631db373af66d13d1e7ac81 (diff)
[PATCH] convert pm_sem to a mutex
The power management semaphore is only used as mutex, so convert it. [akpm@osdl.org: fix rotten bug] Signed-off-by: Stephen Hemminger <shemminger@osdl.org> Acked-by: Ingo Molnar <mingo@elte.hu> Acked-by: Pavel Machek <pavel@ucw.cz> Cc: "Rafael J. Wysocki" <rjw@sisk.pl> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/power')
-rw-r--r--kernel/power/disk.c16
-rw-r--r--kernel/power/main.c10
-rw-r--r--kernel/power/power.h4
-rw-r--r--kernel/power/user.c24
4 files changed, 28 insertions, 26 deletions
diff --git a/kernel/power/disk.c b/kernel/power/disk.c
index 53b3b57c0223..08d9e7aac0f8 100644
--- a/kernel/power/disk.c
+++ b/kernel/power/disk.c
@@ -213,10 +213,10 @@ static int software_resume(void)
213{ 213{
214 int error; 214 int error;
215 215
216 down(&pm_sem); 216 mutex_lock(&pm_mutex);
217 if (!swsusp_resume_device) { 217 if (!swsusp_resume_device) {
218 if (!strlen(resume_file)) { 218 if (!strlen(resume_file)) {
219 up(&pm_sem); 219 mutex_unlock(&pm_mutex);
220 return -ENOENT; 220 return -ENOENT;
221 } 221 }
222 swsusp_resume_device = name_to_dev_t(resume_file); 222 swsusp_resume_device = name_to_dev_t(resume_file);
@@ -231,7 +231,7 @@ static int software_resume(void)
231 * FIXME: If noresume is specified, we need to find the partition 231 * FIXME: If noresume is specified, we need to find the partition
232 * and reset it back to normal swap space. 232 * and reset it back to normal swap space.
233 */ 233 */
234 up(&pm_sem); 234 mutex_unlock(&pm_mutex);
235 return 0; 235 return 0;
236 } 236 }
237 237
@@ -275,7 +275,7 @@ static int software_resume(void)
275 unprepare_processes(); 275 unprepare_processes();
276 Done: 276 Done:
277 /* For success case, the suspend path will release the lock */ 277 /* For success case, the suspend path will release the lock */
278 up(&pm_sem); 278 mutex_unlock(&pm_mutex);
279 pr_debug("PM: Resume from disk failed.\n"); 279 pr_debug("PM: Resume from disk failed.\n");
280 return 0; 280 return 0;
281} 281}
@@ -336,7 +336,7 @@ static ssize_t disk_store(struct subsystem * s, const char * buf, size_t n)
336 p = memchr(buf, '\n', n); 336 p = memchr(buf, '\n', n);
337 len = p ? p - buf : n; 337 len = p ? p - buf : n;
338 338
339 down(&pm_sem); 339 mutex_lock(&pm_mutex);
340 for (i = PM_DISK_FIRMWARE; i < PM_DISK_MAX; i++) { 340 for (i = PM_DISK_FIRMWARE; i < PM_DISK_MAX; i++) {
341 if (!strncmp(buf, pm_disk_modes[i], len)) { 341 if (!strncmp(buf, pm_disk_modes[i], len)) {
342 mode = i; 342 mode = i;
@@ -360,7 +360,7 @@ static ssize_t disk_store(struct subsystem * s, const char * buf, size_t n)
360 360
361 pr_debug("PM: suspend-to-disk mode set to '%s'\n", 361 pr_debug("PM: suspend-to-disk mode set to '%s'\n",
362 pm_disk_modes[mode]); 362 pm_disk_modes[mode]);
363 up(&pm_sem); 363 mutex_unlock(&pm_mutex);
364 return error ? error : n; 364 return error ? error : n;
365} 365}
366 366
@@ -385,9 +385,9 @@ static ssize_t resume_store(struct subsystem *subsys, const char *buf, size_t n)
385 if (maj != MAJOR(res) || min != MINOR(res)) 385 if (maj != MAJOR(res) || min != MINOR(res))
386 goto out; 386 goto out;
387 387
388 down(&pm_sem); 388 mutex_lock(&pm_mutex);
389 swsusp_resume_device = res; 389 swsusp_resume_device = res;
390 up(&pm_sem); 390 mutex_unlock(&pm_mutex);
391 printk("Attempting manual resume\n"); 391 printk("Attempting manual resume\n");
392 noresume = 0; 392 noresume = 0;
393 software_resume(); 393 software_resume();
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 6096c71b182b..751157b7897e 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -25,7 +25,7 @@
25/*This is just an arbitrary number */ 25/*This is just an arbitrary number */
26#define FREE_PAGE_NUMBER (100) 26#define FREE_PAGE_NUMBER (100)
27 27
28DECLARE_MUTEX(pm_sem); 28DEFINE_MUTEX(pm_mutex);
29 29
30struct pm_ops *pm_ops; 30struct pm_ops *pm_ops;
31suspend_disk_method_t pm_disk_mode = PM_DISK_SHUTDOWN; 31suspend_disk_method_t pm_disk_mode = PM_DISK_SHUTDOWN;
@@ -37,9 +37,9 @@ suspend_disk_method_t pm_disk_mode = PM_DISK_SHUTDOWN;
37 37
38void pm_set_ops(struct pm_ops * ops) 38void pm_set_ops(struct pm_ops * ops)
39{ 39{
40 down(&pm_sem); 40 mutex_lock(&pm_mutex);
41 pm_ops = ops; 41 pm_ops = ops;
42 up(&pm_sem); 42 mutex_unlock(&pm_mutex);
43} 43}
44 44
45 45
@@ -183,7 +183,7 @@ static int enter_state(suspend_state_t state)
183 183
184 if (!valid_state(state)) 184 if (!valid_state(state))
185 return -ENODEV; 185 return -ENODEV;
186 if (down_trylock(&pm_sem)) 186 if (!mutex_trylock(&pm_mutex))
187 return -EBUSY; 187 return -EBUSY;
188 188
189 if (state == PM_SUSPEND_DISK) { 189 if (state == PM_SUSPEND_DISK) {
@@ -201,7 +201,7 @@ static int enter_state(suspend_state_t state)
201 pr_debug("PM: Finishing wakeup.\n"); 201 pr_debug("PM: Finishing wakeup.\n");
202 suspend_finish(state); 202 suspend_finish(state);
203 Unlock: 203 Unlock:
204 up(&pm_sem); 204 mutex_unlock(&pm_mutex);
205 return error; 205 return error;
206} 206}
207 207
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 3afa5dbe6bc5..eb461b816bf4 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -22,7 +22,9 @@ static inline int pm_suspend_disk(void)
22 return -EPERM; 22 return -EPERM;
23} 23}
24#endif 24#endif
25extern struct semaphore pm_sem; 25
26extern struct mutex pm_mutex;
27
26#define power_attr(_name) \ 28#define power_attr(_name) \
27static struct subsys_attribute _name##_attr = { \ 29static struct subsys_attribute _name##_attr = { \
28 .attr = { \ 30 .attr = { \
diff --git a/kernel/power/user.c b/kernel/power/user.c
index 26c66941c001..905dc269c3fc 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -79,10 +79,10 @@ static int snapshot_release(struct inode *inode, struct file *filp)
79 free_all_swap_pages(data->swap, data->bitmap); 79 free_all_swap_pages(data->swap, data->bitmap);
80 free_bitmap(data->bitmap); 80 free_bitmap(data->bitmap);
81 if (data->frozen) { 81 if (data->frozen) {
82 down(&pm_sem); 82 mutex_lock(&pm_mutex);
83 thaw_processes(); 83 thaw_processes();
84 enable_nonboot_cpus(); 84 enable_nonboot_cpus();
85 up(&pm_sem); 85 mutex_unlock(&pm_mutex);
86 } 86 }
87 atomic_inc(&device_available); 87 atomic_inc(&device_available);
88 return 0; 88 return 0;
@@ -144,7 +144,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
144 case SNAPSHOT_FREEZE: 144 case SNAPSHOT_FREEZE:
145 if (data->frozen) 145 if (data->frozen)
146 break; 146 break;
147 down(&pm_sem); 147 mutex_lock(&pm_mutex);
148 error = disable_nonboot_cpus(); 148 error = disable_nonboot_cpus();
149 if (!error) { 149 if (!error) {
150 error = freeze_processes(); 150 error = freeze_processes();
@@ -154,7 +154,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
154 error = -EBUSY; 154 error = -EBUSY;
155 } 155 }
156 } 156 }
157 up(&pm_sem); 157 mutex_unlock(&pm_mutex);
158 if (!error) 158 if (!error)
159 data->frozen = 1; 159 data->frozen = 1;
160 break; 160 break;
@@ -162,10 +162,10 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
162 case SNAPSHOT_UNFREEZE: 162 case SNAPSHOT_UNFREEZE:
163 if (!data->frozen) 163 if (!data->frozen)
164 break; 164 break;
165 down(&pm_sem); 165 mutex_lock(&pm_mutex);
166 thaw_processes(); 166 thaw_processes();
167 enable_nonboot_cpus(); 167 enable_nonboot_cpus();
168 up(&pm_sem); 168 mutex_unlock(&pm_mutex);
169 data->frozen = 0; 169 data->frozen = 0;
170 break; 170 break;
171 171
@@ -174,7 +174,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
174 error = -EPERM; 174 error = -EPERM;
175 break; 175 break;
176 } 176 }
177 down(&pm_sem); 177 mutex_lock(&pm_mutex);
178 /* Free memory before shutting down devices. */ 178 /* Free memory before shutting down devices. */
179 error = swsusp_shrink_memory(); 179 error = swsusp_shrink_memory();
180 if (!error) { 180 if (!error) {
@@ -187,7 +187,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
187 } 187 }
188 resume_console(); 188 resume_console();
189 } 189 }
190 up(&pm_sem); 190 mutex_unlock(&pm_mutex);
191 if (!error) 191 if (!error)
192 error = put_user(in_suspend, (unsigned int __user *)arg); 192 error = put_user(in_suspend, (unsigned int __user *)arg);
193 if (!error) 193 if (!error)
@@ -201,7 +201,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
201 error = -EPERM; 201 error = -EPERM;
202 break; 202 break;
203 } 203 }
204 down(&pm_sem); 204 mutex_lock(&pm_mutex);
205 pm_prepare_console(); 205 pm_prepare_console();
206 suspend_console(); 206 suspend_console();
207 error = device_suspend(PMSG_PRETHAW); 207 error = device_suspend(PMSG_PRETHAW);
@@ -211,7 +211,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
211 } 211 }
212 resume_console(); 212 resume_console();
213 pm_restore_console(); 213 pm_restore_console();
214 up(&pm_sem); 214 mutex_unlock(&pm_mutex);
215 break; 215 break;
216 216
217 case SNAPSHOT_FREE: 217 case SNAPSHOT_FREE:
@@ -286,7 +286,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
286 break; 286 break;
287 } 287 }
288 288
289 if (down_trylock(&pm_sem)) { 289 if (!mutex_trylock(&pm_mutex)) {
290 error = -EBUSY; 290 error = -EBUSY;
291 break; 291 break;
292 } 292 }
@@ -314,7 +314,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
314 pm_ops->finish(PM_SUSPEND_MEM); 314 pm_ops->finish(PM_SUSPEND_MEM);
315 315
316OutS3: 316OutS3:
317 up(&pm_sem); 317 mutex_unlock(&pm_mutex);
318 break; 318 break;
319 319
320 case SNAPSHOT_PMOPS: 320 case SNAPSHOT_PMOPS: