btrfs: do more trivial BTRFS_PATH_AUTO_FREE conversions
authorDavid Sterba <dsterba@suse.com>
Tue, 1 Apr 2025 23:18:06 +0000 (01:18 +0200)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:41 +0000 (14:30 +0200)
The most trivial pattern for the auto freeing when the variable is
declared with the macro and the final btrfs_free_path() is removed.
There are almost none goto -> return conversions and there's no other
function cleanup.

Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/fiemap.c
fs/btrfs/file-item.c
fs/btrfs/file.c
fs/btrfs/free-space-cache.c
fs/btrfs/inode.c

index a38578c60f34e60ca1ea841a61dede352808b705..3eba00da9fc7a5a5e73a382d391c926514099171 100644 (file)
@@ -700,7 +700,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
        struct btrfs_block_group *block_group = caching_ctl->block_group;
        struct btrfs_fs_info *fs_info = block_group->fs_info;
        struct btrfs_root *extent_root;
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        struct extent_buffer *leaf;
        struct btrfs_key key;
        u64 total_found = 0;
@@ -827,7 +827,6 @@ next:
                                       block_group->start + block_group->length,
                                       NULL);
 out:
-       btrfs_free_path(path);
        return ret;
 }
 
index b80c07ad8c5e71b0e85a7e8ea29a0a2c031cf63c..7715e30508c575411a803992c1c5be562e5eb601 100644 (file)
@@ -634,7 +634,7 @@ static int extent_fiemap(struct btrfs_inode *inode,
        const u64 ino = btrfs_ino(inode);
        struct extent_state *cached_state = NULL;
        struct extent_state *delalloc_cached_state = NULL;
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        struct fiemap_cache cache = { 0 };
        struct btrfs_backref_share_check_ctx *backref_ctx;
        u64 last_extent_end = 0;
@@ -874,7 +874,6 @@ out:
        free_extent_state(delalloc_cached_state);
        kfree(cache.entries);
        btrfs_free_backref_share_ctx(backref_ctx);
-       btrfs_free_path(path);
        return ret;
 }
 
index 344b4db487a0c6208680eac035705d7e65ccc991..c191be6bcefbd21ac1ce9a2617a013a9f7bd0a2b 100644 (file)
@@ -1048,7 +1048,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
        struct btrfs_fs_info *fs_info = root->fs_info;
        struct btrfs_key file_key;
        struct btrfs_key found_key;
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        struct btrfs_csum_item *item;
        struct btrfs_csum_item *item_end;
        struct extent_buffer *leaf = NULL;
@@ -1259,7 +1259,6 @@ found:
                goto again;
        }
 out:
-       btrfs_free_path(path);
        return ret;
 }
 
index 48fc6561c33aa3d4087a3a42902454563cd0d2df..cbe98e8251623c8215e85b8958352806487f8392 100644 (file)
@@ -553,7 +553,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
 {
        struct btrfs_root *root = inode->root;
        struct extent_buffer *leaf;
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        struct btrfs_file_extent_item *fi;
        struct btrfs_ref ref = { 0 };
        struct btrfs_key key;
@@ -791,7 +791,6 @@ again:
                }
        }
 out:
-       btrfs_free_path(path);
        return ret;
 }
 
index 05e173311c1a92d4d7d359c5e91fff36700783a0..633dfe4ee93e8d5c6174ec6b9a53ee0752b4b3f2 100644 (file)
@@ -308,8 +308,9 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
        bool locked = false;
 
        if (block_group) {
-               struct btrfs_path *path = btrfs_alloc_path();
+               BTRFS_PATH_AUTO_FREE(path);
 
+               path = btrfs_alloc_path();
                if (!path) {
                        ret = -ENOMEM;
                        goto fail;
@@ -330,7 +331,6 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
                spin_lock(&block_group->lock);
                block_group->disk_cache_state = BTRFS_DC_CLEAR;
                spin_unlock(&block_group->lock);
-               btrfs_free_path(path);
        }
 
        btrfs_i_size_write(inode, 0);
index dcf79c2fad9bb86a99803f6802592735bb3de200..bc7e4c1ae0156934ab0ed90cfa2097169b6ee6fb 100644 (file)
@@ -2929,7 +2929,7 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
 {
        struct btrfs_root *root = inode->root;
        const u64 sectorsize = root->fs_info->sectorsize;
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        struct extent_buffer *leaf;
        struct btrfs_key ins;
        u64 disk_num_bytes = btrfs_stack_file_extent_disk_num_bytes(stack_fi);
@@ -3011,8 +3011,6 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
                                               file_pos - offset,
                                               qgroup_reserved, &ins);
 out:
-       btrfs_free_path(path);
-
        return ret;
 }
 
@@ -3538,7 +3536,7 @@ static int btrfs_orphan_del(struct btrfs_trans_handle *trans,
 int btrfs_orphan_cleanup(struct btrfs_root *root)
 {
        struct btrfs_fs_info *fs_info = root->fs_info;
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        struct extent_buffer *leaf;
        struct btrfs_key key, found_key;
        struct btrfs_trans_handle *trans;
@@ -3728,7 +3726,6 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
 out:
        if (ret)
                btrfs_err(fs_info, "could not do orphan cleanup %d", ret);
-       btrfs_free_path(path);
        return ret;
 }
 
@@ -4121,7 +4118,7 @@ static noinline int btrfs_update_inode_item(struct btrfs_trans_handle *trans,
                                            struct btrfs_inode *inode)
 {
        struct btrfs_inode_item *inode_item;
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        struct extent_buffer *leaf;
        struct btrfs_key key;
        int ret;
@@ -4135,7 +4132,7 @@ static noinline int btrfs_update_inode_item(struct btrfs_trans_handle *trans,
        if (ret) {
                if (ret > 0)
                        ret = -ENOENT;
-               goto failed;
+               return ret;
        }
 
        leaf = path->nodes[0];
@@ -4144,10 +4141,7 @@ static noinline int btrfs_update_inode_item(struct btrfs_trans_handle *trans,
 
        fill_inode_item(trans, leaf, inode_item, &inode->vfs_inode);
        btrfs_set_inode_last_trans(trans, inode);
-       ret = 0;
-failed:
-       btrfs_free_path(path);
-       return ret;
+       return 0;
 }
 
 /*
@@ -5454,7 +5448,7 @@ static int btrfs_inode_by_name(struct btrfs_inode *dir, struct dentry *dentry,
                               struct btrfs_key *location, u8 *type)
 {
        struct btrfs_dir_item *di;
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        struct btrfs_root *root = dir->root;
        int ret = 0;
        struct fscrypt_name fname;
@@ -5465,7 +5459,7 @@ static int btrfs_inode_by_name(struct btrfs_inode *dir, struct dentry *dentry,
 
        ret = fscrypt_setup_filename(&dir->vfs_inode, &dentry->d_name, 1, &fname);
        if (ret < 0)
-               goto out;
+               return ret;
        /*
         * fscrypt_setup_filename() should never return a positive value, but
         * gcc on sparc/parisc thinks it can, so assert that doesn't happen.
@@ -5494,7 +5488,6 @@ static int btrfs_inode_by_name(struct btrfs_inode *dir, struct dentry *dentry,
                *type = btrfs_dir_ftype(path->nodes[0], di);
 out:
        fscrypt_free_filename(&fname);
-       btrfs_free_path(path);
        return ret;
 }
 
@@ -5509,7 +5502,7 @@ static int fixup_tree_root_location(struct btrfs_fs_info *fs_info,
                                    struct btrfs_key *location,
                                    struct btrfs_root **sub_root)
 {
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        struct btrfs_root *new_root;
        struct btrfs_root_ref *ref;
        struct extent_buffer *leaf;
@@ -5565,7 +5558,6 @@ static int fixup_tree_root_location(struct btrfs_fs_info *fs_info,
        location->offset = 0;
        err = 0;
 out:
-       btrfs_free_path(path);
        fscrypt_free_filename(&fname);
        return err;
 }
@@ -5986,7 +5978,7 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
        struct btrfs_dir_item *di;
        struct btrfs_key key;
        struct btrfs_key found_key;
-       struct btrfs_path *path;
+       BTRFS_PATH_AUTO_FREE(path);
        void *addr;
        LIST_HEAD(ins_list);
        LIST_HEAD(del_list);
@@ -6099,7 +6091,6 @@ nopos:
 err:
        if (put)
                btrfs_readdir_put_delayed_items(BTRFS_I(inode), &ins_list, &del_list);
-       btrfs_free_path(path);
        return ret;
 }