From: Jack Qiu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: <linux-f2fs-devel@lists.sourceforge.net>
Subject: [f2fs-dev] [PATCH] f2fs: fix page leak in redirty_blocks
Date: Sat, 28 May 2022 17:35:03 +0800 [thread overview]
Message-ID: <20220528093503.2608388-1-jack.qiu@huawei.com> (raw)
When find_lock_page return error, page in [i, page_len) will leak.
Signed-off-by: Jack Qiu <jack.qiu@huawei.com>
---
fs/f2fs/file.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 100637b1adb3..0e8938c5918e 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3954,6 +3954,12 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)
struct page *page;
pgoff_t redirty_idx = page_idx;
int i, page_len = 0, ret = 0;
+ struct page **pages;
+
+ pages = f2fs_kvzalloc(F2FS_I_SB(inode),
+ sizeof(struct page *) * len, GFP_NOFS);
+ if (!pages)
+ return -ENOMEM;
page_cache_ra_unbounded(&ractl, len, 0);
@@ -3964,6 +3970,7 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)
break;
}
page_len++;
+ pages[i] = page;
}
for (i = 0; i < page_len; i++, redirty_idx++) {
@@ -3975,8 +3982,14 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)
set_page_dirty(page);
f2fs_put_page(page, 1);
f2fs_put_page(page, 0);
+ pages[i] = NULL;
}
+ /* put pages[i, page_len) when error happens */
+ for (; ret < 0 && i < page_len; i++)
+ f2fs_put_page(pages[i], 0);
+ kvfree(pages);
+
return ret;
}
--
2.31.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next reply other threads:[~2022-05-28 9:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-28 9:35 Jack Qiu via Linux-f2fs-devel [this message]
2022-05-29 6:58 ` [f2fs-dev] [PATCH] f2fs: fix page leak in redirty_blocks Chao Yu
2022-05-30 1:02 ` Jack Qiu via Linux-f2fs-devel
2022-05-30 12:02 ` Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220528093503.2608388-1-jack.qiu@huawei.com \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=jack.qiu@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).