Skip to content

Commit cbca7d5

Browse files
fdmananakdave
authored andcommitted
Btrfs: add missing error handling after doing leaf/node binary search
The function map_private_extent_buffer() can return an -EINVAL error, and it is called by generic_bin_search() which will return back the error. The btrfs_bin_search() function in turn calls generic_bin_search() and the key_search() function calls btrfs_bin_search(), so both can return the -EINVAL error coming from the map_private_extent_buffer() function. Some callers of these functions were ignoring that these functions can return an error, so fix them to deal with error return values. Reviewed-by: Nikolay Borisov <nborisov@suse.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 669e859 commit cbca7d5

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

fs/btrfs/ctree.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,6 +3020,8 @@ int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
30203020
*/
30213021
prev_cmp = -1;
30223022
ret = key_search(b, key, level, &prev_cmp, &slot);
3023+
if (ret < 0)
3024+
goto done;
30233025

30243026
if (level != 0) {
30253027
int dec = 0;
@@ -5171,6 +5173,10 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
51715173
nritems = btrfs_header_nritems(cur);
51725174
level = btrfs_header_level(cur);
51735175
sret = btrfs_bin_search(cur, min_key, level, &slot);
5176+
if (sret < 0) {
5177+
ret = sret;
5178+
goto out;
5179+
}
51745180

51755181
/* at the lowest level, we're done, setup the path and exit */
51765182
if (level == path->lowest_level) {

fs/btrfs/relocation.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,8 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
18061806
BUG_ON(level < lowest_level);
18071807

18081808
ret = btrfs_bin_search(parent, &key, level, &slot);
1809+
if (ret < 0)
1810+
break;
18091811
if (ret && slot > 0)
18101812
slot--;
18111813

@@ -2730,6 +2732,10 @@ static int do_relocation(struct btrfs_trans_handle *trans,
27302732
if (!lowest) {
27312733
ret = btrfs_bin_search(upper->eb, key,
27322734
upper->level, &slot);
2735+
if (ret < 0) {
2736+
err = ret;
2737+
goto next;
2738+
}
27332739
BUG_ON(ret);
27342740
bytenr = btrfs_node_blockptr(upper->eb, slot);
27352741
if (node->eb->start == bytenr)
@@ -2765,6 +2771,10 @@ static int do_relocation(struct btrfs_trans_handle *trans,
27652771
} else {
27662772
ret = btrfs_bin_search(upper->eb, key, upper->level,
27672773
&slot);
2774+
if (ret < 0) {
2775+
err = ret;
2776+
goto next;
2777+
}
27682778
BUG_ON(ret);
27692779
}
27702780

fs/btrfs/tree-log.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3767,6 +3767,8 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans,
37673767
found_key.type = 0;
37683768
ret = btrfs_bin_search(path->nodes[0], &found_key, 0,
37693769
&start_slot);
3770+
if (ret < 0)
3771+
break;
37703772

37713773
ret = btrfs_del_items(trans, log, path, start_slot,
37723774
path->slots[0] - start_slot + 1);

0 commit comments

Comments
 (0)