[PATCH 1/2] btrfs: get_inode_info(): check NULL info parameter early

Sun YangKai
2025-08-21T13:16:32Z

Move the NULL pointer check for the @info parameter to the beginning
of get_inode_info() function to avoid unnecessary operations when no
output is required.

This change provides two benefits:
1. Avoids allocating path and performing tree lookups when @info is NULL
2. Simplifies the control flow by eliminating the redundant check
before writing output

The functional behavior remains unchanged except for the performance
improvement when called with NULL info parameter.

Signed-off-by: Sun YangKai <sunk67188@gmail.com>
---
fs/btrfs/send.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 7664025a5af4..5010d17878f9 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -913,6 +913,9 @@ static int get_inode_info(struct btrfs_root *root, u64 ino,
struct btrfs_inode_item *ii;
struct btrfs_key key;

+ if (!info)
+ return 0;
+
path = alloc_path_for_send();
if (!path)
return -ENOMEM;
@@ -927,9 +930,6 @@ static int get_inode_info(struct btrfs_root *root, u64 ino,
goto out;
}

- if (!info)
- goto out;
-
ii = btrfs_item_ptr(path->nodes[0], path->slots[0],
struct btrfs_inode_item);
info->size = btrfs_inode_size(path->nodes[0], ii);
--
2.50.1