mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-03 07:38:10 +00:00
[PATCH] swsusp: Fix alloc_pagedir
Get rid of the FIXME in kernel/power/snapshot.c#alloc_pagedir() and simplify the functions called by it. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Pavel Machek <pavel@suse.cz> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
f6143aa60e
commit
cd560bb2f9
1 changed files with 17 additions and 15 deletions
|
@ -316,12 +316,12 @@ static void free_pagedir(struct pbe *pblist, int clear_nosave_free)
|
||||||
* fill_pb_page - Create a list of PBEs on a given memory page
|
* fill_pb_page - Create a list of PBEs on a given memory page
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline void fill_pb_page(struct pbe *pbpage)
|
static inline void fill_pb_page(struct pbe *pbpage, unsigned int n)
|
||||||
{
|
{
|
||||||
struct pbe *p;
|
struct pbe *p;
|
||||||
|
|
||||||
p = pbpage;
|
p = pbpage;
|
||||||
pbpage += PB_PAGE_SKIP;
|
pbpage += n - 1;
|
||||||
do
|
do
|
||||||
p->next = p + 1;
|
p->next = p + 1;
|
||||||
while (++p < pbpage);
|
while (++p < pbpage);
|
||||||
|
@ -330,24 +330,26 @@ static inline void fill_pb_page(struct pbe *pbpage)
|
||||||
/**
|
/**
|
||||||
* create_pbe_list - Create a list of PBEs on top of a given chain
|
* create_pbe_list - Create a list of PBEs on top of a given chain
|
||||||
* of memory pages allocated with alloc_pagedir()
|
* of memory pages allocated with alloc_pagedir()
|
||||||
|
*
|
||||||
|
* This function assumes that pages allocated by alloc_image_page() will
|
||||||
|
* always be zeroed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline void create_pbe_list(struct pbe *pblist, unsigned int nr_pages)
|
static inline void create_pbe_list(struct pbe *pblist, unsigned int nr_pages)
|
||||||
{
|
{
|
||||||
struct pbe *pbpage, *p;
|
struct pbe *pbpage;
|
||||||
unsigned int num = PBES_PER_PAGE;
|
unsigned int num = PBES_PER_PAGE;
|
||||||
|
|
||||||
for_each_pb_page (pbpage, pblist) {
|
for_each_pb_page (pbpage, pblist) {
|
||||||
if (num >= nr_pages)
|
if (num >= nr_pages)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
fill_pb_page(pbpage);
|
fill_pb_page(pbpage, PBES_PER_PAGE);
|
||||||
num += PBES_PER_PAGE;
|
num += PBES_PER_PAGE;
|
||||||
}
|
}
|
||||||
if (pbpage) {
|
if (pbpage) {
|
||||||
for (num -= PBES_PER_PAGE - 1, p = pbpage; num < nr_pages; p++, num++)
|
num -= PBES_PER_PAGE;
|
||||||
p->next = p + 1;
|
fill_pb_page(pbpage, nr_pages - num);
|
||||||
p->next = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,17 +376,17 @@ static struct pbe *alloc_pagedir(unsigned int nr_pages, gfp_t gfp_mask,
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pblist = alloc_image_page(gfp_mask, safe_needed);
|
pblist = alloc_image_page(gfp_mask, safe_needed);
|
||||||
/* FIXME: rewrite this ugly loop */
|
pbe = pblist;
|
||||||
for (pbe = pblist, num = PBES_PER_PAGE; pbe && num < nr_pages;
|
for (num = PBES_PER_PAGE; num < nr_pages; num += PBES_PER_PAGE) {
|
||||||
pbe = pbe->next, num += PBES_PER_PAGE) {
|
if (!pbe) {
|
||||||
|
free_pagedir(pblist, 1);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
pbe += PB_PAGE_SKIP;
|
pbe += PB_PAGE_SKIP;
|
||||||
pbe->next = alloc_image_page(gfp_mask, safe_needed);
|
pbe->next = alloc_image_page(gfp_mask, safe_needed);
|
||||||
|
pbe = pbe->next;
|
||||||
}
|
}
|
||||||
if (!pbe) { /* get_zeroed_page() failed */
|
create_pbe_list(pblist, nr_pages);
|
||||||
free_pagedir(pblist, 1);
|
|
||||||
pblist = NULL;
|
|
||||||
} else
|
|
||||||
create_pbe_list(pblist, nr_pages);
|
|
||||||
return pblist;
|
return pblist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue