Commit a6d70980 authored by Stephen Hemminger's avatar Stephen Hemminger Committed by Linus Torvalds

[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: default avatarStephen Hemminger <shemminger@osdl.org>
Acked-by: default avatarIngo Molnar <mingo@elte.hu>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 3eb1b3a4
...@@ -213,10 +213,10 @@ static int software_resume(void) ...@@ -213,10 +213,10 @@ static int software_resume(void)
{ {
int error; int error;
down(&pm_sem); mutex_lock(&pm_mutex);
if (!swsusp_resume_device) { if (!swsusp_resume_device) {
if (!strlen(resume_file)) { if (!strlen(resume_file)) {
up(&pm_sem); mutex_unlock(&pm_mutex);
return -ENOENT; return -ENOENT;
} }
swsusp_resume_device = name_to_dev_t(resume_file); swsusp_resume_device = name_to_dev_t(resume_file);
...@@ -231,7 +231,7 @@ static int software_resume(void) ...@@ -231,7 +231,7 @@ static int software_resume(void)
* FIXME: If noresume is specified, we need to find the partition * FIXME: If noresume is specified, we need to find the partition
* and reset it back to normal swap space. * and reset it back to normal swap space.
*/ */
up(&pm_sem); mutex_unlock(&pm_mutex);
return 0; return 0;
} }
...@@ -275,7 +275,7 @@ static int software_resume(void) ...@@ -275,7 +275,7 @@ static int software_resume(void)
unprepare_processes(); unprepare_processes();
Done: Done:
/* For success case, the suspend path will release the lock */ /* For success case, the suspend path will release the lock */
up(&pm_sem); mutex_unlock(&pm_mutex);
pr_debug("PM: Resume from disk failed.\n"); pr_debug("PM: Resume from disk failed.\n");
return 0; return 0;
} }
...@@ -336,7 +336,7 @@ static ssize_t disk_store(struct subsystem * s, const char * buf, size_t n) ...@@ -336,7 +336,7 @@ static ssize_t disk_store(struct subsystem * s, const char * buf, size_t n)
p = memchr(buf, '\n', n); p = memchr(buf, '\n', n);
len = p ? p - buf : n; len = p ? p - buf : n;
down(&pm_sem); mutex_lock(&pm_mutex);
for (i = PM_DISK_FIRMWARE; i < PM_DISK_MAX; i++) { for (i = PM_DISK_FIRMWARE; i < PM_DISK_MAX; i++) {
if (!strncmp(buf, pm_disk_modes[i], len)) { if (!strncmp(buf, pm_disk_modes[i], len)) {
mode = i; mode = i;
...@@ -360,7 +360,7 @@ static ssize_t disk_store(struct subsystem * s, const char * buf, size_t n) ...@@ -360,7 +360,7 @@ static ssize_t disk_store(struct subsystem * s, const char * buf, size_t n)
pr_debug("PM: suspend-to-disk mode set to '%s'\n", pr_debug("PM: suspend-to-disk mode set to '%s'\n",
pm_disk_modes[mode]); pm_disk_modes[mode]);
up(&pm_sem); mutex_unlock(&pm_mutex);
return error ? error : n; return error ? error : n;
} }
...@@ -385,9 +385,9 @@ static ssize_t resume_store(struct subsystem *subsys, const char *buf, size_t n) ...@@ -385,9 +385,9 @@ static ssize_t resume_store(struct subsystem *subsys, const char *buf, size_t n)
if (maj != MAJOR(res) || min != MINOR(res)) if (maj != MAJOR(res) || min != MINOR(res))
goto out; goto out;
down(&pm_sem); mutex_lock(&pm_mutex);
swsusp_resume_device = res; swsusp_resume_device = res;
up(&pm_sem); mutex_unlock(&pm_mutex);
printk("Attempting manual resume\n"); printk("Attempting manual resume\n");
noresume = 0; noresume = 0;
software_resume(); software_resume();
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
/*This is just an arbitrary number */ /*This is just an arbitrary number */
#define FREE_PAGE_NUMBER (100) #define FREE_PAGE_NUMBER (100)
DECLARE_MUTEX(pm_sem); DEFINE_MUTEX(pm_mutex);
struct pm_ops *pm_ops; struct pm_ops *pm_ops;
suspend_disk_method_t pm_disk_mode = PM_DISK_SHUTDOWN; suspend_disk_method_t pm_disk_mode = PM_DISK_SHUTDOWN;
...@@ -37,9 +37,9 @@ suspend_disk_method_t pm_disk_mode = PM_DISK_SHUTDOWN; ...@@ -37,9 +37,9 @@ suspend_disk_method_t pm_disk_mode = PM_DISK_SHUTDOWN;
void pm_set_ops(struct pm_ops * ops) void pm_set_ops(struct pm_ops * ops)
{ {
down(&pm_sem); mutex_lock(&pm_mutex);
pm_ops = ops; pm_ops = ops;
up(&pm_sem); mutex_unlock(&pm_mutex);
} }
...@@ -183,7 +183,7 @@ static int enter_state(suspend_state_t state) ...@@ -183,7 +183,7 @@ static int enter_state(suspend_state_t state)
if (!valid_state(state)) if (!valid_state(state))
return -ENODEV; return -ENODEV;
if (down_trylock(&pm_sem)) if (!mutex_trylock(&pm_mutex))
return -EBUSY; return -EBUSY;
if (state == PM_SUSPEND_DISK) { if (state == PM_SUSPEND_DISK) {
...@@ -201,7 +201,7 @@ static int enter_state(suspend_state_t state) ...@@ -201,7 +201,7 @@ static int enter_state(suspend_state_t state)
pr_debug("PM: Finishing wakeup.\n"); pr_debug("PM: Finishing wakeup.\n");
suspend_finish(state); suspend_finish(state);
Unlock: Unlock:
up(&pm_sem); mutex_unlock(&pm_mutex);
return error; return error;
} }
......
...@@ -22,7 +22,9 @@ static inline int pm_suspend_disk(void) ...@@ -22,7 +22,9 @@ static inline int pm_suspend_disk(void)
return -EPERM; return -EPERM;
} }
#endif #endif
extern struct semaphore pm_sem;
extern struct mutex pm_mutex;
#define power_attr(_name) \ #define power_attr(_name) \
static struct subsys_attribute _name##_attr = { \ static struct subsys_attribute _name##_attr = { \
.attr = { \ .attr = { \
......
...@@ -79,10 +79,10 @@ static int snapshot_release(struct inode *inode, struct file *filp) ...@@ -79,10 +79,10 @@ static int snapshot_release(struct inode *inode, struct file *filp)
free_all_swap_pages(data->swap, data->bitmap); free_all_swap_pages(data->swap, data->bitmap);
free_bitmap(data->bitmap); free_bitmap(data->bitmap);
if (data->frozen) { if (data->frozen) {
down(&pm_sem); mutex_lock(&pm_mutex);
thaw_processes(); thaw_processes();
enable_nonboot_cpus(); enable_nonboot_cpus();
up(&pm_sem); mutex_unlock(&pm_mutex);
} }
atomic_inc(&device_available); atomic_inc(&device_available);
return 0; return 0;
...@@ -144,7 +144,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -144,7 +144,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
case SNAPSHOT_FREEZE: case SNAPSHOT_FREEZE:
if (data->frozen) if (data->frozen)
break; break;
down(&pm_sem); mutex_lock(&pm_mutex);
error = disable_nonboot_cpus(); error = disable_nonboot_cpus();
if (!error) { if (!error) {
error = freeze_processes(); error = freeze_processes();
...@@ -154,7 +154,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -154,7 +154,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
error = -EBUSY; error = -EBUSY;
} }
} }
up(&pm_sem); mutex_unlock(&pm_mutex);
if (!error) if (!error)
data->frozen = 1; data->frozen = 1;
break; break;
...@@ -162,10 +162,10 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -162,10 +162,10 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
case SNAPSHOT_UNFREEZE: case SNAPSHOT_UNFREEZE:
if (!data->frozen) if (!data->frozen)
break; break;
down(&pm_sem); mutex_lock(&pm_mutex);
thaw_processes(); thaw_processes();
enable_nonboot_cpus(); enable_nonboot_cpus();
up(&pm_sem); mutex_unlock(&pm_mutex);
data->frozen = 0; data->frozen = 0;
break; break;
...@@ -174,7 +174,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -174,7 +174,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
error = -EPERM; error = -EPERM;
break; break;
} }
down(&pm_sem); mutex_lock(&pm_mutex);
/* Free memory before shutting down devices. */ /* Free memory before shutting down devices. */
error = swsusp_shrink_memory(); error = swsusp_shrink_memory();
if (!error) { if (!error) {
...@@ -187,7 +187,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -187,7 +187,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
} }
resume_console(); resume_console();
} }
up(&pm_sem); mutex_unlock(&pm_mutex);
if (!error) if (!error)
error = put_user(in_suspend, (unsigned int __user *)arg); error = put_user(in_suspend, (unsigned int __user *)arg);
if (!error) if (!error)
...@@ -201,7 +201,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -201,7 +201,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
error = -EPERM; error = -EPERM;
break; break;
} }
down(&pm_sem); mutex_lock(&pm_mutex);
pm_prepare_console(); pm_prepare_console();
suspend_console(); suspend_console();
error = device_suspend(PMSG_PRETHAW); error = device_suspend(PMSG_PRETHAW);
...@@ -211,7 +211,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -211,7 +211,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
} }
resume_console(); resume_console();
pm_restore_console(); pm_restore_console();
up(&pm_sem); mutex_unlock(&pm_mutex);
break; break;
case SNAPSHOT_FREE: case SNAPSHOT_FREE:
...@@ -286,7 +286,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -286,7 +286,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
break; break;
} }
if (down_trylock(&pm_sem)) { if (!mutex_trylock(&pm_mutex)) {
error = -EBUSY; error = -EBUSY;
break; break;
} }
...@@ -314,7 +314,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -314,7 +314,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
pm_ops->finish(PM_SUSPEND_MEM); pm_ops->finish(PM_SUSPEND_MEM);
OutS3: OutS3:
up(&pm_sem); mutex_unlock(&pm_mutex);
break; break;
case SNAPSHOT_PMOPS: case SNAPSHOT_PMOPS:
......
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