int btrfs_get_next_valid_item(struct btrfs_root *root, struct btrfs_key *key,
                              struct btrfs_path *path)
 {
-       while (1) {
+       if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
                int ret;
-               const int slot = path->slots[0];
-               const struct extent_buffer *leaf = path->nodes[0];
 
-               /* This is where we start walking the path. */
-               if (slot >= btrfs_header_nritems(leaf)) {
-                       /*
-                        * If we've reached the last slot in this leaf we need
-                        * to go to the next leaf and reset the path.
-                        */
-                       ret = btrfs_next_leaf(root, path);
-                       if (ret)
-                               return ret;
-                       continue;
-               }
-               /* Store the found, valid item in @key. */
-               btrfs_item_key_to_cpu(leaf, key, slot);
-               break;
+               ret = btrfs_next_leaf(root, path);
+               if (ret)
+                       return ret;
        }
+
+       btrfs_item_key_to_cpu(path->nodes[0], key, path->slots[0]);
        return 0;
 }