btrfs: more trivial BTRFS_PATH_AUTO_FREE conversions
PATCH v4 1/1 btrfs: more trivial BTRFS_PATH_AUTO_FREE conversions
Trivial pattern for the auto freeing with goto -> return conversions if possible. No other function cleanup.
The following cases are considered trivial in this patch:
1. Cases where there are no operations between btrfs_free_path() and the function return.
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.
---
Changelog:
v1 -> v3:
* Directly return 0 if info is NULL in send.c:get_inode_info()
* Limit the scope of the conversion to only what is described in the commit message.
v3 -> v4:
* Fix missing conversions of BTRFS_PATH_AUTO_FREE
and tested with btrfs/quick group in xfstests
--- fs/btrfs/raid-stripe-tree.c | 15 +- fs/btrfs/ref-verify.c | 3 +- fs/btrfs/reflink.c | 3 +- fs/btrfs/relocation.c | 47 ++---- fs/btrfs/root-tree.c | 54 +++---- fs/btrfs/scrub.c | 11 +- fs/btrfs/send.c | 314 +++++++++++++----------------------- fs/btrfs/super.c | 5 +- fs/btrfs/transaction.c | 3 +- fs/btrfs/tree-log.c | 91 ++++------- 10 files changed, 195 insertions(+), 351 deletions(-)
fs/btrfs/raid-stripe-tree.c +5 -10
@@ -67,7 +67,7 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le {struct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_root *stripe_root = fs_info->stripe_root; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_key key;struct extent_buffer *leaf;u64 found_start;
@@ -260,7 +260,6 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 lebtrfs_release_path (path); } -btrfs_free_path (path);return ret; }
@@ -269,7 +268,7 @@ static int update_raid_extent_item(struct btrfs_trans_handle *trans,struct btrfs_stripe_extent *stripe_extent, const size_t item_size) { - struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path );struct extent_buffer *leaf;int ret;int slot;
@@ -288,7 +287,6 @@ static int update_raid_extent_item(struct btrfs_trans_handle *trans,write_extent_buffer (leaf, stripe_extent,btrfs_item_ptr_offset (leaf, slot), item_size); -btrfs_free_path (path);return ret; }
@@ -376,7 +374,7 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,struct btrfs_stripe_extent *stripe_extent;struct btrfs_key stripe_key;struct btrfs_key found_key; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct extent_buffer *leaf;const u64 end = logical + *length;int num_stripes;
@@ -402,7 +400,7 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, ret =btrfs_search_slot (NULL , stripe_root, &stripe_key, path,0 ,0 );if (ret <0 ) - goto free_path; +return ret;if (ret) {if (path->slots[0 ] !=0 ) path->slots[0 ]--;
@@ -459,8 +457,7 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,trace_btrfs_get_raid_extent_offset (fs_info, logical, *length, stripe->physical, devid); - ret =0 ; - goto free_path; +return 0 ; }/* 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, logical, logical + *length, stripe->dev->devid, btrfs_bg_type_to_raid_name(map_type)); } -free_path: -btrfs_free_path (path);return ret; }
fs/btrfs/ref-verify.c +1 -2
@@ -971,7 +971,7 @@ void btrfs_free_ref_tree_range(struct btrfs_fs_info *fs_info, u64 start,int btrfs_build_ref_tree (struct btrfs_fs_info *fs_info) {struct btrfs_root *extent_root; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct extent_buffer *eb;int tree_block_level =0 ;u64 bytenr =0 , num_bytes =0 ;
@@ -1021,6 +1021,5 @@ int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info)btrfs_free_ref_cache (fs_info);btrfs_clear_opt (fs_info->mount_opt,REF_VERIFY ); } -btrfs_free_path (path);return ret; }
fs/btrfs/reflink.c +1 -2
@@ -340,7 +340,7 @@ static int btrfs_clone(struct inode *src, struct inode *inode, const u64 destoff, bool no_time_update) {struct btrfs_fs_info *fs_info =inode_to_fs_info (inode); -struct btrfs_path *path =NULL ; +BTRFS_PATH_AUTO_FREE (path);struct extent_buffer *leaf;struct btrfs_trans_handle *trans;char *buf =NULL ;
@@ -611,7 +611,6 @@ static int btrfs_clone(struct inode *src, struct inode *inode, } out: -btrfs_free_path (path);kvfree (buf);clear_bit (BTRFS_INODE_NO_DELALLOC_FLUSH , &BTRFS_I (inode)->runtime_flags);
fs/btrfs/relocation.c +16 -31
128 lines not on this page · raw message
fs/btrfs/root-tree.c +20 -34
168 lines not on this page · raw message
fs/btrfs/scrub.c +3 -8
@@ -588,7 +588,7 @@ static void scrub_print_common_warning(const char *errstr, struct btrfs_device * bool is_super, u64 logical, u64 physical) { struct btrfs_fs_info *fs_info = dev->fs_info; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_key found_key;struct extent_buffer *eb;struct btrfs_extent_item *ei;
@@ -615,7 +615,7 @@ static void scrub_print_common_warning(const char *errstr, struct btrfs_device * ret =extent_from_logical (fs_info, swarn.logical, path, &found_key, &flags);if (ret <0 ) - goto out; +return ; swarn.extent_item_size = found_key.offset;
@@ -661,9 +661,6 @@ static void scrub_print_common_warning(const char *errstr, struct btrfs_device *iterate_extent_inodes (&ctx, true, scrub_print_warning_inode, &swarn); } - -out: -btrfs_free_path (path); }static int fill_writer_pointer_gap (struct scrub_ctx *sctx,u64 physical)
@@ -2606,7 +2603,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, struct btrfs_device *scrub_dev, u64 start, u64 end) { struct btrfs_dev_extent *dev_extent = NULL; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_fs_info *fs_info = sctx->fs_info;struct btrfs_root *root = fs_info->dev_root;u64 chunk_offset;
@@ -2892,8 +2889,6 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,btrfs_release_path (path); } -btrfs_free_path (path); -return ret; }
fs/btrfs/send.c +114 -200
838 lines not on this page · raw message
fs/btrfs/super.c +1 -4
@@ -925,7 +925,7 @@ static int get_default_subvol_objectid(struct btrfs_fs_info *fs_info, u64 *objec {struct btrfs_root *root = fs_info->tree_root;struct btrfs_dir_item *di; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_key location;struct fscrypt_str name =FSTR_INIT ("default" ,7 );u64 dir_id;
@@ -942,7 +942,6 @@ static int get_default_subvol_objectid(struct btrfs_fs_info *fs_info, u64 *objec dir_id =btrfs_super_root_dir (fs_info->super_copy); di =btrfs_lookup_dir_item (NULL , root, path, dir_id, &name,0 );if (IS_ERR (di)) { -btrfs_free_path (path);return PTR_ERR (di); }if (!di) {
@@ -951,13 +950,11 @@ static int get_default_subvol_objectid(struct btrfs_fs_info *fs_info, u64 *objec* it's always been there, but don't freak out, just try and * mount the top-level subvolume. */ -btrfs_free_path (path); *objectid =BTRFS_FS_TREE_OBJECTID ;return 0 ; }btrfs_dir_item_key_to_cpu (path->nodes[0 ], di, &location); -btrfs_free_path (path); *objectid = location.objectid;return 0 ; }
fs/btrfs/transaction.c +1 -2
@@ -1641,7 +1641,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,struct btrfs_root *parent_root;struct btrfs_block_rsv *rsv;struct btrfs_inode *parent_inode = pending->dir; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_dir_item *dir_item;struct extent_buffer *tmp;struct extent_buffer *old;
@@ -1905,7 +1905,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, free_pending:kfree (new_root_item); pending->root_item =NULL ; -btrfs_free_path (path); pending->path =NULL ;return ret;
fs/btrfs/tree-log.c +33 -58
260 lines not on this page · raw message
Signature · 1 line
2.51.0
Quoted 21 lines · Sun YangKai
Trivial pattern for the auto freeing with goto -> return conversions if possible. No other function cleanup.
The following cases are considered trivial in this patch:
1. Cases where there are no operations between
btrfs_free_path()and the function return.
2. Cases where only simple cleanup operations (such askfree(),kvfree(),clear_bit(), andfs_path_free()) are present betweenbtrfs_free_path()and the function return.Signed-off-by Sun YangKai <[email protected]>---
Changelog:
v1 -> v3:
* Directly return 0 if info is NULL in send.c:get_inode_info()
* Limit the scope of the conversion to only what is described in the commit message.
Quoted 3 lines
v3 -> v4:
* Fix missing conversions ofBTRFS_PATH_AUTO_FREE
and tested with btrfs/quick group in xfstests
Thanks, for the update. Back then I removed the patch from linux-next as it did not pass the full fstests run. I'm not sure if the quick group would be enough. I'll do a test round, if it passes I'll add the patch to for-next.
Quoted 21 lines · Sun YangKai
Trivial pattern for the auto freeing with goto -> return conversions if possible. No other function cleanup.
The following cases are considered trivial in this patch:
1. Cases where there are no operations between
btrfs_free_path()and the function return.
2. Cases where only simple cleanup operations (such askfree(),kvfree(),clear_bit(), andfs_path_free()) are present betweenbtrfs_free_path()and the function return.Signed-off-by Sun YangKai <[email protected]>---
Changelog:
v1 -> v3:
* Directly return 0 if info is NULL in send.c:get_inode_info()
* Limit the scope of the conversion to only what is described in the commit message.
Quoted 3 lines
v3 -> v4:
* Fix missing conversions ofBTRFS_PATH_AUTO_FREE
and tested with btrfs/quick group in xfstests
Added to for-next, thanks.