[PATCH][Fix] swsusp: avoid problems if there are too many pages to save

From: Rafael J. Wysocki
Date: Mon Sep 26 2005 - 14:29:43 EST


Hi,

The following patch makes swsusp avoid problems during resume if there are too many
pages to save on suspend. It adds a constant that allows us to verify if we are going to
save too many pages and implements the check (this is done as early as we can tell that
the check will trigger, which is in swsusp_alloc()).

This is to replace swsusp-prevent-swsusp-from-failing-if-theres-too-many-pagedir-pages.patch

Please consider for applying.

Greetings,
Rafael


Signed-off-by: Rafael J. Wysocki <rjw@xxxxxxx>

Index: linux-2.6.14-rc2-git6/kernel/power/power.h
===================================================================
--- linux-2.6.14-rc2-git6.orig/kernel/power/power.h 2005-09-26 20:58:33.000000000 +0200
+++ linux-2.6.14-rc2-git6/kernel/power/power.h 2005-09-26 21:05:37.000000000 +0200
@@ -9,6 +9,9 @@
#define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
#endif

+#define MAX_PBES ((PAGE_SIZE - sizeof(struct new_utsname) \
+ - 4 - 3*sizeof(unsigned long) - sizeof(int) \
+ - sizeof(void *)) / sizeof(swp_entry_t))

struct swsusp_info {
struct new_utsname uts;
@@ -18,7 +21,7 @@
unsigned long image_pages;
unsigned long pagedir_pages;
suspend_pagedir_t * suspend_pagedir;
- swp_entry_t pagedir[768];
+ swp_entry_t pagedir[MAX_PBES];
} __attribute__((aligned(PAGE_SIZE)));


Index: linux-2.6.14-rc2-git6/kernel/power/swsusp.c
===================================================================
--- linux-2.6.14-rc2-git6.orig/kernel/power/swsusp.c 2005-09-26 20:59:30.000000000 +0200
+++ linux-2.6.14-rc2-git6/kernel/power/swsusp.c 2005-09-26 21:05:13.000000000 +0200
@@ -931,6 +931,10 @@
if (!enough_swap())
return -ENOSPC;

+ if (MAX_PBES < nr_copy_pages / PBES_PER_PAGE +
+ !!(nr_copy_pages % PBES_PER_PAGE))
+ return -ENOSPC;
+
if (!(pagedir_save = alloc_pagedir(nr_copy_pages))) {
printk(KERN_ERR "suspend: Allocating pagedir failed.\n");
return -ENOMEM;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/