From: Michal Schmidt Date: Sat, 3 Sep 2005 22:57:02 +0000 (-0700) Subject: [PATCH] swsusp: simpler calculation of number of pages in PBE list X-Git-Tag: firefly_0821_release~41986 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=56057e1a128a9aab516350500e5b154e70577929;p=firefly-linux-kernel-4.4.55.git [PATCH] swsusp: simpler calculation of number of pages in PBE list The function calc_nr uses an iterative algorithm to calculate the number of pages needed for the image and the pagedir. Exactly the same result can be obtained with a one-line expression. Note that this was even proved correct ;-). Signed-off-by: Michal Schmidt Signed-off-by: Pavel Machek Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/kernel/power/swsusp.c b/kernel/power/swsusp.c index b041cea2e878..1681e8a3fe51 100644 --- a/kernel/power/swsusp.c +++ b/kernel/power/swsusp.c @@ -737,18 +737,7 @@ static void copy_data_pages(void) static int calc_nr(int nr_copy) { - int extra = 0; - int mod = !!(nr_copy % PBES_PER_PAGE); - int diff = (nr_copy / PBES_PER_PAGE) + mod; - - do { - extra += diff; - nr_copy += diff; - mod = !!(nr_copy % PBES_PER_PAGE); - diff = (nr_copy / PBES_PER_PAGE) + mod - extra; - } while (diff > 0); - - return nr_copy; + return nr_copy + (nr_copy+PBES_PER_PAGE-2)/(PBES_PER_PAGE-1); } /**