From: Chunhai Guo Date: Mon, 10 Jul 2023 04:25:31 +0000 (+0800) Subject: erofs: avoid useless loops in z_erofs_pcluster_readmore() when reading beyond EOF X-Git-Tag: v6.6.7~2362^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=936aa701d82d397c2d1afcd18ce2c739471d978d;p=platform%2Fkernel%2Flinux-starfive.git erofs: avoid useless loops in z_erofs_pcluster_readmore() when reading beyond EOF z_erofs_pcluster_readmore() may take a long time to loop when the page offset is large enough, which is unnecessary should be prevented. For example, when the following case is encountered, it will loop 4691368 times, taking about 27 seconds: - offset = 19217289215 - inode_size = 1442672 Signed-off-by: Chunhai Guo Fixes: 386292919c25 ("erofs: introduce readmore decompression strategy") Reviewed-by: Gao Xiang Reviewed-by: Yue Hu Reviewed-by: Chao Yu Link: https://lore.kernel.org/r/20230710042531.28761-1-guochunhai@vivo.com Signed-off-by: Gao Xiang --- diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 5f1890e..d9a0763 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -1841,7 +1841,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f, } cur = map->m_la + map->m_llen - 1; - while (cur >= end) { + while ((cur >= end) && (cur < i_size_read(inode))) { pgoff_t index = cur >> PAGE_SHIFT; struct page *page;