]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ext4: Correct large hole offset calcuation
authorAllison Henderson <achender@linux.vnet.ibm.com>
Mon, 22 Aug 2011 19:04:53 +0000 (15:04 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 22 Aug 2011 19:04:53 +0000 (15:04 -0400)
This bug was reported by Lukas Czerner while working on a
new patch to add discard support for loop devices using
punch hole.

The bug is happens because the data type for logical blocks is
not large enough to calculate the block offset for holes that are
very large.  This bug is resolved by casting the ext4_lblk_t
to an loff_t before calculating the byte offset of the block.

Reviewed-and-Tested-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Allison Henderson <achender@linux.vnet.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/extents.c

index 15c3aaaf65184574f6859b165c4ab3e05e706530..475ddf5efba6a21b025d4e7c58e430162feae1c9 100644 (file)
@@ -4184,8 +4184,8 @@ int ext4_ext_punch_hole(struct file *file, loff_t offset, loff_t length)
                EXT4_BLOCK_SIZE_BITS(sb);
        last_block = (offset + length) >> EXT4_BLOCK_SIZE_BITS(sb);
 
-       first_block_offset = first_block << EXT4_BLOCK_SIZE_BITS(sb);
-       last_block_offset = last_block << EXT4_BLOCK_SIZE_BITS(sb);
+       first_block_offset = ((loff_t)first_block) << EXT4_BLOCK_SIZE_BITS(sb);
+       last_block_offset = ((loff_t)last_block) << EXT4_BLOCK_SIZE_BITS(sb);
 
        first_page = (offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
        last_page = (offset + length) >> PAGE_CACHE_SHIFT;