freezer: clean up freeze_processes() failure path
[firefly-linux-kernel-4.4.55.git] / kernel / power / hibernate.c
index b4511b6d3ef93ef5e2d12a097c3a63fa058de423..ba2319ffc8601ed0a511893d2ab663321fa5952c 100644 (file)
@@ -55,6 +55,8 @@ enum {
 
 static int hibernation_mode = HIBERNATION_SHUTDOWN;
 
+static bool freezer_test_done;
+
 static const struct platform_hibernation_ops *hibernation_ops;
 
 /**
@@ -347,6 +349,17 @@ int hibernation_snapshot(int platform_mode)
        if (error)
                goto Close;
 
+       if (hibernation_test(TEST_FREEZER) ||
+               hibernation_testmode(HIBERNATION_TESTPROC)) {
+
+               /*
+                * Indicate to the caller that we are returning due to a
+                * successful freezer test.
+                */
+               freezer_test_done = true;
+               goto Close;
+       }
+
        error = dpm_prepare(PMSG_FREEZE);
        if (error)
                goto Complete_devices;
@@ -594,17 +607,6 @@ static void power_down(void)
        while(1);
 }
 
-static int prepare_processes(void)
-{
-       int error = 0;
-
-       if (freeze_processes()) {
-               error = -EBUSY;
-               thaw_processes();
-       }
-       return error;
-}
-
 /**
  * hibernate - Carry out system hibernation, including saving the image.
  */
@@ -637,19 +639,17 @@ int hibernate(void)
        sys_sync();
        printk("done.\n");
 
-       error = prepare_processes();
+       error = freeze_processes();
        if (error)
                goto Finish;
 
-       if (hibernation_test(TEST_FREEZER))
-               goto Thaw;
-
-       if (hibernation_testmode(HIBERNATION_TESTPROC))
-               goto Thaw;
-
        error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
        if (error)
                goto Thaw;
+       if (freezer_test_done) {
+               freezer_test_done = false;
+               goto Thaw;
+       }
 
        if (in_suspend) {
                unsigned int flags = 0;
@@ -800,7 +800,7 @@ static int software_resume(void)
                goto close_finish;
 
        pr_debug("PM: Preparing processes for restore.\n");
-       error = prepare_processes();
+       error = freeze_processes();
        if (error) {
                swsusp_close(FMODE_READ);
                goto Done;