Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Btrfs: handle no memory properly in prepare_pages

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>

authored by

Josef Bacik and committed by
Chris Mason
7adf5dfb ad0397a7

+6 -2
+6 -2
fs/btrfs/file.c
··· 792 792 for (i = 0; i < num_pages; i++) { 793 793 pages[i] = grab_cache_page(inode->i_mapping, index + i); 794 794 if (!pages[i]) { 795 - err = -ENOMEM; 796 - BUG_ON(1); 795 + int c; 796 + for (c = i - 1; c >= 0; c--) { 797 + unlock_page(pages[c]); 798 + page_cache_release(pages[c]); 799 + } 800 + return -ENOMEM; 797 801 } 798 802 wait_on_page_writeback(pages[i]); 799 803 }