Skip to content

Commit

Permalink
NOMMU: Fix cleanup handling in ramfs_nommu_get_umapped_area()
Browse files Browse the repository at this point in the history
Fix cleanup handling in ramfs_nommu_get_umapped_area() by only freeing the
number of pages that find_get_pages() said it had returned (nr) rather than
attempting to free the number of pages we asked for (lpages) - thus avoiding
the situation whereby put_page() may be handed NULL pointers if
find_get_pages() returned fewer pages that were requested.

Also avoid a warning about nr being uninitialised and the need for an
if-statement in the cleanup path by using appropriate gotos.

Signed-off-by: David Howells <[email protected]>
  • Loading branch information
dhowells committed Jan 8, 2009
1 parent 9e42d0c commit 0e8f989
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions fs/ramfs/file-nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,31 +262,30 @@ unsigned long ramfs_nommu_get_unmapped_area(struct file *file,
ret = -ENOMEM;
pages = kzalloc(lpages * sizeof(struct page *), GFP_KERNEL);
if (!pages)
goto out;
goto out_free;

nr = find_get_pages(inode->i_mapping, pgoff, lpages, pages);
if (nr != lpages)
goto out; /* leave if some pages were missing */
goto out_free_pages; /* leave if some pages were missing */

/* check the pages for physical adjacency */
ptr = pages;
page = *ptr++;
page++;
for (loop = lpages; loop > 1; loop--)
if (*ptr++ != page++)
goto out;
goto out_free_pages;

/* okay - all conditions fulfilled */
ret = (unsigned long) page_address(pages[0]);

out:
if (pages) {
ptr = pages;
for (loop = lpages; loop > 0; loop--)
put_page(*ptr++);
kfree(pages);
}

out_free_pages:
ptr = pages;
for (loop = nr; loop > 0; loop--)
put_page(*ptr++);
out_free:
kfree(pages);
out:
return ret;
}

Expand Down

0 comments on commit 0e8f989

Please sign in to comment.