Skip to content

Commit 316fb1b

Browse files
robbieko-aikdave
authored andcommitted
btrfs: fix incorrect return value after changing leaf in lookup_extent_data_ref()
After commit 1618aa3 ("btrfs: simplify return variables in lookup_extent_data_ref()"), the err and ret variables were merged into a single ret variable. However, when btrfs_next_leaf() returns 0 (success), ret is overwritten from -ENOENT to 0. If the first key in the next leaf does not match (different objectid or type), the function returns 0 instead of -ENOENT, making the caller believe the lookup succeeded when it did not. This can lead to operations on the wrong extent tree item, potentially causing extent tree corruption. Fix this by returning -ENOENT directly when the key does not match, instead of relying on the ret variable. Fixes: 1618aa3 ("btrfs: simplify return variables in lookup_extent_data_ref()") CC: stable@vger.kernel.org # 6.12+ Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: robbieko <robbieko@synology.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 1c37d89 commit 316fb1b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,
495495
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
496496
if (key.objectid != bytenr ||
497497
key.type != BTRFS_EXTENT_DATA_REF_KEY)
498-
return ret;
498+
return -ENOENT;
499499

500500
ref = btrfs_item_ptr(leaf, path->slots[0],
501501
struct btrfs_extent_data_ref);

0 commit comments

Comments
 (0)