Skip to content

Commit 4ca6f24

Browse files
SaltyKitkatkdave
authored andcommitted
btrfs: more trivial BTRFS_PATH_AUTO_FREE conversions
Trivial pattern for the auto freeing with goto -> return conversions if possible. The following cases are considered trivial in this patch: 1. Cases where there are no operations between btrfs_free_path() and the function returns. 2. Cases where only simple cleanup operations (such as kfree(), kvfree(), clear_bit(), and fs_path_free()) are present between btrfs_free_path() and the function return. Signed-off-by: Sun YangKai <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent c9ff839 commit 4ca6f24

File tree

10 files changed

+195
-351
lines changed

10 files changed

+195
-351
lines changed

fs/btrfs/raid-stripe-tree.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
6767
{
6868
struct btrfs_fs_info *fs_info = trans->fs_info;
6969
struct btrfs_root *stripe_root = fs_info->stripe_root;
70-
struct btrfs_path *path;
70+
BTRFS_PATH_AUTO_FREE(path);
7171
struct btrfs_key key;
7272
struct extent_buffer *leaf;
7373
u64 found_start;
@@ -260,7 +260,6 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
260260
btrfs_release_path(path);
261261
}
262262

263-
btrfs_free_path(path);
264263
return ret;
265264
}
266265

@@ -269,7 +268,7 @@ static int update_raid_extent_item(struct btrfs_trans_handle *trans,
269268
struct btrfs_stripe_extent *stripe_extent,
270269
const size_t item_size)
271270
{
272-
struct btrfs_path *path;
271+
BTRFS_PATH_AUTO_FREE(path);
273272
struct extent_buffer *leaf;
274273
int ret;
275274
int slot;
@@ -288,7 +287,6 @@ static int update_raid_extent_item(struct btrfs_trans_handle *trans,
288287

289288
write_extent_buffer(leaf, stripe_extent, btrfs_item_ptr_offset(leaf, slot),
290289
item_size);
291-
btrfs_free_path(path);
292290

293291
return ret;
294292
}
@@ -376,7 +374,7 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
376374
struct btrfs_stripe_extent *stripe_extent;
377375
struct btrfs_key stripe_key;
378376
struct btrfs_key found_key;
379-
struct btrfs_path *path;
377+
BTRFS_PATH_AUTO_FREE(path);
380378
struct extent_buffer *leaf;
381379
const u64 end = logical + *length;
382380
int num_stripes;
@@ -402,7 +400,7 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
402400

403401
ret = btrfs_search_slot(NULL, stripe_root, &stripe_key, path, 0, 0);
404402
if (ret < 0)
405-
goto free_path;
403+
return ret;
406404
if (ret) {
407405
if (path->slots[0] != 0)
408406
path->slots[0]--;
@@ -459,8 +457,7 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
459457
trace_btrfs_get_raid_extent_offset(fs_info, logical, *length,
460458
stripe->physical, devid);
461459

462-
ret = 0;
463-
goto free_path;
460+
return 0;
464461
}
465462

466463
/* If we're here, we haven't found the requested devid in the stripe. */
@@ -474,8 +471,6 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
474471
logical, logical + *length, stripe->dev->devid,
475472
btrfs_bg_type_to_raid_name(map_type));
476473
}
477-
free_path:
478-
btrfs_free_path(path);
479474

480475
return ret;
481476
}

fs/btrfs/ref-verify.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ void btrfs_free_ref_tree_range(struct btrfs_fs_info *fs_info, u64 start,
971971
int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info)
972972
{
973973
struct btrfs_root *extent_root;
974-
struct btrfs_path *path;
974+
BTRFS_PATH_AUTO_FREE(path);
975975
struct extent_buffer *eb;
976976
int tree_block_level = 0;
977977
u64 bytenr = 0, num_bytes = 0;
@@ -1021,6 +1021,5 @@ int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info)
10211021
btrfs_free_ref_cache(fs_info);
10221022
btrfs_clear_opt(fs_info->mount_opt, REF_VERIFY);
10231023
}
1024-
btrfs_free_path(path);
10251024
return ret;
10261025
}

fs/btrfs/reflink.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
340340
const u64 destoff, bool no_time_update)
341341
{
342342
struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
343-
struct btrfs_path *path = NULL;
343+
BTRFS_PATH_AUTO_FREE(path);
344344
struct extent_buffer *leaf;
345345
struct btrfs_trans_handle *trans;
346346
char *buf = NULL;
@@ -611,7 +611,6 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
611611
}
612612

613613
out:
614-
btrfs_free_path(path);
615614
kvfree(buf);
616615
clear_bit(BTRFS_INODE_NO_DELALLOC_FLUSH, &BTRFS_I(inode)->runtime_flags);
617616

fs/btrfs/relocation.c

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ static int get_new_location(struct inode *reloc_inode, u64 *new_bytenr,
821821
u64 bytenr, u64 num_bytes)
822822
{
823823
struct btrfs_root *root = BTRFS_I(reloc_inode)->root;
824-
struct btrfs_path *path;
824+
BTRFS_PATH_AUTO_FREE(path);
825825
struct btrfs_file_extent_item *fi;
826826
struct extent_buffer *leaf;
827827
int ret;
@@ -834,11 +834,9 @@ static int get_new_location(struct inode *reloc_inode, u64 *new_bytenr,
834834
ret = btrfs_lookup_file_extent(NULL, root, path,
835835
btrfs_ino(BTRFS_I(reloc_inode)), bytenr, 0);
836836
if (ret < 0)
837-
goto out;
838-
if (ret > 0) {
839-
ret = -ENOENT;
840-
goto out;
841-
}
837+
return ret;
838+
if (ret > 0)
839+
return -ENOENT;
842840

843841
leaf = path->nodes[0];
844842
fi = btrfs_item_ptr(leaf, path->slots[0],
@@ -849,16 +847,11 @@ static int get_new_location(struct inode *reloc_inode, u64 *new_bytenr,
849847
btrfs_file_extent_encryption(leaf, fi) ||
850848
btrfs_file_extent_other_encoding(leaf, fi));
851849

852-
if (num_bytes != btrfs_file_extent_disk_num_bytes(leaf, fi)) {
853-
ret = -EINVAL;
854-
goto out;
855-
}
850+
if (num_bytes != btrfs_file_extent_disk_num_bytes(leaf, fi))
851+
return -EINVAL;
856852

857853
*new_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
858-
ret = 0;
859-
out:
860-
btrfs_free_path(path);
861-
return ret;
854+
return 0;
862855
}
863856

864857
/*
@@ -3158,7 +3151,7 @@ static int __add_tree_block(struct reloc_control *rc,
31583151
struct rb_root *blocks)
31593152
{
31603153
struct btrfs_fs_info *fs_info = rc->extent_root->fs_info;
3161-
struct btrfs_path *path;
3154+
BTRFS_PATH_AUTO_FREE(path);
31623155
struct btrfs_key key;
31633156
int ret;
31643157
bool skinny = btrfs_fs_incompat(fs_info, SKINNY_METADATA);
@@ -3186,7 +3179,7 @@ static int __add_tree_block(struct reloc_control *rc,
31863179
path->skip_locking = 1;
31873180
ret = btrfs_search_slot(NULL, rc->extent_root, &key, path, 0, 0);
31883181
if (ret < 0)
3189-
goto out;
3182+
return ret;
31903183

31913184
if (ret > 0 && skinny) {
31923185
if (path->slots[0]) {
@@ -3213,14 +3206,10 @@ static int __add_tree_block(struct reloc_control *rc,
32133206
"tree block extent item (%llu) is not found in extent tree",
32143207
bytenr);
32153208
WARN_ON(1);
3216-
ret = -EINVAL;
3217-
goto out;
3209+
return -EINVAL;
32183210
}
32193211

3220-
ret = add_tree_block(rc, &key, path, blocks);
3221-
out:
3222-
btrfs_free_path(path);
3223-
return ret;
3212+
return add_tree_block(rc, &key, path, blocks);
32243213
}
32253214

32263215
static int delete_block_group_cache(struct btrfs_block_group *block_group,
@@ -3510,7 +3499,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
35103499
struct rb_root blocks = RB_ROOT;
35113500
struct btrfs_key key;
35123501
struct btrfs_trans_handle *trans = NULL;
3513-
struct btrfs_path *path;
3502+
BTRFS_PATH_AUTO_FREE(path);
35143503
struct btrfs_extent_item *ei;
35153504
u64 flags;
35163505
int ret;
@@ -3679,14 +3668,13 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
36793668
if (ret < 0 && !err)
36803669
err = ret;
36813670
btrfs_free_block_rsv(fs_info, rc->block_rsv);
3682-
btrfs_free_path(path);
36833671
return err;
36843672
}
36853673

36863674
static int __insert_orphan_inode(struct btrfs_trans_handle *trans,
36873675
struct btrfs_root *root, u64 objectid)
36883676
{
3689-
struct btrfs_path *path;
3677+
BTRFS_PATH_AUTO_FREE(path);
36903678
struct btrfs_inode_item *item;
36913679
struct extent_buffer *leaf;
36923680
int ret;
@@ -3697,7 +3685,7 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans,
36973685

36983686
ret = btrfs_insert_empty_inode(trans, root, path, objectid);
36993687
if (ret)
3700-
goto out;
3688+
return ret;
37013689

37023690
leaf = path->nodes[0];
37033691
item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_inode_item);
@@ -3707,15 +3695,13 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans,
37073695
btrfs_set_inode_mode(leaf, item, S_IFREG | 0600);
37083696
btrfs_set_inode_flags(leaf, item, BTRFS_INODE_NOCOMPRESS |
37093697
BTRFS_INODE_PREALLOC);
3710-
out:
3711-
btrfs_free_path(path);
3712-
return ret;
3698+
return 0;
37133699
}
37143700

37153701
static void delete_orphan_inode(struct btrfs_trans_handle *trans,
37163702
struct btrfs_root *root, u64 objectid)
37173703
{
3718-
struct btrfs_path *path;
3704+
BTRFS_PATH_AUTO_FREE(path);
37193705
struct btrfs_key key;
37203706
int ret = 0;
37213707

@@ -3738,7 +3724,6 @@ static void delete_orphan_inode(struct btrfs_trans_handle *trans,
37383724
out:
37393725
if (ret)
37403726
btrfs_abort_transaction(trans, ret);
3741-
btrfs_free_path(path);
37423727
}
37433728

37443729
/*

0 commit comments

Comments
 (0)