From e10e9e4ba840b43697b57d9d5faeab87492d2b45 Mon Sep 17 00:00:00 2001 From: Jan Kara Date: Sun, 21 May 2017 22:34:23 -0400 Subject: [PATCH] ext4: fix off-by-in in loop termination in ext4_find_unwritten_pgoff() There is an off-by-one error in loop termination conditions in ext4_find_unwritten_pgoff() since 'end' may index a page beyond end of desired range if 'endoff' is page aligned. It doesn't have any visible effects but still it is good to fix it. Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Orabug: 27093425 (backport upstream commit 3f1d5bad3fae983da07be01cff2fde13293bb7b9) Signed-off-by: Shan Hai --- fs/ext4/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 9bda1f073058..c5bc4bb05c2d 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -402,7 +402,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode, endoff = (loff_t)(map->m_lblk + map->m_len) << blkbits; index = startoff >> PAGE_CACHE_SHIFT; - end = endoff >> PAGE_CACHE_SHIFT; + end = (endoff - 1) >> PAGE_CACHE_SHIFT; pagevec_init(&pvec, 0); do { -- 2.50.1