[PATCH] swsusp: fix error handling and cleanups
authorPavel Machek <pavel@ucw.cz>
Sat, 3 Sep 2005 22:57:05 +0000 (15:57 -0700)
committerLinus Torvalds <torvalds@evo.osdl.org>
Mon, 5 Sep 2005 07:06:17 +0000 (00:06 -0700)
Drop printing during normal boot (when no image exists in swap), print
message when drivers fail, fix error paths and consolidate near-identical
functions in disk.c (and functions with just one statement).

Signed-off-by: Pavel Machek <pavel@suse.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
kernel/power/disk.c
kernel/power/swsusp.c

index 88beec6dcd112534dc59214d6925bf811933d4d5..2d8bf054d036810766352d66b2fb84ec16361717 100644 (file)
@@ -112,24 +112,12 @@ static inline void platform_finish(void)
        }
 }
 
-static void finish(void)
-{
-       device_resume();
-       platform_finish();
-       thaw_processes();
-       enable_nonboot_cpus();
-       pm_restore_console();
-}
-
-
 static int prepare_processes(void)
 {
        int error;
 
        pm_prepare_console();
-
        sys_sync();
-
        disable_nonboot_cpus();
 
        if (freeze_processes()) {
@@ -162,15 +150,6 @@ static void unprepare_processes(void)
        pm_restore_console();
 }
 
-static int prepare_devices(void)
-{
-       int error;
-
-       if ((error = device_suspend(PMSG_FREEZE)))
-               printk("Some devices failed to suspend\n");
-       return error;
-}
-
 /**
  *     pm_suspend_disk - The granpappy of power management.
  *
@@ -187,17 +166,14 @@ int pm_suspend_disk(void)
        error = prepare_processes();
        if (error)
                return error;
-       error = prepare_devices();
 
+       error = device_suspend(PMSG_FREEZE);
        if (error) {
+               printk("Some devices failed to suspend\n");
                unprepare_processes();
                return error;
        }
 
-       pr_debug("PM: Attempting to suspend to disk.\n");
-       if (pm_disk_mode == PM_DISK_FIRMWARE)
-               return pm_ops->enter(PM_SUSPEND_DISK);
-
        pr_debug("PM: snapshotting memory.\n");
        in_suspend = 1;
        if ((error = swsusp_suspend()))
@@ -208,11 +184,20 @@ int pm_suspend_disk(void)
                error = swsusp_write();
                if (!error)
                        power_down(pm_disk_mode);
+               else {
+               /* swsusp_write can not fail in device_resume,
+                  no need to do second device_resume */
+                       swsusp_free();
+                       unprepare_processes();
+                       return error;
+               }
        } else
                pr_debug("PM: Image restored successfully.\n");
+
        swsusp_free();
  Done:
-       finish();
+       device_resume();
+       unprepare_processes();
        return error;
 }
 
@@ -274,15 +259,17 @@ static int software_resume(void)
 
        pr_debug("PM: Preparing devices for restore.\n");
 
-       if ((error = prepare_devices()))
+       if ((error = device_suspend(PMSG_FREEZE))) {
+               printk("Some devices failed to suspend\n");
                goto Free;
+       }
 
        mb();
 
        pr_debug("PM: Restoring saved image.\n");
        swsusp_resume();
        pr_debug("PM: Restore failed, recovering.n");
-       finish();
+       device_resume();
  Free:
        swsusp_free();
  Cleanup:
index 1681e8a3fe514cc3956ce83178491b668392c45e..eaacd5cb58895438ac28013968651f0d1752c4c6 100644 (file)
@@ -530,7 +530,6 @@ static int write_pagedir(void)
  *     write_suspend_image - Write entire image and metadata.
  *
  */
-
 static int write_suspend_image(void)
 {
        int error;
@@ -1021,20 +1020,21 @@ int swsusp_suspend(void)
         * at resume time, and evil weirdness ensues.
         */
        if ((error = device_power_down(PMSG_FREEZE))) {
+               printk(KERN_ERR "Some devices failed to power down, aborting suspend\n");
                local_irq_enable();
                return error;
        }
 
        if ((error = swsusp_swap_check())) {
-               printk(KERN_ERR "swsusp: FATAL: cannot find swap device, try "
-                               "swapon -a!\n");
+               printk(KERN_ERR "swsusp: cannot find swap device, try swapon -a.\n");
+               device_power_up();
                local_irq_enable();
                return error;
        }
 
        save_processor_state();
        if ((error = swsusp_arch_suspend()))
-               printk("Error %d suspending\n", error);
+               printk(KERN_ERR "Error %d suspending\n", error);
        /* Restore control flow magically appears here */
        restore_processor_state();
        BUG_ON (nr_copy_pages_check != nr_copy_pages);
@@ -1314,7 +1314,8 @@ static const char * sanity_check(void)
        if (strcmp(swsusp_info.uts.machine,system_utsname.machine))
                return "machine";
 #if 0
-       if(swsusp_info.cpus != num_online_cpus())
+       /* We can't use number of online CPUs when we use hotplug to remove them ;-))) */
+       if (swsusp_info.cpus != num_possible_cpus())
                return "number of cpus";
 #endif
        return NULL;
@@ -1355,7 +1356,6 @@ static int check_sig(void)
                 */
                error = bio_write_page(0, &swsusp_header);
        } else { 
-               printk(KERN_ERR "swsusp: Suspend partition has wrong signature?\n");
                return -EINVAL;
        }
        if (!error)