Skip to content

Commit d37e411

Browse files
mssolakdave
authored andcommitted
btrfs: declare free_ipath() via DEFINE_FREE()
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>
1 parent d4589b2 commit d37e411

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
lines changed

fs/btrfs/backref.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,7 @@ struct btrfs_data_container *init_data_container(u32 total_bytes)
27852785
* allocates space to return multiple file system paths for an inode.
27862786
* total_bytes to allocate are passed, note that space usable for actual path
27872787
* information will be total_bytes - sizeof(struct inode_fs_paths).
2788-
* the returned pointer must be freed with free_ipath() in the end.
2788+
* the returned pointer must be freed with __free_inode_fs_paths() in the end.
27892789
*/
27902790
struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
27912791
struct btrfs_path *path)
@@ -2810,14 +2810,6 @@ struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
28102810
return ifp;
28112811
}
28122812

2813-
void free_ipath(struct inode_fs_paths *ipath)
2814-
{
2815-
if (!ipath)
2816-
return;
2817-
kvfree(ipath->fspath);
2818-
kfree(ipath);
2819-
}
2820-
28212813
struct btrfs_backref_iter *btrfs_backref_iter_alloc(struct btrfs_fs_info *fs_info)
28222814
{
28232815
struct btrfs_backref_iter *ret;

fs/btrfs/backref.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
241241
struct btrfs_data_container *init_data_container(u32 total_bytes);
242242
struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
243243
struct btrfs_path *path);
244-
void free_ipath(struct inode_fs_paths *ipath);
244+
245+
DEFINE_FREE(inode_fs_paths, struct inode_fs_paths *,
246+
if (_T) {
247+
kvfree(_T->fspath);
248+
kfree(_T);
249+
})
245250

246251
int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid,
247252
u64 start_off, struct btrfs_path *path,

fs/btrfs/inode.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static int data_reloc_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
130130
struct btrfs_fs_info *fs_info = warn->fs_info;
131131
struct extent_buffer *eb;
132132
struct btrfs_inode_item *inode_item;
133-
struct inode_fs_paths *ipath = NULL;
133+
struct inode_fs_paths *ipath __free(inode_fs_paths) = NULL;
134134
struct btrfs_root *local_root;
135135
struct btrfs_key key;
136136
unsigned int nofs_flag;
@@ -193,15 +193,13 @@ static int data_reloc_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
193193
}
194194

195195
btrfs_put_root(local_root);
196-
free_ipath(ipath);
197196
return 0;
198197

199198
err:
200199
btrfs_warn(fs_info,
201200
"checksum error at logical %llu mirror %u root %llu inode %llu offset %llu, path resolving failed with ret=%d",
202201
warn->logical, warn->mirror_num, root, inum, offset, ret);
203202

204-
free_ipath(ipath);
205203
return ret;
206204
}
207205

fs/btrfs/ioctl.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,7 +3298,7 @@ static long btrfs_ioctl_ino_to_path(struct btrfs_root *root, void __user *arg)
32983298
u64 rel_ptr;
32993299
int size;
33003300
struct btrfs_ioctl_ino_path_args *ipa = NULL;
3301-
struct inode_fs_paths *ipath = NULL;
3301+
struct inode_fs_paths *ipath __free(inode_fs_paths) = NULL;
33023302
struct btrfs_path *path;
33033303

33043304
if (!capable(CAP_DAC_READ_SEARCH))
@@ -3346,7 +3346,6 @@ static long btrfs_ioctl_ino_to_path(struct btrfs_root *root, void __user *arg)
33463346

33473347
out:
33483348
btrfs_free_path(path);
3349-
free_ipath(ipath);
33503349
kfree(ipa);
33513350

33523351
return ret;

fs/btrfs/scrub.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
505505
struct btrfs_inode_item *inode_item;
506506
struct scrub_warning *swarn = warn_ctx;
507507
struct btrfs_fs_info *fs_info = swarn->dev->fs_info;
508-
struct inode_fs_paths *ipath = NULL;
508+
struct inode_fs_paths *ipath __free(inode_fs_paths) = NULL;
509509
struct btrfs_root *local_root;
510510
struct btrfs_key key;
511511

@@ -569,7 +569,6 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
569569
(char *)(unsigned long)ipath->fspath->val[i]);
570570

571571
btrfs_put_root(local_root);
572-
free_ipath(ipath);
573572
return 0;
574573

575574
err:
@@ -580,7 +579,6 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
580579
swarn->physical,
581580
root, inum, offset, ret);
582581

583-
free_ipath(ipath);
584582
return 0;
585583
}
586584

0 commit comments

Comments
 (0)