Skip to content

Commit b73f45a

Browse files
LiBaokun96tytso
authored andcommitted
ext4: remove page offset calculation in ext4_block_truncate_page()
For bs <= ps scenarios, calculating the offset within the block is sufficient. For bs > ps, an initial page offset calculation can lead to incorrect behavior. Thus this redundant calculation has been removed. Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Message-ID: <20251121090654.631996-3-libaokun@huaweicloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 5835b13 commit b73f45a

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

fs/ext4/inode.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4193,7 +4193,6 @@ static int ext4_block_zero_page_range(handle_t *handle,
41934193
static int ext4_block_truncate_page(handle_t *handle,
41944194
struct address_space *mapping, loff_t from)
41954195
{
4196-
unsigned offset = from & (PAGE_SIZE-1);
41974196
unsigned length;
41984197
unsigned blocksize;
41994198
struct inode *inode = mapping->host;
@@ -4202,8 +4201,8 @@ static int ext4_block_truncate_page(handle_t *handle,
42024201
if (IS_ENCRYPTED(inode) && !fscrypt_has_encryption_key(inode))
42034202
return 0;
42044203

4205-
blocksize = inode->i_sb->s_blocksize;
4206-
length = blocksize - (offset & (blocksize - 1));
4204+
blocksize = i_blocksize(inode);
4205+
length = blocksize - (from & (blocksize - 1));
42074206

42084207
return ext4_block_zero_page_range(handle, mapping, from, length);
42094208
}

0 commit comments

Comments
 (0)