summaryrefslogtreecommitdiff
path: root/fs/btrfs/ctree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r--fs/btrfs/ctree.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index d248d79932..7fae383f15 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -185,10 +185,20 @@ int btrfs_search_tree(const struct btrfs_root *root, struct btrfs_key *key,
p->slots[lvl] = slot;
p->nodes[lvl] = buf;
- if (lvl)
+ if (lvl) {
logical = buf->node.ptrs[slot].blockptr;
- else
+ } else {
+ /*
+ * The path might be invalid if:
+ * cur leaf max < searched value < next leaf min
+ *
+ * Jump to the next valid element if it exists.
+ */
+ if (slot >= buf->header.nritems)
+ if (btrfs_next_slot(p) < 0)
+ goto err;
break;
+ }
}
return 0;