Skip to content

Commit da8848a

Browse files
fdmananakdave
authored andcommitted
btrfs: simplify check for extent item overrun at lookup_inline_extent_backref()
At lookup_inline_extent_backref() we can simplify the check for an overrun of the extent item by making the while loop's condition to be "ptr < end" and then check after the loop if an overrun happened ("ptr > end"). This reduces indentation and makes the loop condition more clear. So move the check out of the loop and change the loop condition accordingly, while also adding the 'unlikely' tag to the check since it's not supposed to be triggered. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent eba444f commit da8848a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

fs/btrfs/extent-tree.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -883,17 +883,7 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
883883
needed = BTRFS_REF_TYPE_BLOCK;
884884

885885
ret = -ENOENT;
886-
while (1) {
887-
if (ptr >= end) {
888-
if (ptr > end) {
889-
ret = -EUCLEAN;
890-
btrfs_print_leaf(path->nodes[0]);
891-
btrfs_crit(fs_info,
892-
"overrun extent record at slot %d while looking for inline extent for root %llu owner %llu offset %llu parent %llu",
893-
path->slots[0], root_objectid, owner, offset, parent);
894-
}
895-
break;
896-
}
886+
while (ptr < end) {
897887
iref = (struct btrfs_extent_inline_ref *)ptr;
898888
type = btrfs_get_extent_inline_ref_type(leaf, iref, needed);
899889
if (type == BTRFS_REF_TYPE_INVALID) {
@@ -940,6 +930,16 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
940930
}
941931
ptr += btrfs_extent_inline_ref_size(type);
942932
}
933+
934+
if (unlikely(ptr > end)) {
935+
ret = -EUCLEAN;
936+
btrfs_print_leaf(path->nodes[0]);
937+
btrfs_crit(fs_info,
938+
"overrun extent record at slot %d while looking for inline extent for root %llu owner %llu offset %llu parent %llu",
939+
path->slots[0], root_objectid, owner, offset, parent);
940+
goto out;
941+
}
942+
943943
if (ret == -ENOENT && insert) {
944944
if (item_size + extra_size >=
945945
BTRFS_MAX_EXTENT_ITEM_SIZE(root)) {

0 commit comments

Comments
 (0)