]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: fix to use per-inode maxbytes and cleanup
authorZhiguo Niu <zhiguo.niu@unisoc.com>
Fri, 26 Jul 2024 06:27:26 +0000 (14:27 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 15 Aug 2024 15:26:40 +0000 (15:26 +0000)
This is a supplement to commit 6d1451bf7f84 ("f2fs: fix to use per-inode maxbytes")
for some missed cases, also cleanup redundant code in f2fs_llseek.

Cc: Chengguang Xu <cgxu519@mykernel.net>
Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c
fs/f2fs/file.c
fs/f2fs/verity.c

index a2c3d39ddfed93a8addb1c71126c2caf70a3f7d2..e9570f4e0f212717d2fd75ead3554741b077d190 100644 (file)
@@ -1938,7 +1938,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 
        inode_lock_shared(inode);
 
-       maxbytes = max_file_blocks(inode) << F2FS_BLKSIZE_BITS;
+       maxbytes = F2FS_BLK_TO_BYTES(max_file_blocks(inode));
        if (start > maxbytes) {
                ret = -EFBIG;
                goto out;
@@ -2063,7 +2063,7 @@ out:
 static inline loff_t f2fs_readpage_limit(struct inode *inode)
 {
        if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode))
-               return inode->i_sb->s_maxbytes;
+               return F2FS_BLK_TO_BYTES(max_file_blocks(inode));
 
        return i_size_read(inode);
 }
index a7a3e6ac7f681825691a835b6dd8d61c447859a0..a2d466ca25799e8f1a9bed4964e3eeec7672aa61 100644 (file)
@@ -432,7 +432,7 @@ static bool __found_offset(struct address_space *mapping,
 static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence)
 {
        struct inode *inode = file->f_mapping->host;
-       loff_t maxbytes = inode->i_sb->s_maxbytes;
+       loff_t maxbytes = F2FS_BLK_TO_BYTES(max_file_blocks(inode));
        struct dnode_of_data dn;
        pgoff_t pgofs, end_offset;
        loff_t data_ofs = offset;
@@ -514,10 +514,7 @@ fail:
 static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence)
 {
        struct inode *inode = file->f_mapping->host;
-       loff_t maxbytes = inode->i_sb->s_maxbytes;
-
-       if (f2fs_compressed_file(inode))
-               maxbytes = max_file_blocks(inode) << F2FS_BLKSIZE_BITS;
+       loff_t maxbytes = F2FS_BLK_TO_BYTES(max_file_blocks(inode));
 
        switch (whence) {
        case SEEK_SET:
index f7bb0c54502c8d57981ffe9f41850b5c196e9f2c..83310b5e042289e7711dea24ee322880d328f4eb 100644 (file)
@@ -74,7 +74,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,
        struct address_space *mapping = inode->i_mapping;
        const struct address_space_operations *aops = mapping->a_ops;
 
-       if (pos + count > inode->i_sb->s_maxbytes)
+       if (pos + count > F2FS_BLK_TO_BYTES(max_file_blocks(inode)))
                return -EFBIG;
 
        while (count) {
@@ -237,7 +237,8 @@ static int f2fs_get_verity_descriptor(struct inode *inode, void *buf,
        pos = le64_to_cpu(dloc.pos);
 
        /* Get the descriptor */
-       if (pos + size < pos || pos + size > inode->i_sb->s_maxbytes ||
+       if (pos + size < pos ||
+           pos + size > F2FS_BLK_TO_BYTES(max_file_blocks(inode)) ||
            pos < f2fs_verity_metadata_pos(inode) || size > INT_MAX) {
                f2fs_warn(F2FS_I_SB(inode), "invalid verity xattr");
                f2fs_handle_error(F2FS_I_SB(inode),