btrfs: avoid redundant path slot assignment in btrfs_search_forward()
authorSun YangKai <sunk67188@gmail.com>
Tue, 11 Mar 2025 08:13:14 +0000 (16:13 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 18 Mar 2025 19:35:52 +0000 (20:35 +0100)
Move path slot assignment before the condition check to prevent
duplicate assignment. Previously, the slot was set both inside and after
the 'slot >= nritems' block with no change in its value, which is
unnecessary.

Signed-off-by: Sun YangKai <sunk67188@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.c

index 5322df012c29d9aec67da23b52eee9f664dd2f9f..a2e7979372ccd8fb56e53f438803ff36d6c11265 100644 (file)
@@ -4667,8 +4667,8 @@ find_next_key:
                 * we didn't find a candidate key in this node, walk forward
                 * and find another one
                 */
+               path->slots[level] = slot;
                if (slot >= nritems) {
-                       path->slots[level] = slot;
                        sret = btrfs_find_next_key(root, path, min_key, level,
                                                  min_trans);
                        if (sret == 0) {
@@ -4678,7 +4678,6 @@ find_next_key:
                                goto out;
                        }
                }
-               path->slots[level] = slot;
                if (level == path->lowest_level) {
                        ret = 0;
                        /* Save our key for returning back. */