diff options
author | Pavel Machek <pavel@ucw.cz> | 2005-09-03 18:57:05 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@evo.osdl.org> | 2005-09-05 03:06:17 -0400 |
commit | 99dc7d63e0dcb457580241055b2a39d011309db8 (patch) | |
tree | 3be63831f5fa823ef7e5c99339e9a71c29d3ad08 /kernel | |
parent | dd5d666b7995e542b7f81a4bb1c7ad634f4f6c51 (diff) |
[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: Pavel Machek <pavel@suse.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/power/disk.c | 45 | ||||
-rw-r--r-- | kernel/power/swsusp.c | 12 |
2 files changed, 22 insertions, 35 deletions
diff --git a/kernel/power/disk.c b/kernel/power/disk.c index 88beec6dcd11..2d8bf054d036 100644 --- a/kernel/power/disk.c +++ b/kernel/power/disk.c | |||
@@ -112,24 +112,12 @@ static inline void platform_finish(void) | |||
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | static void finish(void) | ||
116 | { | ||
117 | device_resume(); | ||
118 | platform_finish(); | ||
119 | thaw_processes(); | ||
120 | enable_nonboot_cpus(); | ||
121 | pm_restore_console(); | ||
122 | } | ||
123 | |||
124 | |||
125 | static int prepare_processes(void) | 115 | static int prepare_processes(void) |
126 | { | 116 | { |
127 | int error; | 117 | int error; |
128 | 118 | ||
129 | pm_prepare_console(); | 119 | pm_prepare_console(); |
130 | |||
131 | sys_sync(); | 120 | sys_sync(); |
132 | |||
133 | disable_nonboot_cpus(); | 121 | disable_nonboot_cpus(); |
134 | 122 | ||
135 | if (freeze_processes()) { | 123 | if (freeze_processes()) { |
@@ -162,15 +150,6 @@ static void unprepare_processes(void) | |||
162 | pm_restore_console(); | 150 | pm_restore_console(); |
163 | } | 151 | } |
164 | 152 | ||
165 | static int prepare_devices(void) | ||
166 | { | ||
167 | int error; | ||
168 | |||
169 | if ((error = device_suspend(PMSG_FREEZE))) | ||
170 | printk("Some devices failed to suspend\n"); | ||
171 | return error; | ||
172 | } | ||
173 | |||
174 | /** | 153 | /** |
175 | * pm_suspend_disk - The granpappy of power management. | 154 | * pm_suspend_disk - The granpappy of power management. |
176 | * | 155 | * |
@@ -187,17 +166,14 @@ int pm_suspend_disk(void) | |||
187 | error = prepare_processes(); | 166 | error = prepare_processes(); |
188 | if (error) | 167 | if (error) |
189 | return error; | 168 | return error; |
190 | error = prepare_devices(); | ||
191 | 169 | ||
170 | error = device_suspend(PMSG_FREEZE); | ||
192 | if (error) { | 171 | if (error) { |
172 | printk("Some devices failed to suspend\n"); | ||
193 | unprepare_processes(); | 173 | unprepare_processes(); |
194 | return error; | 174 | return error; |
195 | } | 175 | } |
196 | 176 | ||
197 | pr_debug("PM: Attempting to suspend to disk.\n"); | ||
198 | if (pm_disk_mode == PM_DISK_FIRMWARE) | ||
199 | return pm_ops->enter(PM_SUSPEND_DISK); | ||
200 | |||
201 | pr_debug("PM: snapshotting memory.\n"); | 177 | pr_debug("PM: snapshotting memory.\n"); |
202 | in_suspend = 1; | 178 | in_suspend = 1; |
203 | if ((error = swsusp_suspend())) | 179 | if ((error = swsusp_suspend())) |
@@ -208,11 +184,20 @@ int pm_suspend_disk(void) | |||
208 | error = swsusp_write(); | 184 | error = swsusp_write(); |
209 | if (!error) | 185 | if (!error) |
210 | power_down(pm_disk_mode); | 186 | power_down(pm_disk_mode); |
187 | else { | ||
188 | /* swsusp_write can not fail in device_resume, | ||
189 | no need to do second device_resume */ | ||
190 | swsusp_free(); | ||
191 | unprepare_processes(); | ||
192 | return error; | ||
193 | } | ||
211 | } else | 194 | } else |
212 | pr_debug("PM: Image restored successfully.\n"); | 195 | pr_debug("PM: Image restored successfully.\n"); |
196 | |||
213 | swsusp_free(); | 197 | swsusp_free(); |
214 | Done: | 198 | Done: |
215 | finish(); | 199 | device_resume(); |
200 | unprepare_processes(); | ||
216 | return error; | 201 | return error; |
217 | } | 202 | } |
218 | 203 | ||
@@ -274,15 +259,17 @@ static int software_resume(void) | |||
274 | 259 | ||
275 | pr_debug("PM: Preparing devices for restore.\n"); | 260 | pr_debug("PM: Preparing devices for restore.\n"); |
276 | 261 | ||
277 | if ((error = prepare_devices())) | 262 | if ((error = device_suspend(PMSG_FREEZE))) { |
263 | printk("Some devices failed to suspend\n"); | ||
278 | goto Free; | 264 | goto Free; |
265 | } | ||
279 | 266 | ||
280 | mb(); | 267 | mb(); |
281 | 268 | ||
282 | pr_debug("PM: Restoring saved image.\n"); | 269 | pr_debug("PM: Restoring saved image.\n"); |
283 | swsusp_resume(); | 270 | swsusp_resume(); |
284 | pr_debug("PM: Restore failed, recovering.n"); | 271 | pr_debug("PM: Restore failed, recovering.n"); |
285 | finish(); | 272 | device_resume(); |
286 | Free: | 273 | Free: |
287 | swsusp_free(); | 274 | swsusp_free(); |
288 | Cleanup: | 275 | Cleanup: |
diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c index 1681e8a3fe51..eaacd5cb5889 100644 --- a/kernel/power/swsusp.c +++ b/kernel/power/swsusp.c | |||
@@ -530,7 +530,6 @@ static int write_pagedir(void) | |||
530 | * write_suspend_image - Write entire image and metadata. | 530 | * write_suspend_image - Write entire image and metadata. |
531 | * | 531 | * |
532 | */ | 532 | */ |
533 | |||
534 | static int write_suspend_image(void) | 533 | static int write_suspend_image(void) |
535 | { | 534 | { |
536 | int error; | 535 | int error; |
@@ -1021,20 +1020,21 @@ int swsusp_suspend(void) | |||
1021 | * at resume time, and evil weirdness ensues. | 1020 | * at resume time, and evil weirdness ensues. |
1022 | */ | 1021 | */ |
1023 | if ((error = device_power_down(PMSG_FREEZE))) { | 1022 | if ((error = device_power_down(PMSG_FREEZE))) { |
1023 | printk(KERN_ERR "Some devices failed to power down, aborting suspend\n"); | ||
1024 | local_irq_enable(); | 1024 | local_irq_enable(); |
1025 | return error; | 1025 | return error; |
1026 | } | 1026 | } |
1027 | 1027 | ||
1028 | if ((error = swsusp_swap_check())) { | 1028 | if ((error = swsusp_swap_check())) { |
1029 | printk(KERN_ERR "swsusp: FATAL: cannot find swap device, try " | 1029 | printk(KERN_ERR "swsusp: cannot find swap device, try swapon -a.\n"); |
1030 | "swapon -a!\n"); | 1030 | device_power_up(); |
1031 | local_irq_enable(); | 1031 | local_irq_enable(); |
1032 | return error; | 1032 | return error; |
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | save_processor_state(); | 1035 | save_processor_state(); |
1036 | if ((error = swsusp_arch_suspend())) | 1036 | if ((error = swsusp_arch_suspend())) |
1037 | printk("Error %d suspending\n", error); | 1037 | printk(KERN_ERR "Error %d suspending\n", error); |
1038 | /* Restore control flow magically appears here */ | 1038 | /* Restore control flow magically appears here */ |
1039 | restore_processor_state(); | 1039 | restore_processor_state(); |
1040 | BUG_ON (nr_copy_pages_check != nr_copy_pages); | 1040 | BUG_ON (nr_copy_pages_check != nr_copy_pages); |
@@ -1314,7 +1314,8 @@ static const char * sanity_check(void) | |||
1314 | if (strcmp(swsusp_info.uts.machine,system_utsname.machine)) | 1314 | if (strcmp(swsusp_info.uts.machine,system_utsname.machine)) |
1315 | return "machine"; | 1315 | return "machine"; |
1316 | #if 0 | 1316 | #if 0 |
1317 | if(swsusp_info.cpus != num_online_cpus()) | 1317 | /* We can't use number of online CPUs when we use hotplug to remove them ;-))) */ |
1318 | if (swsusp_info.cpus != num_possible_cpus()) | ||
1318 | return "number of cpus"; | 1319 | return "number of cpus"; |
1319 | #endif | 1320 | #endif |
1320 | return NULL; | 1321 | return NULL; |
@@ -1355,7 +1356,6 @@ static int check_sig(void) | |||
1355 | */ | 1356 | */ |
1356 | error = bio_write_page(0, &swsusp_header); | 1357 | error = bio_write_page(0, &swsusp_header); |
1357 | } else { | 1358 | } else { |
1358 | printk(KERN_ERR "swsusp: Suspend partition has wrong signature?\n"); | ||
1359 | return -EINVAL; | 1359 | return -EINVAL; |
1360 | } | 1360 | } |
1361 | if (!error) | 1361 | if (!error) |