Skip to content

Commit

Permalink
Btrfs: handle no memory properly in prepare_pages
Browse files Browse the repository at this point in the history
Instead of doing a BUG_ON(1) in prepare_pages if grab_cache_page() fails, just
loop through the pages we've already grabbed and unlock and release them, then
return -ENOMEM like we should.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Josef Bacik authored and Chris Mason committed Jan 28, 2011
1 parent ad0397a commit 7adf5df
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@ static noinline int prepare_pages(struct btrfs_root *root, struct file *file,
for (i = 0; i < num_pages; i++) {
pages[i] = grab_cache_page(inode->i_mapping, index + i);
if (!pages[i]) {
err = -ENOMEM;
BUG_ON(1);
int c;
for (c = i - 1; c >= 0; c--) {
unlock_page(pages[c]);
page_cache_release(pages[c]);
}
return -ENOMEM;
}
wait_on_page_writeback(pages[i]);
}
Expand Down

0 comments on commit 7adf5df

Please sign in to comment.