]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: remove unnecessary btrfs_key local variable in btrfs_search_forward()
authorSun YangKai <sunk67188@gmail.com>
Tue, 11 Mar 2025 08:13:13 +0000 (16:13 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 18 Mar 2025 19:35:52 +0000 (20:35 +0100)
The 'found_key' variable was only used to temporarily store the found key
before copying it to 'min_key' at the end of the function when returning
success.

Eliminate the 'found_key' variable, and directly store the key into
'min_key' at the exact loop exit points where ret=0 is set, maintaining
identical functionality.

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 4d02227e94989c801604e48de5fa524cd4473974..5322df012c29d9aec67da23b52eee9f664dd2f9f 100644 (file)
@@ -4607,7 +4607,6 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
                         u64 min_trans)
 {
        struct extent_buffer *cur;
-       struct btrfs_key found_key;
        int slot;
        int sret;
        u32 nritems;
@@ -4643,7 +4642,8 @@ again:
                                goto find_next_key;
                        ret = 0;
                        path->slots[level] = slot;
-                       btrfs_item_key_to_cpu(cur, &found_key, slot);
+                       /* Save our key for returning back. */
+                       btrfs_item_key_to_cpu(cur, min_key, slot);
                        goto out;
                }
                if (sret && slot > 0)
@@ -4678,11 +4678,11 @@ find_next_key:
                                goto out;
                        }
                }
-               /* save our key for returning back */
-               btrfs_node_key_to_cpu(cur, &found_key, slot);
                path->slots[level] = slot;
                if (level == path->lowest_level) {
                        ret = 0;
+                       /* Save our key for returning back. */
+                       btrfs_node_key_to_cpu(cur, min_key, slot);
                        goto out;
                }
                cur = btrfs_read_node_slot(cur, slot);
@@ -4699,10 +4699,8 @@ find_next_key:
        }
 out:
        path->keep_locks = keep_locks;
-       if (ret == 0) {
+       if (ret == 0)
                btrfs_unlock_up_safe(path, path->lowest_level + 1);
-               memcpy(min_key, &found_key, sizeof(found_key));
-       }
        return ret;
 }