]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: use BTRFS_PATH_AUTO_FREE in can_nocow_extent()
authorDavid Sterba <dsterba@suse.com>
Tue, 1 Apr 2025 23:18:09 +0000 (01:18 +0200)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:41 +0000 (14:30 +0200)
This is the trivial pattern for path auto free, initialize at the
beginning and free at the end with simple goto -> return conversions.

Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c

index 72beac7b9099aa6aaea81ea5f9fcf51fa0182402..8f47846698db297943744315db39759acd6ba23a 100644 (file)
@@ -7085,7 +7085,7 @@ noinline int can_nocow_extent(struct btrfs_inode *inode, u64 offset, u64 *len,
        struct btrfs_root *root = inode->root;
        struct btrfs_fs_info *fs_info = root->fs_info;
        struct can_nocow_file_extent_args nocow_args = { 0 };
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        int ret;
        struct extent_buffer *leaf;
        struct extent_io_tree *io_tree = &inode->io_tree;
@@ -7101,13 +7101,12 @@ noinline int can_nocow_extent(struct btrfs_inode *inode, u64 offset, u64 *len,
        ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(inode),
                                       offset, 0);
        if (ret < 0)
-               goto out;
+               return ret;
 
        if (ret == 1) {
                if (path->slots[0] == 0) {
-                       /* can't find the item, must cow */
-                       ret = 0;
-                       goto out;
+                       /* Can't find the item, must COW. */
+                       return 0;
                }
                path->slots[0]--;
        }
@@ -7116,17 +7115,17 @@ noinline int can_nocow_extent(struct btrfs_inode *inode, u64 offset, u64 *len,
        btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
        if (key.objectid != btrfs_ino(inode) ||
            key.type != BTRFS_EXTENT_DATA_KEY) {
-               /* not our file or wrong item type, must cow */
-               goto out;
+               /* Not our file or wrong item type, must COW. */
+               return 0;
        }
 
        if (key.offset > offset) {
-               /* Wrong offset, must cow */
-               goto out;
+               /* Wrong offset, must COW. */
+               return 0;
        }
 
        if (btrfs_file_extent_end(path) <= offset)
-               goto out;
+               return 0;
 
        fi = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item);
        found_type = btrfs_file_extent_type(leaf, fi);
@@ -7141,15 +7140,13 @@ noinline int can_nocow_extent(struct btrfs_inode *inode, u64 offset, u64 *len,
 
        if (ret != 1) {
                /* Treat errors as not being able to NOCOW. */
-               ret = 0;
-               goto out;
+               return 0;
        }
 
-       ret = 0;
        if (btrfs_extent_readonly(fs_info,
                                  nocow_args.file_extent.disk_bytenr +
                                  nocow_args.file_extent.offset))
-               goto out;
+               return 0;
 
        if (!(inode->flags & BTRFS_INODE_NODATACOW) &&
            found_type == BTRFS_FILE_EXTENT_PREALLOC) {
@@ -7158,20 +7155,16 @@ noinline int can_nocow_extent(struct btrfs_inode *inode, u64 offset, u64 *len,
                range_end = round_up(offset + nocow_args.file_extent.num_bytes,
                                     root->fs_info->sectorsize) - 1;
                ret = test_range_bit_exists(io_tree, offset, range_end, EXTENT_DELALLOC);
-               if (ret) {
-                       ret = -EAGAIN;
-                       goto out;
-               }
+               if (ret)
+                       return -EAGAIN;
        }
 
        if (file_extent)
                memcpy(file_extent, &nocow_args.file_extent, sizeof(*file_extent));
 
        *len = nocow_args.file_extent.num_bytes;
-       ret = 1;
-out:
-       btrfs_free_path(path);
-       return ret;
+
+       return 1;
 }
 
 /* The callers of this must take lock_extent() */