nommu: ramfs: don't leak pages when adding to page cache fails
authorJohannes Weiner <>
Fri, 13 Mar 2009 20:51:58 +0000 (13:51 -0700)
committerLinus Torvalds <>
Sat, 14 Mar 2009 18:57:22 +0000 (11:57 -0700)
When a ramfs nommu mapping is expanded, contiguous pages are allocated
and added to the pagecache.  The caller's reference is then passed on
by moving whole pagevecs to the file lru list.

If the page cache adding fails, make sure that the error path also
moves the pagevec contents which might still contain up to PAGEVEC_SIZE
successfully added pages, of which we would leak references otherwise.

Signed-off-by: Johannes Weiner <>
Cc: David Howells <>
Cc: Enrik Berkhan <>
Cc: Nick Piggin <>
Cc: Peter Zijlstra <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>

index 90d72bead55be2d3b49de34503209c0e2446db8c..5d7c7ececa64a3345eb9a2632a660e695a9a73cc 100644 (file)
@@ -129,6 +129,7 @@ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)
        return -EFBIG;
+       pagevec_lru_add_file(&lru_pvec);
        page_cache_release(pages + loop);
        for (loop++; loop < npages; loop++)
                __free_page(pages + loop);