[PATCH 14/16] squashfs: use folio_pos() and squashfs_block_bytes() in squashfs_read_folio()
From: Tal Zussman
Date: Tue Nov 03 2026 - 08:28:38 EST
Compute the block index and the EOF check from folio_pos(), and get
the number of bytes in the block from squashfs_block_bytes() rather
than open-coding it. Keep the block index and file_end in u64, which is
what squashfs_block_bytes() takes, so its comparison doesn't mix a
truncated index with an untruncated one.
No functional change.
Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/squashfs/file.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c
index abefe9c3cbaa..a6ca783c5e04 100644
--- a/fs/squashfs/file.c
+++ b/fs/squashfs/file.c
@@ -476,18 +476,15 @@ static int squashfs_read_folio(struct file *file, struct folio *folio)
{
struct inode *inode = folio->mapping->host;
struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
- int index = folio->index >> (msblk->block_log - PAGE_SHIFT);
- int file_end = i_size_read(inode) >> msblk->block_log;
- int expected = index == file_end ?
- (i_size_read(inode) & (msblk->block_size - 1)) :
- msblk->block_size;
+ u64 index = folio_pos(folio) >> msblk->block_log;
+ u64 file_end = i_size_read(inode) >> msblk->block_log;
+ int expected = squashfs_block_bytes(inode, index);
int res = 0;
TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
folio->index, squashfs_i(inode)->start);
- if (folio->index >= ((i_size_read(inode) + PAGE_SIZE - 1) >>
- PAGE_SHIFT))
+ if (folio_pos(folio) >= i_size_read(inode))
goto out;
if (index < file_end || squashfs_i(inode)->fragment_block ==
--
2.39.5