btrfs: more trivial BTRFS_PATH_AUTO_FREE conversions
PATCH v2 1/1 btrfs: more trivial BTRFS_PATH_AUTO_FREE conversions
Trivial pattern for the auto freeing with goto -> return conversions. No other function cleanup.
---
Changelog:
v1 -> v2:
* Add goto -> return conversions
--- fs/btrfs/uuid-tree.c | 114 ++++++++++++---------------------- fs/btrfs/verity.c | 23 +++---- fs/btrfs/volumes.c | 142 +++++++++++++++---------------------------- fs/btrfs/xattr.c | 36 ++++------- 4 files changed, 109 insertions(+), 206 deletions(-)
fs/btrfs/uuid-tree.c +40 -74
@@ -27,32 +27,26 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid, u8 type, u64 subid) { int ret; -struct btrfs_path *path =NULL ; +BTRFS_PATH_AUTO_FREE (path);struct extent_buffer *eb;int slot;u32 item_size;unsigned long offset;struct btrfs_key key; -if (WARN_ON_ONCE (!uuid_root)) { - ret = -ENOENT ; - goto out; - } +if (WARN_ON_ONCE (!uuid_root)) +return -ENOENT ; path =btrfs_alloc_path (); -if (!path) { - ret = -ENOMEM ; - goto out; - } +if (!path) +return -ENOMEM ;btrfs_uuid_to_key (uuid, type, &key); ret =btrfs_search_slot (NULL , uuid_root, &key, path,0 ,0 ); -if (ret <0 ) { - goto out; - }else if (ret >0 ) { - ret = -ENOENT ; - goto out; - } +if (ret <0 ) +return ret; +if (ret >0 ) +return -ENOENT ; eb = path->nodes[0 ]; slot = path->slots[0 ];
@@ -64,7 +58,7 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid,btrfs_warn (uuid_root->fs_info,"uuid item with illegal size %lu!" , (unsigned long )item_size); - goto out; +return ret; }while (item_size) {__le64 data;
@@ -78,8 +72,6 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid, item_size -=sizeof (data); } -out: -btrfs_free_path (path);return ret; }
@@ -89,7 +81,7 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typstruct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_root *uuid_root = fs_info->uuid_root;int ret; -struct btrfs_path *path =NULL ; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_key key;struct extent_buffer *eb;int slot;
@@ -100,18 +92,14 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typif (ret != -ENOENT )return ret; -if (WARN_ON_ONCE (!uuid_root)) { - ret = -EINVAL ; - goto out; - } +if (WARN_ON_ONCE (!uuid_root)) +return -EINVAL ;btrfs_uuid_to_key (uuid, type, &key); path =btrfs_alloc_path (); -if (!path) { - ret = -ENOMEM ; - goto out; - } +if (!path) +return -ENOMEM ; ret =btrfs_insert_empty_item (trans, uuid_root, path, &key,sizeof (subid_le));
@@ -134,15 +122,12 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typbtrfs_warn (fs_info,"insert uuid item failed %d (0x%016llx, 0x%016llx) type %u!" , ret, key.objectid, key.offset, type); - goto out; +return ret; } - ret =0 ; subid_le =cpu_to_le64 (subid_cpu);write_extent_buffer (eb, &subid_le, offset,sizeof (subid_le)); -out: -btrfs_free_path (path); -return ret; +return 0 ; } int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8 type,
@@ -151,7 +136,7 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8struct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_root *uuid_root = fs_info->uuid_root;int ret; -struct btrfs_path *path =NULL ; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_key key;struct extent_buffer *eb;int slot;
@@ -161,29 +146,23 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8unsigned long move_src;unsigned long move_len; -if (WARN_ON_ONCE (!uuid_root)) { - ret = -EINVAL ; - goto out; - } +if (WARN_ON_ONCE (!uuid_root)) +return -EINVAL ;btrfs_uuid_to_key (uuid, type, &key); path =btrfs_alloc_path (); -if (!path) { - ret = -ENOMEM ; - goto out; - } +if (!path) +return -ENOMEM ; ret =btrfs_search_slot (trans, uuid_root, &key, path,-1 ,1 );if (ret <0 ) {btrfs_warn (fs_info,"error %d while searching for uuid item!" , ret); - goto out; - } -if (ret >0 ) { - ret = -ENOENT ; - goto out; +return ret; } +if (ret >0 ) +return -ENOENT ; eb = path->nodes[0 ]; slot = path->slots[0 ];
@@ -192,8 +171,7 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8if (!IS_ALIGNED (item_size,sizeof (u64))) {btrfs_warn (fs_info,"uuid item with illegal size %lu!" , (unsigned long )item_size); - ret = -ENOENT ; - goto out; +return -ENOENT ; }while (item_size) {__le64 read_subid;
@@ -205,26 +183,19 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8 item_size -=sizeof (read_subid); } -if (!item_size) { - ret = -ENOENT ; - goto out; - } +if (!item_size) +return -ENOENT ; item_size =btrfs_item_size (eb, slot); -if (item_size ==sizeof (subid)) { - ret =btrfs_del_item (trans, uuid_root, path); - goto out; - } +if (item_size ==sizeof (subid)) +return btrfs_del_item (trans, uuid_root, path); move_dst = offset; move_src = offset +sizeof (subid); move_len = item_size - (move_src -btrfs_item_ptr_offset (eb, slot));memmove_extent_buffer (eb, move_dst, move_src, move_len);btrfs_truncate_item (trans, path, item_size -sizeof (subid),1 ); - -out: -btrfs_free_path (path); -return ret; +return 0 ; } static int btrfs_uuid_iter_rem(struct btrfs_root *uuid_root, u8 *uuid, u8 type,
@@ -293,7 +264,7 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info) {struct btrfs_root *root = fs_info->uuid_root;struct btrfs_key key; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);int ret =0 ;struct extent_buffer *leaf;int slot;
@@ -301,10 +272,8 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)unsigned long offset; path =btrfs_alloc_path (); -if (!path) { - ret = -ENOMEM ; - goto out; - } +if (!path) +return -ENOMEM ; key.objectid =0 ; key.type =0 ;
@@ -315,14 +284,13 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)if (ret) {if (ret >0 ) ret =0 ; - goto out; +return ret; }while (1 ) { -if (btrfs_fs_closing (fs_info)) { - ret = -EINTR ; - goto out; - } +if (btrfs_fs_closing (fs_info)) +return -EINTR ; +cond_resched (); leaf = path->nodes[0 ]; slot = path->slots[0 ];
@@ -353,7 +321,7 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info) ret =btrfs_check_uuid_tree_entry (fs_info, uuid, key.type, subid_cpu);if (ret <0 ) - goto out; +return ret;if (ret >0 ) {btrfs_release_path (path); ret = btrfs_uuid_iter_rem(root, uuid, key.type,
@@ -369,7 +337,7 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info) goto again_search_slot; }if (ret <0 && ret != -ENOENT ) - goto out; +return ret; key.offset++; goto again_search_slot; }
@@ -386,8 +354,6 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)break ; } -out: -btrfs_free_path (path);return ret; }
fs/btrfs/verity.c +8 -15
@@ -109,7 +109,7 @@ static int drop_verity_items(struct btrfs_inode *inode, u8 key_type) {struct btrfs_trans_handle *trans;struct btrfs_root *root = inode->root; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_key key;int count =0 ;int ret;
@@ -121,10 +121,8 @@ static int drop_verity_items(struct btrfs_inode *inode, u8 key_type)while (1 ) {/* 1 for the item being dropped */ trans =btrfs_start_transaction (root,1 ); -if (IS_ERR (trans)) { - ret =PTR_ERR (trans); - goto out; - } +if (IS_ERR (trans)) +return PTR_ERR (trans);/* * Walk backwards through all the items until we find one that
@@ -143,7 +141,7 @@ static int drop_verity_items(struct btrfs_inode *inode, u8 key_type) path->slots[0 ]--; }else if (ret <0 ) {btrfs_end_transaction (trans); - goto out; +return ret; }btrfs_item_key_to_cpu (path->nodes[0 ], &key, path->slots[0 ]);
@@ -161,17 +159,14 @@ static int drop_verity_items(struct btrfs_inode *inode, u8 key_type) ret =btrfs_del_items (trans, root, path, path->slots[0 ],1 );if (ret) {btrfs_end_transaction (trans); - goto out; +return ret; } count++;btrfs_release_path (path);btrfs_end_transaction (trans); } - ret = count;btrfs_end_transaction (trans); -out: -btrfs_free_path (path); -return ret; +return count; }/*
@@ -217,7 +212,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, const char *src, u64 len) {struct btrfs_trans_handle *trans; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_root *root = inode->root;struct extent_buffer *leaf;struct btrfs_key key;
@@ -267,7 +262,6 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,btrfs_end_transaction (trans); } -btrfs_free_path (path);return ret; }
@@ -296,7 +290,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,static int read_key_bytes (struct btrfs_inode *inode,u8 key_type,u64 offset,char *dest,u64 len,struct folio *dest_folio) { -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_root *root = inode->root;struct extent_buffer *leaf;struct btrfs_key key;
@@ -404,7 +398,6 @@ static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, } } out: -btrfs_free_path (path);if (!ret) ret = copied;return ret;
fs/btrfs/volumes.c +50 -92
444 lines not on this page · raw message
fs/btrfs/xattr.c +11 -25
@@ -29,9 +29,8 @@ int btrfs_getxattr(const struct inode *inode, const char *name, {struct btrfs_dir_item *di;struct btrfs_root *root =BTRFS_I (inode)->root; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct extent_buffer *leaf; -int ret =0 ;unsigned long data_ptr; path =btrfs_alloc_path ();
@@ -41,26 +40,19 @@ int btrfs_getxattr(const struct inode *inode, const char *name,/* lookup the xattr by name */ di =btrfs_lookup_xattr (NULL , root, path,btrfs_ino (BTRFS_I (inode)), name,strlen (name),0 ); -if (!di) { - ret = -ENODATA ; - goto out; - }else if (IS_ERR (di)) { - ret =PTR_ERR (di); - goto out; - } +if (!di) +return -ENODATA ; +if (IS_ERR (di)) +return PTR_ERR (di); leaf = path->nodes[0 ];/* if size is 0, that means we want the size of the attr */ -if (!size) { - ret =btrfs_dir_data_len (leaf, di); - goto out; - } +if (!size) +return btrfs_dir_data_len (leaf, di);/* now get the data out of our dir_item */ -if (btrfs_dir_data_len (leaf, di) > size) { - ret = -ERANGE ; - goto out; - } +if (btrfs_dir_data_len (leaf, di) > size) +return -ERANGE ;/* * The way things are packed into the leaf is like this
@@ -73,11 +65,7 @@ int btrfs_getxattr(const struct inode *inode, const char *name, btrfs_dir_name_len(leaf, di));read_extent_buffer (leaf, buffer, data_ptr,btrfs_dir_data_len (leaf, di)); - ret =btrfs_dir_data_len (leaf, di); - -out: -btrfs_free_path (path); -return ret; +return btrfs_dir_data_len (leaf, di); } int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode,
@@ -278,7 +266,7 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)struct btrfs_key key;struct inode *inode =d_inode (dentry);struct btrfs_root *root =BTRFS_I (inode)->root; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);int iter_ret =0 ;int ret =0 ;size_t total_size =0 , size_left = size;
@@ -354,8 +342,6 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)else ret = total_size; -btrfs_free_path (path); -return ret; }
Signature · 1 line
2.51.0
Quoted 2 lines · Sun YangKai
Trivial pattern for the auto freeing with goto -> return conversions. No other function cleanup.
You could have copied the changelog from previous version, the above is too terse.
Quoted 2 lines
---
The --- is a delimiter of the changelog so anything below that untill the diff starts will be dropped.
Quoted 6 lines
Changelog:
v1 -> v2:
* Add goto -> return conversionsSigned-off-by Sun YangKai <[email protected]>
In this case your signed off that I added manually to the committed version.
Below are a few fixups I did in the final version, a few cases to unify the returns.
fs/btrfs/uuid-tree.c int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info) · line 288
Quoted 7 lines
fs/btrfs/uuid-tree.c +1
-1@@ -315,14 +284,13 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)if (ret) {if (ret >0 ) ret =0 ; - goto out; +return ret; }
The ifs can be untangled to two:
if (ret < 0) return ret; if (ret > 0) return 0;
Quoted 16 lines
fs/btrfs/uuid-tree.c +3
-4while (1 ) { -if (btrfs_fs_closing (fs_info)) { - ret = -EINTR ; - goto out; - } +if (btrfs_fs_closing (fs_info)) +return -EINTR ; +cond_resched (); leaf = path->nodes[0 ]; slot = path->slots[0 ];
fs/btrfs/verity.c static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, · line 218
Quoted 8 lines
fs/btrfs/verity.c +1
-1@@ -217,7 +212,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, const char *src, u64 len) {struct btrfs_trans_handle *trans; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_root *root = inode->root;struct extent_buffer *leaf;struct btrfs_key key;
One break -> return conversion in the while() loop from after btrfs_start_transaction() failure.
Quoted 4 lines
fs/btrfs/volumes.c +0
-0@@ -2034,12 +2024,10 @@ static int btrfs_rm_dev_item(struct btrfs_trans_handle *trans,if (ret) {
fs/btrfs/volumes.c static int btrfs_rm_dev_item(struct btrfs_trans_handle *trans, · line 2031
Quoted 10 lines
fs/btrfs/volumes.c +1
-3if (ret >0 ) ret = -ENOENT ; - goto out; +return ret; } ret =btrfs_del_item (trans, root, path); -out: -btrfs_free_path (path);return ret;
Here the btrfs_del_item() can be put to return, it was done in another part of this patch too.
fs/btrfs/volumes.c static int btrfs_free_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset) · line 3033
Quoted 10 lines
fs/btrfs/volumes.c +2
-2}@@ -3048,23 +3029,20 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset) ret =btrfs_search_slot (trans, root, &key, path,-1 ,1 );if (ret <0 ) - goto out; -else if (unlikely (ret >0 )) {/* Logic error or corruption */ +return ret; +if (unlikely (ret >0 )) {/* Logic error or corruption */
Minor style fixup to move the comment to a separate line, you can still find that but it's from old code and this is a good time to update it.
fs/btrfs/volumes.c static int btrfs_free_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset) · line 3038
Quoted 7 lines
fs/btrfs/volumes.c +1
-2btrfs_err (fs_info,"failed to lookup chunk %llu when freeing" , chunk_offset);btrfs_abort_transaction (trans, -ENOENT ); - ret = -EUCLEAN ; - goto out; +return -EUCLEAN ; }
Otherwise OK. You don't need to fix and resend the patch. I'm not sure if there are more places to convert. If you find some please send them. Thanks.
Quoted 13 lines · David Sterba
Quoted 2 lines · Sun YangKai
Trivial pattern for the auto freeing with goto -> return conversions. No other function cleanup.
You could have copied the changelog from previous version, the above is too terse.
Quoted 2 lines
---
The --- is a delimiter of the changelog so anything below that untill the diff starts will be dropped.
Quoted 1 line
Quoted 9 lines
Quoted 5 lines
Changelog:
v1 -> v2:
* Add goto -> return conversionsSigned-off-by Sun YangKai <[email protected]>In this case your signed off that I added manually to the committed version.
Thank you David. Your guidance on the mailing list workflow was very helpful, as I was unfamiliar with it. I'd welcome any further suggestions.
Quoted 68 lines
Below are a few fixups I did in the final version, a few cases to unify the returns.
fs/btrfs/uuid-tree.c int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info) · line 288
Quoted 7 lines
fs/btrfs/uuid-tree.c +1
-1@@ -315,14 +284,13 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)if (ret) {if (ret >0 ) ret =0 ; - goto out; +return ret; }The ifs can be untangled to two:
if (ret < 0) return ret; if (ret > 0) return 0;Quoted 16 lines
fs/btrfs/uuid-tree.c +3
-4while (1 ) { -if (btrfs_fs_closing (fs_info)) { - ret = -EINTR ; - goto out; - } +if (btrfs_fs_closing (fs_info)) +return -EINTR ; +cond_resched (); leaf = path->nodes[0 ]; slot = path->slots[0 ];fs/btrfs/verity.c static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, · line 218
Quoted 8 lines
fs/btrfs/verity.c +1
-1@@ -217,7 +212,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, const char *src, u64 len) {struct btrfs_trans_handle *trans; -struct btrfs_path *path; +BTRFS_PATH_AUTO_FREE (path);struct btrfs_root *root = inode->root;struct extent_buffer *leaf;struct btrfs_key key;One break -> return conversion in the
while()loop from afterbtrfs_start_transaction()failure.Quoted 4 lines
fs/btrfs/volumes.c +0
-0@@ -2034,12 +2024,10 @@ static int btrfs_rm_dev_item(struct btrfs_trans_handle *trans,if (ret) {fs/btrfs/volumes.c static int btrfs_rm_dev_item(struct btrfs_trans_handle *trans, · line 2031
Quoted 10 lines
fs/btrfs/volumes.c +1
-3if (ret >0 ) ret = -ENOENT ; - goto out; +return ret; } ret =btrfs_del_item (trans, root, path); -out: -btrfs_free_path (path);return ret;Here the
btrfs_del_item()can be put to return, it was done in another part of this patch too.Quoted 4 lines
fs/btrfs/volumes.c +0
-0}@@ -3048,23 +3029,20 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset)
Quoted 9 lines
fs/btrfs/volumes.c static int btrfs_free_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset) · line 3033
Quoted 6 lines
fs/btrfs/volumes.c +2
-2ret =btrfs_search_slot (trans, root, &key, path,-1 ,1 );if (ret <0 ) - goto out; -else if (unlikely (ret >0 )) {/* Logic error or corruption */ +return ret; +if (unlikely (ret >0 )) {/* Logic error or corruption */ Minor style fixup to move the comment to a separate line, you can still find that but it's from old code and this is a good time to update it.
After a quick pass through the patch, I noticed another similar case:
@@ -4724,17 +4699,14 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); if (ret < 0)
- goto out;
+ return ret;
if (ret > 0) { /* ret = -ENOENT; */
- ret = 0;
- goto out;
+ return 0;
}
Quoted 12 lines
fs/btrfs/volumes.c static int btrfs_free_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset) · line 3038
Quoted 8 lines
fs/btrfs/volumes.c +1
-2btrfs_err (fs_info,"failed to lookup chunk %llu when freeing" , chunk_offset);btrfs_abort_transaction (trans, -ENOENT ); - ret = -EUCLEAN ; - goto out; +return -EUCLEAN ; }Otherwise OK. You don't need to fix and resend the patch. I'm not sure if there are more places to convert. If you find some please send them. Thanks.
Best reguards,
Sun Yangkai