PM / hibernate: Untangle power_down()
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 23 Feb 2017 23:25:28 +0000 (00:25 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 27 Feb 2017 14:09:28 +0000 (15:09 +0100)
The power_down() routine in the core hibernation code is not exactly
straightforward (to put it lightly), so clean it up to make it avoid
invoking itself recursively, among other things.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/hibernate.c

index b26dbc48c75b9fa9045fafeccde8b23e69b9ab2e..f251b4d32913eafc0d2ae839ca2e1cd036d5cf83 100644 (file)
@@ -608,6 +608,22 @@ static void power_down(void)
 {
 #ifdef CONFIG_SUSPEND
        int error;
+
+       if (hibernation_mode == HIBERNATION_SUSPEND) {
+               error = suspend_devices_and_enter(PM_SUSPEND_MEM);
+               if (error) {
+                       hibernation_mode = hibernation_ops ?
+                                               HIBERNATION_PLATFORM :
+                                               HIBERNATION_SHUTDOWN;
+               } else {
+                       /* Restore swap signature. */
+                       error = swsusp_unmark();
+                       if (error)
+                               pr_err("PM: Swap will be unusable! Try swapon -a.\n");
+
+                       return;
+               }
+       }
 #endif
 
        switch (hibernation_mode) {
@@ -620,25 +636,6 @@ static void power_down(void)
                if (pm_power_off)
                        kernel_power_off();
                break;
-#ifdef CONFIG_SUSPEND
-       case HIBERNATION_SUSPEND:
-               error = suspend_devices_and_enter(PM_SUSPEND_MEM);
-               if (error) {
-                       if (hibernation_ops)
-                               hibernation_mode = HIBERNATION_PLATFORM;
-                       else
-                               hibernation_mode = HIBERNATION_SHUTDOWN;
-                       power_down();
-               }
-               /*
-                * Restore swap signature.
-                */
-               error = swsusp_unmark();
-               if (error)
-                       printk(KERN_ERR "PM: Swap will be unusable! "
-                                       "Try swapon -a.\n");
-               return;
-#endif
        }
        kernel_halt();
        /*