]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ext4: simplify the mapping query logic in ext4_iomap_begin()
authorZhang Yi <yi.zhang@huawei.com>
Mon, 5 Jan 2026 01:45:21 +0000 (09:45 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 20 Jan 2026 03:28:30 +0000 (22:28 -0500)
In the write path mapping check of ext4_iomap_begin(), the return value
'ret' should never greater than orig_mlen. If 'ret' equals 'orig_mlen',
it can be returned directly without checking IOMAP_ATOMIC.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Link: https://patch.msgid.link/20260105014522.1937690-7-yi.zhang@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/inode.c

index f346302709b9b01df9e53cc3d2b36b6d2faa7a12..d914f612da1039a2ac9dbe929ea0cf24b51b5a93 100644 (file)
@@ -3812,17 +3812,19 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
                if (offset + length <= i_size_read(inode)) {
                        ret = ext4_map_blocks(NULL, inode, &map, 0);
                        /*
-                        * For atomic writes the entire requested length should
-                        * be mapped. For DAX we convert extents to initialized
-                        * ones before copying the data, otherwise we do it
-                        * after I/O so there's no need to call into
-                        * ext4_iomap_alloc().
+                        * For DAX we convert extents to initialized ones before
+                        * copying the data, otherwise we do it after I/O so
+                        * there's no need to call into ext4_iomap_alloc().
                         */
                        if ((map.m_flags & EXT4_MAP_MAPPED) ||
                            (!(flags & IOMAP_DAX) &&
                             (map.m_flags & EXT4_MAP_UNWRITTEN))) {
-                               if ((!(flags & IOMAP_ATOMIC) && ret > 0) ||
-                                  (flags & IOMAP_ATOMIC && ret >= orig_mlen))
+                               /*
+                                * For atomic writes the entire requested
+                                * length should be mapped.
+                                */
+                               if (ret == orig_mlen ||
+                                   (!(flags & IOMAP_ATOMIC) && ret > 0))
                                        goto out;
                        }
                        map.m_len = orig_mlen;