Skip to content

Commit ae6bd7f

Browse files
fdmananakdave
authored andcommitted
btrfs: fix off-by-one chunk length calculation at contains_pending_extent()
At contains_pending_extent() the value of the end offset of a chunk we found in the device's allocation state io tree is inclusive, so when we calculate the length we pass to the in_range() macro, we must sum 1 to the expression "physical_end - physical_offset". In practice the wrong calculation should be harmless as chunks sizes are never 1 byte and we should never have 1 byte ranges of unallocated space. Nevertheless fix the wrong calculation. Reported-by: Alex Lyakas <[email protected]> Link: https://lore.kernel.org/linux-btrfs/CAOcd+r30e-f4R-5x-S7sV22RJPe7+pgwherA6xqN2_qe7o4XTg@mail.gmail.com/ Fixes: 1c11b63 ("btrfs: replace pending/pinned chunks lists with io tree") CC: [email protected] # 6.1+ Reviewed-by: Josef Bacik <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent b20fe56 commit ae6bd7f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/btrfs/volumes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start,
14061406

14071407
if (in_range(physical_start, *start, len) ||
14081408
in_range(*start, physical_start,
1409-
physical_end - physical_start)) {
1409+
physical_end + 1 - physical_start)) {
14101410
*start = physical_end + 1;
14111411
return true;
14121412
}

0 commit comments

Comments
 (0)