swsusp: fix hibernation code ordering
[deliverable/linux.git] / kernel / power / main.c
index f6dda685e7e2b06bd0eb27631dd84dbf33e8c0ef..fc45ed22620f46c8a84341e51069892cab3e93fa 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/init.h>
-#include <linux/pm.h>
 #include <linux/console.h>
 #include <linux/cpu.h>
 #include <linux/resume-trace.h>
@@ -30,7 +29,6 @@
 DEFINE_MUTEX(pm_mutex);
 
 struct pm_ops *pm_ops;
-suspend_disk_method_t pm_disk_mode = PM_DISK_SHUTDOWN;
 
 /**
  *     pm_set_ops - Set the global power method table. 
@@ -41,10 +39,6 @@ void pm_set_ops(struct pm_ops * ops)
 {
        mutex_lock(&pm_mutex);
        pm_ops = ops;
-       if (ops && ops->pm_disk_mode != PM_DISK_INVALID) {
-               pm_disk_mode = ops->pm_disk_mode;
-       } else
-               pm_disk_mode = PM_DISK_SHUTDOWN;
        mutex_unlock(&pm_mutex);
 }
 
@@ -102,25 +96,31 @@ static int suspend_prepare(suspend_state_t state)
                }
        }
 
-       if (pm_ops->prepare) {
-               if ((error = pm_ops->prepare(state)))
+       if (pm_ops->set_target) {
+               error = pm_ops->set_target(state);
+               if (error)
                        goto Thaw;
        }
-
        suspend_console();
        error = device_suspend(PMSG_SUSPEND);
        if (error) {
                printk(KERN_ERR "Some devices failed to suspend\n");
-               goto Resume_devices;
+               goto Resume_console;
+       }
+       if (pm_ops->prepare) {
+               if ((error = pm_ops->prepare(state)))
+                       goto Resume_devices;
        }
+
        error = disable_nonboot_cpus();
        if (!error)
                return 0;
 
        enable_nonboot_cpus();
- Resume_devices:
        pm_finish(state);
+ Resume_devices:
        device_resume();
+ Resume_console:
        resume_console();
  Thaw:
        thaw_processes();
@@ -184,24 +184,12 @@ static void suspend_finish(suspend_state_t state)
 static const char * const pm_states[PM_SUSPEND_MAX] = {
        [PM_SUSPEND_STANDBY]    = "standby",
        [PM_SUSPEND_MEM]        = "mem",
-       [PM_SUSPEND_DISK]       = "disk",
 };
 
 static inline int valid_state(suspend_state_t state)
 {
-       /* Suspend-to-disk does not really need low-level support.
-        * It can work with shutdown/reboot if needed. If it isn't
-        * configured, then it cannot be supported.
-        */
-       if (state == PM_SUSPEND_DISK)
-#ifdef CONFIG_SOFTWARE_SUSPEND
-               return 1;
-#else
-               return 0;
-#endif
-
-       /* all other states need lowlevel support and need to be
-        * valid to the lowlevel implementation, no valid callback
+       /* All states need lowlevel support and need to be valid
+        * to the lowlevel implementation, no valid callback
         * implies that none are valid. */
        if (!pm_ops || !pm_ops->valid || !pm_ops->valid(state))
                return 0;
@@ -229,11 +217,6 @@ static int enter_state(suspend_state_t state)
        if (!mutex_trylock(&pm_mutex))
                return -EBUSY;
 
-       if (state == PM_SUSPEND_DISK) {
-               error = pm_suspend_disk();
-               goto Unlock;
-       }
-
        pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]);
        if ((error = suspend_prepare(state)))
                goto Unlock;
@@ -251,7 +234,7 @@ static int enter_state(suspend_state_t state)
 
 /**
  *     pm_suspend - Externally visible function for suspending system.
- *     @state:         Enumarted value of state to enter.
+ *     @state:         Enumerated value of state to enter.
  *
  *     Determine whether or not value is within range, get state 
  *     structure, and enter (above).
@@ -289,7 +272,13 @@ static ssize_t state_show(struct kset *kset, char *buf)
                if (pm_states[i] && valid_state(i))
                        s += sprintf(s,"%s ", pm_states[i]);
        }
-       s += sprintf(s,"\n");
+#ifdef CONFIG_SOFTWARE_SUSPEND
+       s += sprintf(s, "%s\n", "disk");
+#else
+       if (s != buf)
+               /* convert the last space to a newline */
+               *(s-1) = '\n';
+#endif
        return (s - buf);
 }
 
@@ -304,8 +293,14 @@ static ssize_t state_store(struct kset *kset, const char *buf, size_t n)
        p = memchr(buf, '\n', n);
        len = p ? p - buf : n;
 
+       /* First, check if we are requested to hibernate */
+       if (len == 4 && !strncmp(buf, "disk", len)) {
+               error = hibernate();
+               return error ? error : n;
+       }
+
        for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
-               if (*s && !strncmp(buf, *s, len))
+               if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
                        break;
        }
        if (state < PM_SUSPEND_MAX && *s)
This page took 0.04114 seconds and 5 git commands to generate.