From: Allison Henderson Date: Mon, 22 Aug 2011 19:04:53 +0000 (-0400) Subject: ext4: Correct large hole offset calcuation X-Git-Tag: next-20110824~74^2~1 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=ae405042e38f4206ef99e9ffa048f4e5973d10f9;p=karo-tx-linux.git ext4: Correct large hole offset calcuation 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 Signed-off-by: Allison Henderson Signed-off-by: "Theodore Ts'o" --- diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 15c3aaaf6518..475ddf5efba6 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -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;