]> git.baikalelectronics.ru Git - uboot.git/commitdiff
fs: btrfs: Fix wrong comparison in logical to physical mapping
authorMarek BehĂșn <marek.behun@nic.cz>
Wed, 4 Jul 2018 18:23:01 +0000 (20:23 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 20 Jul 2018 19:37:44 +0000 (15:37 -0400)
The comparison
  logical > item->logical + item->length
in btrfs_map_logical_to_physical is wrong and should be instead
  logical >= item->logical + item->length
For example, if
  item->logical = 4096
  item->length = 4096
and we are looking for logical = 8192, it is not part of item (item is
[4096, 8191]). But the comparison is false and we think we have found
the correct item, although we should be searing in the right subtree.

This fixes some bugs I encountered.

Signed-off-by: Marek Behun <marek.behun@nic.cz>
fs/btrfs/chunk-map.c

index beb6a4bb928e79819a529fb1c611a421bc7ae38b..0c9a659f8fffc1036d9b6673190ef0e6e9728dab 100644 (file)
@@ -78,7 +78,7 @@ u64 btrfs_map_logical_to_physical(u64 logical)
 
                if (item->logical > logical)
                        node = node->rb_left;
-               else if (logical > item->logical + item->length)
+               else if (logical >= item->logical + item->length)
                        node = node->rb_right;
                else
                        return item->physical + logical - item->logical;