Skip to content

Commit 2e68180

Browse files
SaltyKitkatkdave
authored andcommitted
btrfs: more trivial BTRFS_PATH_AUTO_FREE conversions
Trivial pattern for the auto freeing without goto -> return conversions. No other function cleanup. Tested with btrfs/auto group. Signed-off-by: Sun YangKai <sunk67188@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 8a27ff1 commit 2e68180

File tree

4 files changed

+23
-49
lines changed

4 files changed

+23
-49
lines changed

fs/btrfs/uuid-tree.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid,
2727
u8 type, u64 subid)
2828
{
2929
int ret;
30-
struct btrfs_path *path = NULL;
30+
BTRFS_PATH_AUTO_FREE(path);
3131
struct extent_buffer *eb;
3232
int slot;
3333
u32 item_size;
@@ -79,7 +79,6 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid,
7979
}
8080

8181
out:
82-
btrfs_free_path(path);
8382
return ret;
8483
}
8584

@@ -89,7 +88,7 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typ
8988
struct btrfs_fs_info *fs_info = trans->fs_info;
9089
struct btrfs_root *uuid_root = fs_info->uuid_root;
9190
int ret;
92-
struct btrfs_path *path = NULL;
91+
BTRFS_PATH_AUTO_FREE(path);
9392
struct btrfs_key key;
9493
struct extent_buffer *eb;
9594
int slot;
@@ -141,7 +140,6 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typ
141140
subid_le = cpu_to_le64(subid_cpu);
142141
write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le));
143142
out:
144-
btrfs_free_path(path);
145143
return ret;
146144
}
147145

@@ -151,7 +149,7 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
151149
struct btrfs_fs_info *fs_info = trans->fs_info;
152150
struct btrfs_root *uuid_root = fs_info->uuid_root;
153151
int ret;
154-
struct btrfs_path *path = NULL;
152+
BTRFS_PATH_AUTO_FREE(path);
155153
struct btrfs_key key;
156154
struct extent_buffer *eb;
157155
int slot;
@@ -223,7 +221,6 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
223221
btrfs_truncate_item(trans, path, item_size - sizeof(subid), 1);
224222

225223
out:
226-
btrfs_free_path(path);
227224
return ret;
228225
}
229226

@@ -293,7 +290,7 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
293290
{
294291
struct btrfs_root *root = fs_info->uuid_root;
295292
struct btrfs_key key;
296-
struct btrfs_path *path;
293+
BTRFS_PATH_AUTO_FREE(path);
297294
int ret = 0;
298295
struct extent_buffer *leaf;
299296
int slot;
@@ -387,7 +384,6 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
387384
}
388385

389386
out:
390-
btrfs_free_path(path);
391387
return ret;
392388
}
393389

fs/btrfs/verity.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int drop_verity_items(struct btrfs_inode *inode, u8 key_type)
109109
{
110110
struct btrfs_trans_handle *trans;
111111
struct btrfs_root *root = inode->root;
112-
struct btrfs_path *path;
112+
BTRFS_PATH_AUTO_FREE(path);
113113
struct btrfs_key key;
114114
int count = 0;
115115
int ret;
@@ -170,7 +170,6 @@ static int drop_verity_items(struct btrfs_inode *inode, u8 key_type)
170170
ret = count;
171171
btrfs_end_transaction(trans);
172172
out:
173-
btrfs_free_path(path);
174173
return ret;
175174
}
176175

@@ -217,7 +216,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
217216
const char *src, u64 len)
218217
{
219218
struct btrfs_trans_handle *trans;
220-
struct btrfs_path *path;
219+
BTRFS_PATH_AUTO_FREE(path);
221220
struct btrfs_root *root = inode->root;
222221
struct extent_buffer *leaf;
223222
struct btrfs_key key;
@@ -267,7 +266,6 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
267266
btrfs_end_transaction(trans);
268267
}
269268

270-
btrfs_free_path(path);
271269
return ret;
272270
}
273271

@@ -296,7 +294,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
296294
static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
297295
char *dest, u64 len, struct folio *dest_folio)
298296
{
299-
struct btrfs_path *path;
297+
BTRFS_PATH_AUTO_FREE(path);
300298
struct btrfs_root *root = inode->root;
301299
struct extent_buffer *leaf;
302300
struct btrfs_key key;
@@ -404,7 +402,6 @@ static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
404402
}
405403
}
406404
out:
407-
btrfs_free_path(path);
408405
if (!ret)
409406
ret = copied;
410407
return ret;

fs/btrfs/volumes.c

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
16811681
struct btrfs_root *root = fs_info->dev_root;
16821682
struct btrfs_key key;
16831683
struct btrfs_dev_extent *dev_extent;
1684-
struct btrfs_path *path;
1684+
BTRFS_PATH_AUTO_FREE(path);
16851685
u64 search_start;
16861686
u64 hole_size;
16871687
u64 max_hole_start;
@@ -1812,7 +1812,6 @@ static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
18121812
"max_hole_start=%llu max_hole_size=%llu search_end=%llu",
18131813
max_hole_start, max_hole_size, search_end);
18141814
out:
1815-
btrfs_free_path(path);
18161815
*start = max_hole_start;
18171816
if (len)
18181817
*len = max_hole_size;
@@ -1826,7 +1825,7 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
18261825
struct btrfs_fs_info *fs_info = device->fs_info;
18271826
struct btrfs_root *root = fs_info->dev_root;
18281827
int ret;
1829-
struct btrfs_path *path;
1828+
BTRFS_PATH_AUTO_FREE(path);
18301829
struct btrfs_key key;
18311830
struct btrfs_key found_key;
18321831
struct extent_buffer *leaf = NULL;
@@ -1869,7 +1868,6 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
18691868
if (ret == 0)
18701869
set_bit(BTRFS_TRANS_HAVE_FREE_BGS, &trans->transaction->flags);
18711870
out:
1872-
btrfs_free_path(path);
18731871
return ret;
18741872
}
18751873

@@ -1897,7 +1895,7 @@ static noinline int find_next_devid(struct btrfs_fs_info *fs_info,
18971895
int ret;
18981896
struct btrfs_key key;
18991897
struct btrfs_key found_key;
1900-
struct btrfs_path *path;
1898+
BTRFS_PATH_AUTO_FREE(path);
19011899

19021900
path = btrfs_alloc_path();
19031901
if (!path)
@@ -1930,7 +1928,6 @@ static noinline int find_next_devid(struct btrfs_fs_info *fs_info,
19301928
}
19311929
ret = 0;
19321930
error:
1933-
btrfs_free_path(path);
19341931
return ret;
19351932
}
19361933

@@ -1942,7 +1939,7 @@ static int btrfs_add_dev_item(struct btrfs_trans_handle *trans,
19421939
struct btrfs_device *device)
19431940
{
19441941
int ret;
1945-
struct btrfs_path *path;
1942+
BTRFS_PATH_AUTO_FREE(path);
19461943
struct btrfs_dev_item *dev_item;
19471944
struct extent_buffer *leaf;
19481945
struct btrfs_key key;
@@ -1989,7 +1986,6 @@ static int btrfs_add_dev_item(struct btrfs_trans_handle *trans,
19891986

19901987
ret = 0;
19911988
out:
1992-
btrfs_free_path(path);
19931989
return ret;
19941990
}
19951991

@@ -2017,7 +2013,7 @@ static int btrfs_rm_dev_item(struct btrfs_trans_handle *trans,
20172013
{
20182014
struct btrfs_root *root = device->fs_info->chunk_root;
20192015
int ret;
2020-
struct btrfs_path *path;
2016+
BTRFS_PATH_AUTO_FREE(path);
20212017
struct btrfs_key key;
20222018

20232019
path = btrfs_alloc_path();
@@ -2039,7 +2035,6 @@ static int btrfs_rm_dev_item(struct btrfs_trans_handle *trans,
20392035

20402036
ret = btrfs_del_item(trans, root, path);
20412037
out:
2042-
btrfs_free_path(path);
20432038
return ret;
20442039
}
20452040

@@ -2626,7 +2621,7 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)
26262621
BTRFS_DEV_LOOKUP_ARGS(args);
26272622
struct btrfs_fs_info *fs_info = trans->fs_info;
26282623
struct btrfs_root *root = fs_info->chunk_root;
2629-
struct btrfs_path *path;
2624+
BTRFS_PATH_AUTO_FREE(path);
26302625
struct extent_buffer *leaf;
26312626
struct btrfs_dev_item *dev_item;
26322627
struct btrfs_device *device;
@@ -2690,7 +2685,6 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)
26902685
}
26912686
ret = 0;
26922687
error:
2693-
btrfs_free_path(path);
26942688
return ret;
26952689
}
26962690

@@ -2946,7 +2940,7 @@ static noinline int btrfs_update_device(struct btrfs_trans_handle *trans,
29462940
struct btrfs_device *device)
29472941
{
29482942
int ret;
2949-
struct btrfs_path *path;
2943+
BTRFS_PATH_AUTO_FREE(path);
29502944
struct btrfs_root *root = device->fs_info->chunk_root;
29512945
struct btrfs_dev_item *dev_item;
29522946
struct extent_buffer *leaf;
@@ -2982,7 +2976,6 @@ static noinline int btrfs_update_device(struct btrfs_trans_handle *trans,
29822976
btrfs_set_device_bytes_used(leaf, dev_item,
29832977
btrfs_device_get_bytes_used(device));
29842978
out:
2985-
btrfs_free_path(path);
29862979
return ret;
29872980
}
29882981

@@ -3035,7 +3028,7 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset)
30353028
struct btrfs_fs_info *fs_info = trans->fs_info;
30363029
struct btrfs_root *root = fs_info->chunk_root;
30373030
int ret;
3038-
struct btrfs_path *path;
3031+
BTRFS_PATH_AUTO_FREE(path);
30393032
struct btrfs_key key;
30403033

30413034
path = btrfs_alloc_path();
@@ -3064,7 +3057,6 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset)
30643057
goto out;
30653058
}
30663059
out:
3067-
btrfs_free_path(path);
30683060
return ret;
30693061
}
30703062

@@ -3501,7 +3493,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset,
35013493
static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
35023494
{
35033495
struct btrfs_root *chunk_root = fs_info->chunk_root;
3504-
struct btrfs_path *path;
3496+
BTRFS_PATH_AUTO_FREE(path);
35053497
struct extent_buffer *leaf;
35063498
struct btrfs_chunk *chunk;
35073499
struct btrfs_key key;
@@ -3580,7 +3572,6 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
35803572
ret = -ENOSPC;
35813573
}
35823574
error:
3583-
btrfs_free_path(path);
35843575
return ret;
35853576
}
35863577

@@ -4709,7 +4700,7 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
47094700
struct btrfs_balance_control *bctl;
47104701
struct btrfs_balance_item *item;
47114702
struct btrfs_disk_balance_args disk_bargs;
4712-
struct btrfs_path *path;
4703+
BTRFS_PATH_AUTO_FREE(path);
47134704
struct extent_buffer *leaf;
47144705
struct btrfs_key key;
47154706
int ret;
@@ -4772,7 +4763,6 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
47724763
spin_unlock(&fs_info->balance_lock);
47734764
mutex_unlock(&fs_info->balance_mutex);
47744765
out:
4775-
btrfs_free_path(path);
47764766
return ret;
47774767
}
47784768

@@ -7450,7 +7440,7 @@ static void readahead_tree_node_children(struct extent_buffer *node)
74507440
int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
74517441
{
74527442
struct btrfs_root *root = fs_info->chunk_root;
7453-
struct btrfs_path *path;
7443+
BTRFS_PATH_AUTO_FREE(path);
74547444
struct extent_buffer *leaf;
74557445
struct btrfs_key key;
74567446
struct btrfs_key found_key;
@@ -7567,8 +7557,6 @@ int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
75677557
ret = 0;
75687558
error:
75697559
mutex_unlock(&uuid_mutex);
7570-
7571-
btrfs_free_path(path);
75727560
return ret;
75737561
}
75747562

@@ -7668,7 +7656,7 @@ int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info)
76687656
{
76697657
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices, *seed_devs;
76707658
struct btrfs_device *device;
7671-
struct btrfs_path *path = NULL;
7659+
BTRFS_PATH_AUTO_FREE(path);
76727660
int ret = 0;
76737661

76747662
path = btrfs_alloc_path();
@@ -7690,8 +7678,6 @@ int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info)
76907678
}
76917679
out:
76927680
mutex_unlock(&fs_devices->device_list_mutex);
7693-
7694-
btrfs_free_path(path);
76957681
return ret;
76967682
}
76977683

@@ -7700,7 +7686,7 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
77007686
{
77017687
struct btrfs_fs_info *fs_info = trans->fs_info;
77027688
struct btrfs_root *dev_root = fs_info->dev_root;
7703-
struct btrfs_path *path;
7689+
BTRFS_PATH_AUTO_FREE(path);
77047690
struct btrfs_key key;
77057691
struct extent_buffer *eb;
77067692
struct btrfs_dev_stats_item *ptr;
@@ -7754,7 +7740,6 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
77547740
btrfs_set_dev_stats_value(eb, ptr, i,
77557741
btrfs_dev_stat_read(device, i));
77567742
out:
7757-
btrfs_free_path(path);
77587743
return ret;
77597744
}
77607745

@@ -8044,7 +8029,7 @@ static int verify_chunk_dev_extent_mapping(struct btrfs_fs_info *fs_info)
80448029
*/
80458030
int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
80468031
{
8047-
struct btrfs_path *path;
8032+
BTRFS_PATH_AUTO_FREE(path);
80488033
struct btrfs_root *root = fs_info->dev_root;
80498034
struct btrfs_key key;
80508035
u64 prev_devid = 0;
@@ -8134,7 +8119,6 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
81348119
/* Ensure all chunks have corresponding dev extents */
81358120
ret = verify_chunk_dev_extent_mapping(fs_info);
81368121
out:
8137-
btrfs_free_path(path);
81388122
return ret;
81398123
}
81408124

fs/btrfs/xattr.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ int btrfs_getxattr(const struct inode *inode, const char *name,
2929
{
3030
struct btrfs_dir_item *di;
3131
struct btrfs_root *root = BTRFS_I(inode)->root;
32-
struct btrfs_path *path;
32+
BTRFS_PATH_AUTO_FREE(path);
3333
struct extent_buffer *leaf;
3434
int ret = 0;
3535
unsigned long data_ptr;
@@ -76,7 +76,6 @@ int btrfs_getxattr(const struct inode *inode, const char *name,
7676
ret = btrfs_dir_data_len(leaf, di);
7777

7878
out:
79-
btrfs_free_path(path);
8079
return ret;
8180
}
8281

@@ -278,7 +277,7 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
278277
struct btrfs_key key;
279278
struct inode *inode = d_inode(dentry);
280279
struct btrfs_root *root = BTRFS_I(inode)->root;
281-
struct btrfs_path *path;
280+
BTRFS_PATH_AUTO_FREE(path);
282281
int iter_ret = 0;
283282
int ret = 0;
284283
size_t total_size = 0, size_left = size;
@@ -354,8 +353,6 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
354353
else
355354
ret = total_size;
356355

357-
btrfs_free_path(path);
358-
359356
return ret;
360357
}
361358

0 commit comments

Comments
 (0)