Commit 99dc7d63 authored by Pavel Machek's avatar Pavel Machek Committed by Linus Torvalds

[PATCH] swsusp: fix error handling and cleanups

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: default avatarPavel Machek <pavel@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent dd5d666b
...@@ -112,24 +112,12 @@ static inline void platform_finish(void) ...@@ -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) static int prepare_processes(void)
{ {
int error; int error;
pm_prepare_console(); pm_prepare_console();
sys_sync(); sys_sync();
disable_nonboot_cpus(); disable_nonboot_cpus();
if (freeze_processes()) { if (freeze_processes()) {
...@@ -162,15 +150,6 @@ static void unprepare_processes(void) ...@@ -162,15 +150,6 @@ static void unprepare_processes(void)
pm_restore_console(); 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. * pm_suspend_disk - The granpappy of power management.
* *
...@@ -187,17 +166,14 @@ int pm_suspend_disk(void) ...@@ -187,17 +166,14 @@ int pm_suspend_disk(void)
error = prepare_processes(); error = prepare_processes();
if (error) if (error)
return error; return error;
error = prepare_devices();
error = device_suspend(PMSG_FREEZE);
if (error) { if (error) {
printk("Some devices failed to suspend\n");
unprepare_processes(); unprepare_processes();
return error; 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"); pr_debug("PM: snapshotting memory.\n");
in_suspend = 1; in_suspend = 1;
if ((error = swsusp_suspend())) if ((error = swsusp_suspend()))
...@@ -208,11 +184,20 @@ int pm_suspend_disk(void) ...@@ -208,11 +184,20 @@ int pm_suspend_disk(void)
error = swsusp_write(); error = swsusp_write();
if (!error) if (!error)
power_down(pm_disk_mode); 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 } else
pr_debug("PM: Image restored successfully.\n"); pr_debug("PM: Image restored successfully.\n");
swsusp_free(); swsusp_free();
Done: Done:
finish(); device_resume();
unprepare_processes();
return error; return error;
} }
...@@ -274,15 +259,17 @@ static int software_resume(void) ...@@ -274,15 +259,17 @@ static int software_resume(void)
pr_debug("PM: Preparing devices for restore.\n"); 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; goto Free;
}
mb(); mb();
pr_debug("PM: Restoring saved image.\n"); pr_debug("PM: Restoring saved image.\n");
swsusp_resume(); swsusp_resume();
pr_debug("PM: Restore failed, recovering.n"); pr_debug("PM: Restore failed, recovering.n");
finish(); device_resume();
Free: Free:
swsusp_free(); swsusp_free();
Cleanup: Cleanup:
......
...@@ -530,7 +530,6 @@ static int write_pagedir(void) ...@@ -530,7 +530,6 @@ static int write_pagedir(void)
* write_suspend_image - Write entire image and metadata. * write_suspend_image - Write entire image and metadata.
* *
*/ */
static int write_suspend_image(void) static int write_suspend_image(void)
{ {
int error; int error;
...@@ -1021,20 +1020,21 @@ int swsusp_suspend(void) ...@@ -1021,20 +1020,21 @@ int swsusp_suspend(void)
* at resume time, and evil weirdness ensues. * at resume time, and evil weirdness ensues.
*/ */
if ((error = device_power_down(PMSG_FREEZE))) { if ((error = device_power_down(PMSG_FREEZE))) {
printk(KERN_ERR "Some devices failed to power down, aborting suspend\n");
local_irq_enable(); local_irq_enable();
return error; return error;
} }
if ((error = swsusp_swap_check())) { if ((error = swsusp_swap_check())) {
printk(KERN_ERR "swsusp: FATAL: cannot find swap device, try " printk(KERN_ERR "swsusp: cannot find swap device, try swapon -a.\n");
"swapon -a!\n"); device_power_up();
local_irq_enable(); local_irq_enable();
return error; return error;
} }
save_processor_state(); save_processor_state();
if ((error = swsusp_arch_suspend())) 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 control flow magically appears here */
restore_processor_state(); restore_processor_state();
BUG_ON (nr_copy_pages_check != nr_copy_pages); BUG_ON (nr_copy_pages_check != nr_copy_pages);
...@@ -1314,7 +1314,8 @@ static const char * sanity_check(void) ...@@ -1314,7 +1314,8 @@ static const char * sanity_check(void)
if (strcmp(swsusp_info.uts.machine,system_utsname.machine)) if (strcmp(swsusp_info.uts.machine,system_utsname.machine))
return "machine"; return "machine";
#if 0 #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"; return "number of cpus";
#endif #endif
return NULL; return NULL;
...@@ -1355,7 +1356,6 @@ static int check_sig(void) ...@@ -1355,7 +1356,6 @@ static int check_sig(void)
*/ */
error = bio_write_page(0, &swsusp_header); error = bio_write_page(0, &swsusp_header);
} else { } else {
printk(KERN_ERR "swsusp: Suspend partition has wrong signature?\n");
return -EINVAL; return -EINVAL;
} }
if (!error) if (!error)
......
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