diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2012-07-08 14:29:53 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2012-07-08 14:29:53 +0000 |
commit | b87977228a6f6a5a391c69fdfb2dc717d206ece4 (patch) | |
tree | 6350c1c555fd4be5f42b71d8c91787a686c80813 /sys/kern/subr_hibernate.c | |
parent | 37637f0c9a055baea192ecc1e13795605744ed96 (diff) |
Make hibernate_free() safe to be called even if hibernate areas
allocation failed
ok mlarkin
Diffstat (limited to 'sys/kern/subr_hibernate.c')
-rw-r--r-- | sys/kern/subr_hibernate.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/sys/kern/subr_hibernate.c b/sys/kern/subr_hibernate.c index 05afdbad235..23d1dba89b6 100644 --- a/sys/kern/subr_hibernate.c +++ b/sys/kern/subr_hibernate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_hibernate.c,v 1.37 2012/07/08 12:22:26 mlarkin Exp $ */ +/* $OpenBSD: subr_hibernate.c,v 1.38 2012/07/08 14:29:52 deraadt Exp $ */ /* * Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl> @@ -1852,17 +1852,30 @@ hibernate_suspend(void) } /* - * Free items allocated during hibernate + * Free items allocated by hibernate_suspend() */ void hibernate_free(void) { - uvm_pmr_free_piglet(global_piglet_va, 3*HIBERNATE_CHUNK_SIZE); + if (global_piglet_va) + uvm_pmr_free_piglet(global_piglet_va, + 3*HIBERNATE_CHUNK_SIZE); + + if (hibernate_copy_page) + pmap_kremove(hibernate_copy_page, PAGE_SIZE); + if (hibernate_temp_page) + pmap_kremove(hibernate_temp_page, PAGE_SIZE); - pmap_kremove(hibernate_copy_page, PAGE_SIZE); - pmap_kremove(hibernate_temp_page, PAGE_SIZE); pmap_update(pmap_kernel()); - km_free((void *)hibernate_copy_page, PAGE_SIZE, &kv_any, &kp_none); - km_free((void *)hibernate_temp_page, PAGE_SIZE, &kv_any, &kp_none); + if (hibernate_copy_page) + km_free((void *)hibernate_copy_page, PAGE_SIZE, + &kv_any, &kp_none); + if (hibernate_temp_page) + km_free((void *)hibernate_temp_page, PAGE_SIZE, + &kv_any, &kp_none); + + global_piglet_va = 0; + hibernate_copy_page = 0; + hibernate_temp_page = 0; } |