Skip to content

Commit

Permalink
vmalloc: clean up page array indexing
Browse files Browse the repository at this point in the history
The page array is repeatedly indexed both in vunmap and vmalloc_area_node().
Add a temporary variable to make it easier to read (and easier to patch
later).

Signed-off-by: Christoph Lameter <clameter@sgi.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Christoph Lameter authored and Linus Torvalds committed Feb 5, 2008
1 parent 9e2779f commit bf53d6f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions mm/vmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,10 @@ static void __vunmap(const void *addr, int deallocate_pages)
int i;

for (i = 0; i < area->nr_pages; i++) {
BUG_ON(!area->pages[i]);
__free_page(area->pages[i]);
struct page *page = area->pages[i];

BUG_ON(!page);
__free_page(page);
}

if (area->flags & VM_VPAGES)
Expand Down Expand Up @@ -489,15 +491,19 @@ void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
}

for (i = 0; i < area->nr_pages; i++) {
struct page *page;

if (node < 0)
area->pages[i] = alloc_page(gfp_mask);
page = alloc_page(gfp_mask);
else
area->pages[i] = alloc_pages_node(node, gfp_mask, 0);
if (unlikely(!area->pages[i])) {
page = alloc_pages_node(node, gfp_mask, 0);

if (unlikely(!page)) {
/* Successfully allocated i pages, free them in __vunmap() */
area->nr_pages = i;
goto fail;
}
area->pages[i] = page;
}

if (map_vm_area(area, prot, &pages))
Expand Down

0 comments on commit bf53d6f

Please sign in to comment.