Skip to contentSkip to conversation

Btrfs: handle no memory properly in prepare_pages

PATCH New Josef Bacik 1 participant 1 message Jan 25, 2011 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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,

---
 fs/btrfs/file.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
fs/btrfs/file.c +6 -2
index f4eef63..416eee8 100644
@@ -790,8 +790,12 @@ again:
 	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]);
 	}
Signature · 1 line
1.6.6.1