]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: declare free_ipath() via DEFINE_FREE()
authorMiquel Sabaté Solà <mssola@mssola.com>
Fri, 24 Oct 2025 10:21:40 +0000 (12:21 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:34:51 +0000 (22:34 +0100)
The free_ipath() function was being used as a cleanup function
everywhere. Declare it via DEFINE_FREE() so we can use this function
with the __free() helper.

The name has also been adjusted so it's closer to the type's name.

Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/backref.c
fs/btrfs/backref.h
fs/btrfs/inode.c
fs/btrfs/ioctl.c
fs/btrfs/scrub.c

index e050d0938dc45f13a1dd44a7ba59dbd76ddd82e9..eff2d388a706dda1b31264d8199839d4638c7f11 100644 (file)
@@ -2785,7 +2785,7 @@ struct btrfs_data_container *init_data_container(u32 total_bytes)
  * allocates space to return multiple file system paths for an inode.
  * total_bytes to allocate are passed, note that space usable for actual path
  * information will be total_bytes - sizeof(struct inode_fs_paths).
- * the returned pointer must be freed with free_ipath() in the end.
+ * the returned pointer must be freed with __free_inode_fs_paths() in the end.
  */
 struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
                                        struct btrfs_path *path)
@@ -2810,14 +2810,6 @@ struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
        return ifp;
 }
 
-void free_ipath(struct inode_fs_paths *ipath)
-{
-       if (!ipath)
-               return;
-       kvfree(ipath->fspath);
-       kfree(ipath);
-}
-
 struct btrfs_backref_iter *btrfs_backref_iter_alloc(struct btrfs_fs_info *fs_info)
 {
        struct btrfs_backref_iter *ret;
index 25d51c2460703b042ef6f19ee93275daa41f24a2..1d009b0f4c699ab8ecd2b7729d3c695f13d9dad3 100644 (file)
@@ -241,7 +241,12 @@ char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
 struct btrfs_data_container *init_data_container(u32 total_bytes);
 struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
                                        struct btrfs_path *path);
-void free_ipath(struct inode_fs_paths *ipath);
+
+DEFINE_FREE(inode_fs_paths, struct inode_fs_paths *,
+       if (_T) {
+               kvfree(_T->fspath);
+               kfree(_T);
+       })
 
 int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid,
                          u64 start_off, struct btrfs_path *path,
index 41b1d7819b8612885daea14b1e581b08a337dcdc..7958e6c4f6b3a79b360091363490646463d02063 100644 (file)
@@ -130,7 +130,7 @@ static int data_reloc_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
        struct btrfs_fs_info *fs_info = warn->fs_info;
        struct extent_buffer *eb;
        struct btrfs_inode_item *inode_item;
-       struct inode_fs_paths *ipath = NULL;
+       struct inode_fs_paths *ipath __free(inode_fs_paths) = NULL;
        struct btrfs_root *local_root;
        struct btrfs_key key;
        unsigned int nofs_flag;
@@ -195,7 +195,6 @@ static int data_reloc_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
        }
 
        btrfs_put_root(local_root);
-       free_ipath(ipath);
        return 0;
 
 err:
@@ -203,7 +202,6 @@ err:
 "checksum error at logical %llu mirror %u root %llu inode %llu offset %llu, path resolving failed with ret=%d",
                   warn->logical, warn->mirror_num, root, inum, offset, ret);
 
-       free_ipath(ipath);
        return ret;
 }
 
index 127b5d8303a8c8457370721b298ffeaf4f0de538..875d286bec8623afe945f18225ce9ef570e819f8 100644 (file)
@@ -3298,7 +3298,7 @@ static long btrfs_ioctl_ino_to_path(struct btrfs_root *root, void __user *arg)
        u64 rel_ptr;
        int size;
        struct btrfs_ioctl_ino_path_args *ipa = NULL;
-       struct inode_fs_paths *ipath = NULL;
+       struct inode_fs_paths *ipath __free(inode_fs_paths) = NULL;
        struct btrfs_path *path;
 
        if (!capable(CAP_DAC_READ_SEARCH))
@@ -3346,7 +3346,6 @@ static long btrfs_ioctl_ino_to_path(struct btrfs_root *root, void __user *arg)
 
 out:
        btrfs_free_path(path);
-       free_ipath(ipath);
        kfree(ipa);
 
        return ret;
index 5959511288c4e3955ed148b39fe0e6404e51477f..33c9cb91f0a948c8d3264bdd95bfa8aafc098cd5 100644 (file)
@@ -505,7 +505,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
        struct btrfs_inode_item *inode_item;
        struct scrub_warning *swarn = warn_ctx;
        struct btrfs_fs_info *fs_info = swarn->dev->fs_info;
-       struct inode_fs_paths *ipath = NULL;
+       struct inode_fs_paths *ipath __free(inode_fs_paths) = NULL;
        struct btrfs_root *local_root;
        struct btrfs_key key;
 
@@ -569,7 +569,6 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
                                  (char *)(unsigned long)ipath->fspath->val[i]);
 
        btrfs_put_root(local_root);
-       free_ipath(ipath);
        return 0;
 
 err:
@@ -580,7 +579,6 @@ err:
                          swarn->physical,
                          root, inum, offset, ret);
 
-       free_ipath(ipath);
        return 0;
 }