Skip to contentSkip to conversation

btrfs: fix page leaks after failure to lock page for delalloc

PATCH In review robbieko 3 participants 3 messages Jul 20, 2020 Btrfs file system

lore
Share & tools
lore

robbieko

author
#0 lore raw

PATCH 1/1 btrfs: fix page leaks after failure to lock page for delalloc

From: Robbie Ko <[email protected]>

When locking pages for delalloc, we check if it's dirty and mapping still matches, if it does not match, we will return -EAGAIN and release all pages.

---
 fs/btrfs/extent_io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/extent_io.c +2 -1
index 68c96057ad2d..22fc47f9c900 100644
@@ -1999,7 +1999,8 @@ static int __process_pages_contig(struct address_space *mapping,
 				if (!PageDirty(pages[i]) ||
 				    pages[i]->mapping != mapping) {
 					unlock_page(pages[i]);
-					put_page(pages[i]);
+					for (; i < ret; i++)
+						put_page(pages[i]);
 					err = -EAGAIN;
 					goto out;
 				}
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · robbieko

From: Robbie Ko <[email protected]>

When locking pages for delalloc, we check if it's dirty and mapping still matches, if it does not match, we will return -EAGAIN and release all pages.

Quoted 19 lines
---
 fs/btrfs/extent_io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/extent_io.c +2 -1
index 68c96057ad2d..22fc47f9c900 100644
@@ -1999,7 +1999,8 @@ static int __process_pages_contig(struct address_space *mapping,
 				if (!PageDirty(pages[i]) ||
 				    pages[i]->mapping != mapping) {
 					unlock_page(pages[i]);
-					put_page(pages[i]);
+					for (; i < ret; i++)
+						put_page(pages[i]);
 					err = -EAGAIN;
 					goto out;
 				}