udf: Fix off-by-one error when discarding preallocation
authorJan Kara <jack@suse.cz>
Mon, 23 Jan 2023 13:29:15 +0000 (14:29 +0100)
committerJan Kara <jack@suse.cz>
Thu, 26 Jan 2023 15:46:35 +0000 (16:46 +0100)
The condition determining whether the preallocation can be used had
an off-by-one error so we didn't discard preallocation when new
allocation was just following it. This can then confuse code in
inode_getblk().

CC: stable@vger.kernel.org
Fixes: 16d055656814 ("udf: Discard preallocation before extending file with a hole")
Signed-off-by: Jan Kara <jack@suse.cz>
fs/udf/inode.c

index 51deada..ee440d1 100644 (file)
@@ -361,7 +361,7 @@ static int udf_map_block(struct inode *inode, struct udf_map_rq *map)
         * Block beyond EOF and prealloc extents? Just discard preallocation
         * as it is not useful and complicates things.
         */
-       if (((loff_t)map->lblk) << inode->i_blkbits > iinfo->i_lenExtents)
+       if (((loff_t)map->lblk) << inode->i_blkbits >= iinfo->i_lenExtents)
                udf_discard_prealloc(inode);
        udf_clear_extent_cache(inode);
        err = inode_getblk(inode, map);