diff mbox series

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

Message ID 20200720014209.11485-1-robbieko@synology.com (mailing list archive)
State New, archived
Headers show
Series btrfs: fix page leaks after failure to lock page for delalloc | expand

Commit Message

robbieko July 20, 2020, 1:42 a.m. UTC
From: Robbie Ko <robbieko@synology.com>

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.

Signed-off-by: Robbie Ko <robbieko@synology.com>
---
 fs/btrfs/extent_io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Nikolay Borisov July 20, 2020, 6:36 a.m. UTC | #1
On 20.07.20 г. 4:42 ч., robbieko wrote:
> From: Robbie Ko <robbieko@synology.com>
> 
> 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.
> 
> Signed-off-by: Robbie Ko <robbieko@synology.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  fs/btrfs/extent_io.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 68c96057ad2d..22fc47f9c900 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -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;
>  				}
>
David Sterba July 20, 2020, 3:34 p.m. UTC | #2
On Mon, Jul 20, 2020 at 09:42:09AM +0800, robbieko wrote:
> From: Robbie Ko <robbieko@synology.com>
> 
> 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.
> 
> Signed-off-by: Robbie Ko <robbieko@synology.com>

Nice catch, added to misc-next, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 68c96057ad2d..22fc47f9c900 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -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;
 				}