[PATCH 1/3] f2fs: clean up check condition for writting beyond EOF

From: Chao Yu
Date: Fri Nov 01 2019 - 05:54:11 EST


Clean up with below codes suggested by Eric:

__write_data_page()

unsigned nr_pages = DIV_ROUND_UP(i_size, PAGE_SIZE);

/*
* If the offset is out-of-range of file size,
* this page does not have to be written to disk.
*/
if (page->index >= nr_pages)
goto out;

Signed-off-by: Chao Yu <yuchao0@xxxxxxxxxx>
---
fs/f2fs/data.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index ba3bcf4c7889..ca7161e38d1f 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2204,6 +2204,7 @@ static int __write_data_page(struct page *page, bool *submitted,
const pgoff_t end_index = ((unsigned long long) i_size)
>> PAGE_SHIFT;
loff_t psize = (page->index + 1) << PAGE_SHIFT;
+ unsigned nr_pages = DIV_ROUND_UP(i_size, PAGE_SIZE);
unsigned offset = 0;
bool need_balance_fs = false;
int err = 0;
@@ -2248,8 +2249,7 @@ static int __write_data_page(struct page *page, bool *submitted,
* If the offset is out-of-range of file size,
* this page does not have to be written to disk.
*/
- offset = i_size & (PAGE_SIZE - 1);
- if ((page->index >= end_index + 1) || !offset)
+ if (page->index >= nr_pages)
goto out;

zero_user_segment(page, offset, PAGE_SIZE);
--
2.18.0.rc1