btrfs: fix a return value and remove pointless labels and gotos
cover btrfs: fix a return value and remove pointless labels and gotos
From: Filipe Manana <[email protected]>
Remove pointless labels and gotos that can be replaced with a single "return ret" or "return -SOMEERROR", making the code shorter and more straighforward to follow and to not leave such examples for people to copy and keep repeating it. The first patch fixes a bug in an error path where we can end up returning success (0) instead of an error.
Filipe Manana (19):
btrfs: qgroup: return correct error when deleting qgroup relation item
btrfs: remove pointless out labels from ioctl.c
btrfs: remove pointless out labels from send.c
btrfs: remove pointless out labels from qgroup.c
btrfs: remove pointless out labels from disk-io.c
btrfs: remove pointless out labels from extent-tree.c
btrfs: remove pointless out labels from free-space-cache.c
btrfs: remove pointless out labels from inode.c
btrfs: remove pointless out labels from uuid-tree.c
btrfs: remove out label in load_extent_tree_free()
btrfs: remove out_failed label in find_lock_delalloc_range()
btrfs: remove out label in btrfs_csum_file_blocks()
btrfs: remove out label in btrfs_mark_extent_written()
btrfs: remove out label in lzo_decompress()
btrfs: remove out label in scrub_find_fill_first_stripe()
btrfs: remove out label in finish_verity()
btrfs: remove out label in btrfs_check_rw_degradable()
btrfs: remove out label in btrfs_init_space_info()
btrfs: remove out label in btrfs_wait_for_commit()
fs/btrfs/block-group.c | 10 +++--- fs/btrfs/disk-io.c | 54 ++++++++++++------------------ fs/btrfs/extent-tree.c | 24 ++++++------- fs/btrfs/extent_io.c | 5 ++- fs/btrfs/file-item.c | 16 ++++----- fs/btrfs/file.c | 30 ++++++++--------- fs/btrfs/free-space-cache.c | 31 +++++++---------- fs/btrfs/inode.c | 21 +++++------- fs/btrfs/ioctl.c | 40 +++++++++------------- fs/btrfs/lzo.c | 15 ++++----- fs/btrfs/qgroup.c | 22 +++++------- fs/btrfs/scrub.c | 8 ++--- fs/btrfs/send.c | 67 ++++++++++++++++--------------------- fs/btrfs/space-info.c | 13 ++++--- fs/btrfs/transaction.c | 9 ++--- fs/btrfs/uuid-tree.c | 16 ++++----- fs/btrfs/verity.c | 13 +++---- fs/btrfs/volumes.c | 12 +++---- 18 files changed, 173 insertions(+), 233 deletions(-)
Signature · 1 line
2.47.2
PATCH 1/19 btrfs: qgroup: return correct error when deleting qgroup relation item
From: Filipe Manana <[email protected]>
If we fail to delete the second qgroup relation item, we end up returning success or -ENOENT in case the first item does not exist, instead of returning the error from the second item deletion.
--- fs/btrfs/qgroup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/qgroup.c +3 -1
@@ -1640,8 +1640,10 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src,if (ret <0 && ret != -ENOENT ) goto out; ret2 =del_qgroup_relation_item (trans, dst, src); -if (ret2 <0 && ret2 != -ENOENT ) +if (ret2 <0 && ret2 != -ENOENT ) { + ret = ret2; goto out; + }/* At least one deletion succeeded, return 0 */ if (!ret || !ret2)
Signature · 1 line
2.47.2
PATCH 2/19 btrfs: remove pointless out labels from ioctl.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (__btrfs_ioctl_snap_create(), btrfs_ioctl_subvol_setflags() and copy_to_sk()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting up the 'ret' variable.
--- fs/btrfs/ioctl.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-)
fs/btrfs/ioctl.c +15 -25
@@ -1184,7 +1184,7 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file, ret =mnt_want_write_file (file);if (ret) - goto out; +return ret;if (strchr (name,'/' )) { ret = -EINVAL ;
@@ -1236,7 +1236,6 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file, } out_drop_write:mnt_drop_write_file (file); -out:return ret; }
@@ -1359,7 +1358,7 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file, ret =mnt_want_write_file (file);if (ret) - goto out; +return ret;if (btrfs_ino (BTRFS_I (inode)) !=BTRFS_FIRST_FREE_OBJECTID ) { ret = -EINVAL ;
@@ -1428,7 +1427,6 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,up_write (&fs_info->subvol_sem); out_drop_write:mnt_drop_write_file (file); -out:return ret; }
@@ -1494,10 +1492,8 @@ static noinline int copy_to_sk(struct btrfs_path *path,continue ;if (sizeof (sh) + item_len > *buf_size) { -if (*num_found) { - ret =1 ; - goto out; - } +if (*num_found) +return 1 ;/* * return one empty item back for v1, which does not
@@ -1509,10 +1505,8 @@ static noinline int copy_to_sk(struct btrfs_path *path, ret = -EOVERFLOW ; } -if (sizeof (sh) + item_len + *sk_offset > *buf_size) { - ret =1 ; - goto out; - } +if (sizeof (sh) + item_len + *sk_offset > *buf_size) +return 1 ; sh.objectid = key->objectid; sh.type = key->type;
@@ -1526,10 +1520,8 @@ static noinline int copy_to_sk(struct btrfs_path *path,* problem. Otherwise we'll fault and then copy the buffer in * properly this next time through */ -if (copy_to_user_nofault (ubuf + *sk_offset, &sh,sizeof (sh))) { - ret =0 ; - goto out; - } +if (copy_to_user_nofault (ubuf + *sk_offset, &sh,sizeof (sh))) +return 0 ; *sk_offset +=sizeof (sh);
@@ -1541,22 +1533,20 @@ static noinline int copy_to_sk(struct btrfs_path *path,*/ if (read_extent_buffer_to_user_nofault (leaf, up, item_off, item_len)) { - ret =0 ; *sk_offset -=sizeof (sh); - goto out; +return 0 ; } *sk_offset += item_len; } (*num_found)++; -if (ret)/* -EOVERFLOW from above */ - goto out; +/* -EOVERFLOW from above. */ +if (ret) +return ret; -if (*num_found >= sk->nr_items) { - ret =1 ; - goto out; - } +if (*num_found >= sk->nr_items) +return 1 ; } advance_key: ret =0 ;
@@ -1576,7 +1566,7 @@ static noinline int copy_to_sk(struct btrfs_path *path, key->objectid++; }else ret =1 ; -out: +/* * 0: all items from this leaf copied, continue with next * 1: * more items can be copied, but unused buffer is too small
Signature · 1 line
2.47.2
PATCH 3/19 btrfs: remove pointless out labels from send.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (process_extent(), process_recorded_refs_if_needed(), changed_inode(), compare_refs() and changed_cb()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/send.c | 67 +++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 38 deletions(-)
fs/btrfs/send.c +29 -38
@@ -6449,7 +6449,7 @@ static int process_extent(struct send_ctx *sctx,if (sctx->parent_root && !sctx->cur_inode_new) { ret =is_extent_unchanged (sctx, path, key);if (ret <0 ) - goto out; +return ret;if (ret) { ret =0 ; goto out_hole;
@@ -6469,30 +6469,25 @@ static int process_extent(struct send_ctx *sctx,* we have enough commands queued up to justify rev'ing * the send spec. */ -if (type ==BTRFS_FILE_EXTENT_PREALLOC ) { - ret =0 ; - goto out; - } +if (type ==BTRFS_FILE_EXTENT_PREALLOC ) +return 0 ;/* Have a hole, just skip it. */ -if (btrfs_file_extent_disk_bytenr (path->nodes[0 ], ei) ==0 ) { - ret =0 ; - goto out; - } +if (btrfs_file_extent_disk_bytenr (path->nodes[0 ], ei) ==0 ) +return 0 ; } } ret =find_extent_clone (sctx, path, key->objectid, key->offset, sctx->cur_inode_size, &found_clone);if (ret != -ENOENT && ret <0 ) - goto out; +return ret; ret =send_write_or_clone (sctx, path, key, found_clone);if (ret) - goto out; +return ret; out_hole: ret =maybe_send_hole (sctx, path, key); -out:return ret; }
@@ -6535,23 +6530,22 @@ static int process_recorded_refs_if_needed(struct send_ctx *sctx, bool at_end,int *pending_move, int *refs_processed) { - int ret = 0; + int ret;if (sctx->cur_ino ==0 ) - goto out; +return 0 ;if (!at_end && sctx->cur_ino == sctx->cmp_key->objectid && sctx->cmp_key->type <=BTRFS_INODE_EXTREF_KEY ) - goto out; +return 0 ;if (list_empty (&sctx->new_refs) &&list_empty (&sctx->deleted_refs)) - goto out; +return 0 ; ret =process_recorded_refs (sctx, pending_move);if (ret <0 ) - goto out; +return ret; *refs_processed =1 ; -out: -return ret; +return 0 ; }static int finish_inode_if_needed (struct send_ctx *sctx,bool at_end)
@@ -6768,7 +6762,7 @@ static void close_current_inode(struct send_ctx *sctx)static int changed_inode (struct send_ctx *sctx,enum btrfs_compare_tree_result result) { -int ret =0 ; +int ret;struct btrfs_key *key = sctx->cmp_key;struct btrfs_inode_item *left_ii =NULL ;struct btrfs_inode_item *right_ii =NULL ;
@@ -6860,7 +6854,7 @@ static int changed_inode(struct send_ctx *sctx,if (result ==BTRFS_COMPARE_TREE_NEW ) {if (btrfs_inode_nlink (sctx->left_path->nodes[0 ], left_ii) ==0 ) { sctx->ignore_cur_inode = true; - goto out; +return 0 ; } sctx->cur_inode_gen = left_gen; sctx->cur_inode_new = true;
@@ -6888,7 +6882,7 @@ static int changed_inode(struct send_ctx *sctx, old_nlinks =btrfs_inode_nlink (sctx->right_path->nodes[0 ], right_ii);if (new_nlinks ==0 && old_nlinks ==0 ) { sctx->ignore_cur_inode = true; - goto out; +return 0 ; }else if (new_nlinks ==0 || old_nlinks ==0 ) { sctx->cur_inode_new_gen =1 ; }
@@ -6914,7 +6908,7 @@ static int changed_inode(struct send_ctx *sctx, ret =process_all_refs (sctx,BTRFS_COMPARE_TREE_DELETED );if (ret <0 ) - goto out; +return ret; }/*
@@ -6935,11 +6929,11 @@ static int changed_inode(struct send_ctx *sctx, left_ii); ret =send_create_inode_if_needed (sctx);if (ret <0 ) - goto out; +return ret; ret =process_all_refs (sctx,BTRFS_COMPARE_TREE_NEW );if (ret <0 ) - goto out; +return ret;/* * Advance send_progress now as we did not get * into process_recorded_refs_if_needed in the
@@ -6953,10 +6947,10 @@ static int changed_inode(struct send_ctx *sctx,*/ ret =process_all_extents (sctx);if (ret <0 ) - goto out; +return ret; ret =process_all_new_xattrs (sctx);if (ret <0 ) - goto out; +return ret; } }else { sctx->cur_inode_gen = left_gen;
@@ -6970,8 +6964,7 @@ static int changed_inode(struct send_ctx *sctx, } } -out: -return ret; +return 0 ; }/*
@@ -7104,20 +7097,20 @@ static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path,u32 item_size;u32 cur_offset =0 ;int ref_name_len; -int ret =0 ;/* Easy case, just check this one dirid */ if (key->type ==BTRFS_INODE_REF_KEY ) { dirid = key->offset; - ret =dir_changed (sctx, dirid); - goto out; +return dir_changed (sctx, dirid); } leaf = path->nodes[0 ]; item_size =btrfs_item_size (leaf, path->slots[0 ]); ptr =btrfs_item_ptr_offset (leaf, path->slots[0 ]);while (cur_offset < item_size) { +int ret; + extref = (struct btrfs_inode_extref *)(ptr + cur_offset); dirid =btrfs_inode_extref_parent (leaf, extref);
@@ -7130,8 +7123,7 @@ static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path,break ; last_dirid = dirid; } -out: -return ret; +return 0 ; }/*
@@ -7212,12 +7204,12 @@ static int changed_cb(struct btrfs_path *left_path, ret =finish_inode_if_needed (sctx,0 );if (ret <0 ) - goto out; +return ret;/* Ignore non-FS objects */ if (key->objectid ==BTRFS_FREE_INO_OBJECTID || key->objectid ==BTRFS_FREE_SPACE_OBJECTID ) - goto out; +return 0 ;if (key->type ==BTRFS_INODE_ITEM_KEY ) { ret =changed_inode (sctx, result);
@@ -7234,8 +7226,7 @@ static int changed_cb(struct btrfs_path *left_path, ret =changed_verity (sctx, result); } -out: -return ret; +return 0 ; } static int search_key_again(const struct send_ctx *sctx,
Signature · 1 line
2.47.2
Re: [PATCH 03/19] btrfs: remove pointless out labels from send.c
fs/btrfs/send.c static int process_recorded_refs_if_needed(struct send_ctx *sctx, bool at_end, · line 6540
Quoted 8 lines · On 1/21/26 12:28 PM, [email protected] wrote:
if (
sctx->cur_ino== 0)fs/btrfs/send.c +2
-2- goto out; +return 0 ;if (!at_end && sctx->cur_ino == sctx->cmp_key->objectid && sctx->cmp_key->type <=BTRFS_INODE_EXTREF_KEY ) - goto out; +return 0 ;if (list_empty (&sctx->new_refs) &&list_empty (&sctx->deleted_refs))
Nit: a newline after the inserted return statements here would be nice.
Re: [PATCH 03/19] btrfs: remove pointless out labels from send.c
In reply to [email protected]fs/btrfs/send.c static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path, · line 7126
Quoted 13 lines · On 1/21/26 12:28 PM, [email protected] wrote:
while (cur_offset < item_size) {fs/btrfs/send.c +3
-2+int ret; + extref = (struct btrfs_inode_extref *)(ptr + cur_offset); dirid =btrfs_inode_extref_parent (leaf, extref);@@ -7130,8 +7123,7 @@ static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path,break ; last_dirid = dirid; } -out: -return ret; +return 0 ;
Doesn't this omit the return from dir_changed?
while (cur_offset < item_size) {
extref = (struct btrfs_inode_extref *)(ptr + cur_offset);
dirid = btrfs_inode_extref_parent(leaf, extref); ref_name_len = btrfs_inode_extref_name_len(leaf, extref); cur_offset += ref_name_len + sizeof(*extref); if (dirid == last_dirid)
continue;
ret = dir_changed(sctx, dirid);
if (ret)
break;
last_dirid = dirid;
}
out:
return ret;
IIUIC we need to keep 'return ret' here.
Re: [PATCH 03/19] btrfs: remove pointless out labels from send.c
Quoted 35 lines · Johannes Thumshirn
fs/btrfs/send.c static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path, · line 7126
Quoted 13 lines · On 1/21/26 12:28 PM, [email protected] wrote:
while (cur_offset < item_size) {fs/btrfs/send.c +3
-2+int ret; + extref = (struct btrfs_inode_extref *)(ptr + cur_offset); dirid =btrfs_inode_extref_parent (leaf, extref);@@ -7130,8 +7123,7 @@ static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path,break ; last_dirid = dirid; } -out: -return ret; +return 0 ;Doesn't this omit the return from
dir_changed?while (cur_offset < item_size) { extref = (struct btrfs_inode_extref *)(ptr + cur_offset); dirid = btrfs_inode_extref_parent(leaf, extref); ref_name_len = btrfs_inode_extref_name_len(leaf, extref); cur_offset += ref_name_len + sizeof(*extref); if (dirid == last_dirid) continue; ret = dir_changed(sctx, dirid); if (ret) break; last_dirid = dirid; } out: return ret;
Quoted 1 line
IIUIC we need to keep 'return ret' here.
The intention was really to return 0 and instead of break do return ret, but I forgot that last part. Will fix in second version.
Quoted 1 line
Re: [PATCH 03/19] btrfs: remove pointless out labels from send.c
Quoted 35 lines · Filipe Manana
Quoted 33 lines · Johannes Thumshirn
fs/btrfs/send.c static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path, · line 7126
Quoted 13 lines · On 1/21/26 12:28 PM, [email protected] wrote:
while (cur_offset < item_size) {fs/btrfs/send.c +3
-2+int ret; + extref = (struct btrfs_inode_extref *)(ptr + cur_offset); dirid =btrfs_inode_extref_parent (leaf, extref);@@ -7130,8 +7123,7 @@ static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path,break ; last_dirid = dirid; } -out: -return ret; +return 0 ;Doesn't this omit the return from
dir_changed?while (cur_offset < item_size) { extref = (struct btrfs_inode_extref *)(ptr + cur_offset); dirid = btrfs_inode_extref_parent(leaf, extref); ref_name_len = btrfs_inode_extref_name_len(leaf, extref); cur_offset += ref_name_len + sizeof(*extref); if (dirid == last_dirid) continue; ret = dir_changed(sctx, dirid); if (ret) break; last_dirid = dirid; } out: return ret;
Quoted 4 lines
Quoted 1 line
IIUIC we need to keep 'return ret' here.
The intention was really to return 0 and instead of break do return ret, but I forgot that last part. Will fix in second version.
OK, I'm not done reviewing the series though, but I'll do so tomorrow morning.
PATCH 4/19 btrfs: remove pointless out labels from qgroup.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (__del_qgroup_relation() and qgroup_trace_new_subtree_blocks()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/qgroup.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
fs/btrfs/qgroup.c +10 -16
@@ -1613,10 +1613,8 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src,int ret =0 ;int ret2; -if (!fs_info->quota_root) { - ret = -ENOTCONN ; - goto out; - } +if (!fs_info->quota_root) +return -ENOTCONN ; member =find_qgroup_rb (fs_info, src); parent =find_qgroup_rb (fs_info, dst);
@@ -1638,12 +1636,10 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src, delete_item: ret =del_qgroup_relation_item (trans, src, dst);if (ret <0 && ret != -ENOENT ) - goto out; +return ret; ret2 =del_qgroup_relation_item (trans, dst, src); -if (ret2 <0 && ret2 != -ENOENT ) { - ret = ret2; - goto out; - } +if (ret2 <0 && ret2 != -ENOENT ) +return ret2;/* At least one deletion succeeded, return 0 */ if (!ret || !ret2)
@@ -1657,7 +1653,7 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src,squota_check_parent_usage (fs_info, parent);spin_unlock (&fs_info->qgroup_lock); } -out: +return ret; }
@@ -2490,13 +2486,11 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans,/* This node is old, no need to trace */ if (child_gen < last_snapshot) - goto out; +return ret; eb =btrfs_read_node_slot (eb, parent_slot); -if (IS_ERR (eb)) { - ret =PTR_ERR (eb); - goto out; - } +if (IS_ERR (eb)) +return PTR_ERR (eb); dst_path->nodes[cur_level] = eb; dst_path->slots[cur_level] =0 ;
@@ -2541,7 +2535,7 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans, dst_path->slots[cur_level] =0 ; dst_path->locks[cur_level] =0 ; } -out: +return ret; }
Signature · 1 line
2.47.2
PATCH 5/19 btrfs: remove pointless out labels from disk-io.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (btrfs_validate_extent_buffer() and btrfs_start_pre_rw_mount()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/disk-io.c | 54 +++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 32 deletions(-)
fs/btrfs/disk-io.c +22 -32
@@ -369,22 +369,19 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,btrfs_err_rl (fs_info,"bad tree block start, mirror %u want %llu have %llu" , eb->read_mirror, eb->start, found_start); - ret = -EIO ; - goto out; +return -EIO ; }if (unlikely (check_tree_block_fsid (eb))) {btrfs_err_rl (fs_info,"bad fsid on logical %llu mirror %u" , eb->start, eb->read_mirror); - ret = -EIO ; - goto out; +return -EIO ; } found_level =btrfs_header_level (eb);if (unlikely (found_level >=BTRFS_MAX_LEVEL )) {btrfs_err (fs_info,"bad tree block level, mirror %u level %d on logical %llu" , eb->read_mirror,btrfs_header_level (eb), eb->start); - ret = -EIO ; - goto out; +return -EIO ; }csum_tree_block (eb, result);
@@ -399,18 +396,15 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,BTRFS_CSUM_FMT_VALUE (csum_size, result),btrfs_header_level (eb), ignore_csum ? ", ignored" : ""); -if (unlikely (!ignore_csum)) { - ret = -EUCLEAN ; - goto out; - } +if (unlikely (!ignore_csum)) +return -EUCLEAN ; }if (unlikely (found_level != check->level)) {btrfs_err (fs_info,"level verify failed on logical %llu mirror %u wanted %u found %u" , eb->start, eb->read_mirror, check->level, found_level); - ret = -EIO ; - goto out; +return -EIO ; }if (unlikely (check->transid &&btrfs_header_generation (eb) != check->transid)) {
@@ -418,8 +412,7 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,"parent transid verify failed on logical %llu mirror %u wanted %llu found %llu" , eb->start, eb->read_mirror, check->transid, btrfs_header_generation(eb)); - ret = -EIO ; - goto out; +return -EIO ; }if (check->has_first_key) {const struct btrfs_key *expect_key = &check->first_key;
@@ -437,14 +430,13 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb, expect_key->type, expect_key->offset, found_key.objectid, found_key.type, found_key.offset); - ret = -EUCLEAN ; - goto out; +return -EUCLEAN ; } }if (check->owner_root) { ret =btrfs_check_eb_owner (eb, check->owner_root);if (ret <0 ) - goto out; +return ret; }/* If this is a leaf block and it is corrupt, just return -EIO. */
@@ -458,7 +450,6 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,btrfs_err (fs_info,"read time tree block corruption detected on logical %llu mirror %u" , eb->start, eb->read_mirror); -out:return ret; }
@@ -3075,7 +3066,7 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)if (ret) {btrfs_warn (fs_info,"failed to rebuild free space tree: %d" , ret); - goto out; +return ret; } }
@@ -3086,7 +3077,7 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)if (ret) {btrfs_warn (fs_info,"failed to disable free space tree: %d" , ret); - goto out; +return ret; } }
@@ -3097,7 +3088,7 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info) ret =btrfs_delete_orphan_free_space_entries (fs_info);if (ret <0 ) {btrfs_err (fs_info,"failed to delete orphan free space tree entries: %d" , ret); - goto out; +return ret; }/* * btrfs_find_orphan_roots() is responsible for finding all the dead
@@ -3112,17 +3103,17 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)*/ ret =btrfs_find_orphan_roots (fs_info);if (ret) - goto out; +return ret; ret =btrfs_cleanup_fs_roots (fs_info);if (ret) - goto out; +return ret;down_read (&fs_info->cleanup_work_sem);if ((ret =btrfs_orphan_cleanup (fs_info->fs_root)) || (ret =btrfs_orphan_cleanup (fs_info->tree_root))) {up_read (&fs_info->cleanup_work_sem); - goto out; +return ret; }up_read (&fs_info->cleanup_work_sem);
@@ -3131,7 +3122,7 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)mutex_unlock (&fs_info->cleaner_mutex);if (ret <0 ) {btrfs_warn (fs_info,"failed to recover relocation: %d" , ret); - goto out; +return ret; } if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) &&
@@ -3141,24 +3132,24 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)if (ret) {btrfs_warn (fs_info,"failed to create free space tree: %d" , ret); - goto out; +return ret; } }if (cache_opt !=btrfs_free_space_cache_v1_active (fs_info)) { ret =btrfs_set_free_space_cache_v1_active (fs_info, cache_opt);if (ret) - goto out; +return ret; } ret =btrfs_resume_balance_async (fs_info);if (ret) - goto out; +return ret; ret =btrfs_resume_dev_replace_async (fs_info);if (ret) {btrfs_warn (fs_info,"failed to resume dev_replace" ); - goto out; +return ret; }btrfs_qgroup_rescan_resume (fs_info);
@@ -3169,12 +3160,11 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)if (ret) {btrfs_warn (fs_info,"failed to create the UUID tree %d" , ret); - goto out; +return ret; } } -out: -return ret; +return 0 ; }/*
Signature · 1 line
2.47.2
PATCH 6/19 btrfs: remove pointless out labels from extent-tree.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (lookup_extent_data_ref(), __btrfs_mod_ref() and btrfs_free_tree_block()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/extent-tree.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
fs/btrfs/extent-tree.c +10 -14
@@ -477,7 +477,7 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,btrfs_item_key_to_cpu (leaf, &key, path->slots[0 ]);if (key.objectid != bytenr || key.type !=BTRFS_EXTENT_DATA_REF_KEY ) - goto fail; +return ret; ref =btrfs_item_ptr (leaf, path->slots[0 ], struct btrfs_extent_data_ref);
@@ -488,12 +488,11 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,btrfs_release_path (path); goto again; } - ret =0 ; -break ; +return 0 ; } path->slots[0 ]++; } -fail: +return ret; }
@@ -2501,7 +2500,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,int i;int action;int level; -int ret =0 ; +int ret;if (btrfs_is_testing (fs_info))return 0 ;
@@ -2553,7 +2552,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,else ret =btrfs_free_extent (trans, &ref);if (ret) - goto fail; +return ret; }else {/* We don't know the owning_root, leave as 0. */ ref.bytenr =btrfs_node_blockptr (buf, i);
@@ -2566,12 +2565,10 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,else ret =btrfs_free_extent (trans, &ref);if (ret) - goto fail; +return ret; } }return 0 ; -fail: -return ret; } int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
@@ -3575,12 +3572,12 @@ int btrfs_free_tree_block(struct btrfs_trans_handle *trans,return 0 ;if (btrfs_header_generation (buf) != trans->transid) - goto out; +return 0 ;if (root_id !=BTRFS_TREE_LOG_OBJECTID ) { ret =check_ref_cleanup (trans, buf->start);if (!ret) - goto out; +return 0 ; } bg =btrfs_lookup_block_group (fs_info, buf->start);
@@ -3588,7 +3585,7 @@ int btrfs_free_tree_block(struct btrfs_trans_handle *trans,if (btrfs_header_flag (buf,BTRFS_HEADER_FLAG_WRITTEN )) {pin_down_extent (trans, bg, buf->start, buf->len, true);btrfs_put_block_group (bg); - goto out; +return 0 ; }/*
@@ -3612,7 +3609,7 @@ int btrfs_free_tree_block(struct btrfs_trans_handle *trans, || btrfs_is_zoned(fs_info)) {pin_down_extent (trans, bg, buf->start, buf->len, true);btrfs_put_block_group (bg); - goto out; +return 0 ; }WARN_ON (test_bit (EXTENT_BUFFER_DIRTY , &buf->bflags));
@@ -3622,7 +3619,6 @@ int btrfs_free_tree_block(struct btrfs_trans_handle *trans,btrfs_put_block_group (bg);trace_btrfs_reserved_extent_free (fs_info, buf->start, buf->len); -out:return 0 ; }
Signature · 1 line
2.47.2
PATCH 7/19 btrfs: remove pointless out labels from free-space-cache.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (update_cache_item(), find_free_space(), trim_bitmaps(), btrfs_remove_free_space() and cleanup_free_space_cache_v1()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/free-space-cache.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-)
fs/btrfs/free-space-cache.c +13 -18
@@ -1162,7 +1162,7 @@ update_cache_item(struct btrfs_trans_handle *trans,if (ret <0 ) {btrfs_clear_extent_bit (&BTRFS_I (inode)->io_tree,0 , inode->i_size -1 ,EXTENT_DELALLOC ,NULL ); - goto fail; +return ret; } leaf = path->nodes[0 ];if (ret >0 ) {
@@ -1176,7 +1176,7 @@ update_cache_item(struct btrfs_trans_handle *trans, inode->i_size -1 ,EXTENT_DELALLOC , NULL);btrfs_release_path (path); - goto fail; +return -ENOENT ; } }
@@ -1189,9 +1189,6 @@ update_cache_item(struct btrfs_trans_handle *trans,btrfs_release_path (path);return 0 ; - -fail: -return -1 ; } static noinline_for_stack int write_pinned_extent_entries(
@@ -2017,7 +2014,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes,int ret;if (!ctl->free_space_offset.rb_node) - goto out; +return NULL ; again:if (use_bytes_index) { node =rb_first_cached (&ctl->free_space_bytes);
@@ -2025,7 +2022,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, entry =tree_search_offset (ctl,offset_to_bitmap (ctl, *offset),0 ,1 );if (!entry) - goto out; +return NULL ; node = &entry->offset_index; }
@@ -2109,7 +2106,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, *bytes = entry->bytes - align_off;return entry; } -out: +return NULL ; }
@@ -2828,7 +2825,6 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group,spin_lock (&ctl->tree_lock); again: - ret =0 ;if (!bytes) goto out_lock;
@@ -2894,7 +2890,7 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group, old_end - (offset + bytes), info->trim_state);WARN_ON (ret); - goto out; +return ret; } }
@@ -2906,8 +2902,8 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group, out_lock:btrfs_discard_update_discardable (block_group);spin_unlock (&ctl->tree_lock); -out: -return ret; + +return 0 ; } void btrfs_dump_free_space(struct btrfs_block_group *block_group,
@@ -4007,7 +4003,7 @@ static int trim_bitmaps(struct btrfs_block_group *block_group,if (async && *total_trimmed) {spin_unlock (&ctl->tree_lock);mutex_unlock (&ctl->cache_writeout_mutex); - goto out; +return ret; } bytes =min (bytes, end - start);
@@ -4068,7 +4064,6 @@ static int trim_bitmaps(struct btrfs_block_group *block_group,if (offset >= end) block_group->discard_cursor = end; -out:return ret; }
@@ -4161,20 +4156,20 @@ static int cleanup_free_space_cache_v1(struct btrfs_fs_info *fs_info, {struct btrfs_block_group *block_group;struct rb_node *node; -int ret =0 ;btrfs_info (fs_info,"cleaning free space cache v1" ); node =rb_first_cached (&fs_info->block_group_cache_tree);while (node) { +int ret; + block_group = rb_entry(node, struct btrfs_block_group, cache_node); ret =btrfs_remove_free_space_inode (trans,NULL , block_group);if (ret) - goto out; +return ret; node =rb_next (node); } -out: -return ret; +return 0 ; }int btrfs_set_free_space_cache_v1_active (struct btrfs_fs_info *fs_info,bool active)
Signature · 1 line
2.47.2
PATCH 8/19 btrfs: remove pointless out labels from inode.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (insert_inline_extent() and insert_reserved_file_extent()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/inode.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
fs/btrfs/inode.c +9 -12
@@ -507,7 +507,7 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans, ret =btrfs_insert_empty_item (trans, root, path, &key, datasize);if (ret) - goto fail; +return ret; } leaf = path->nodes[0 ]; ei = btrfs_item_ptr(leaf, path->slots[0],
@@ -546,7 +546,7 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans, ret =btrfs_inode_set_file_extent_range (inode,0 ,ALIGN (size, root->fs_info->sectorsize));if (ret) - goto fail; +return ret;/* * We're an inline extent, so nobody can extend the file past i_size
@@ -562,8 +562,7 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans, } inode->disk_i_size = i_size; -fail: -return ret; +return 0 ; } static bool can_cow_file_range_inline(struct btrfs_inode *inode,
@@ -3037,7 +3036,7 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, drop_args.extent_item_size =sizeof (*stack_fi); ret =btrfs_drop_extents (trans, root, inode, &drop_args);if (ret) - goto out; +return ret;if (!drop_args.extent_inserted) { ins.objectid =btrfs_ino (inode);
@@ -3047,7 +3046,7 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, ret =btrfs_insert_empty_item (trans, root, path, &ins,sizeof (*stack_fi));if (ret) - goto out; +return ret; } leaf = path->nodes[0 ];btrfs_set_stack_file_extent_generation (stack_fi, trans->transid);
@@ -3082,13 +3081,11 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, ret =btrfs_inode_set_file_extent_range (inode, file_pos, ram_bytes);if (ret) - goto out; +return ret; - ret =btrfs_alloc_reserved_file_extent (trans, root,btrfs_ino (inode), - file_pos - offset, - qgroup_reserved, &ins); -out: -return ret; +return btrfs_alloc_reserved_file_extent (trans, root,btrfs_ino (inode), + file_pos - offset, + qgroup_reserved, &ins); } static void btrfs_release_delalloc_bytes(struct btrfs_fs_info *fs_info,
Signature · 1 line
2.47.2
PATCH 9/19 btrfs: remove pointless out labels from uuid-tree.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (btrfs_uuid_iter_rem() and btrfs_check_uuid_tree_entry()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/uuid-tree.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
fs/btrfs/uuid-tree.c +6 -10
@@ -207,15 +207,11 @@ static int btrfs_uuid_iter_rem(struct btrfs_root *uuid_root, u8 *uuid, u8 type,/* 1 - for the uuid item */ trans =btrfs_start_transaction (uuid_root,1 ); -if (IS_ERR (trans)) { - ret =PTR_ERR (trans); - goto out; - } +if (IS_ERR (trans)) +return PTR_ERR (trans); ret =btrfs_uuid_tree_remove (trans, uuid, type, subid);btrfs_end_transaction (trans); - -out:return ret; }
@@ -235,14 +231,14 @@ static int btrfs_check_uuid_tree_entry(struct btrfs_fs_info *fs_info,if (type !=BTRFS_UUID_KEY_SUBVOL && type !=BTRFS_UUID_KEY_RECEIVED_SUBVOL ) - goto out; +return 0 ; subvol_root =btrfs_get_fs_root (fs_info, subvolid, true);if (IS_ERR (subvol_root)) { ret =PTR_ERR (subvol_root);if (ret == -ENOENT ) - ret =1 ; - goto out; +return 1 ; +return ret; }switch (type) {
@@ -257,7 +253,7 @@ static int btrfs_check_uuid_tree_entry(struct btrfs_fs_info *fs_info,break ; }btrfs_put_root (subvol_root); -out: +return ret; }
Signature · 1 line
2.47.2
PATCH 10/19 btrfs: remove out label in load_extent_tree_free()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/block-group.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/btrfs/block-group.c +4 -6
@@ -760,7 +760,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) next: ret =btrfs_search_slot (NULL , extent_root, &key, path,0 ,0 );if (ret <0 ) - goto out; +return ret; leaf = path->nodes[0 ]; nritems =btrfs_header_nritems (leaf);
@@ -791,7 +791,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) ret =btrfs_next_leaf (extent_root, path);if (ret <0 ) - goto out; +return ret;if (ret)break ; leaf = path->nodes[0 ];
@@ -822,7 +822,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) ret =btrfs_add_new_free_space (block_group, last, key.objectid, &space_added);if (ret) - goto out; +return ret; total_found += space_added;if (key.type ==BTRFS_METADATA_ITEM_KEY ) last = key.objectid +
@@ -841,9 +841,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) path->slots[0 ]++; } - ret =btrfs_add_new_free_space (block_group, last, block_group_end,NULL ); -out: -return ret; +return btrfs_add_new_free_space (block_group, last, block_group_end,NULL ); }static inline void btrfs_free_excluded_extents (const struct btrfs_block_group *bg)
Signature · 1 line
2.47.2
PATCH 11/19 btrfs: remove out_failed label in find_lock_delalloc_range()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'found' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/extent_io.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/extent_io.c +2 -3
@@ -440,8 +440,7 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode, loops =1 ; goto again; }else { - found = false; - goto out_failed; +return false; } }
@@ -461,7 +460,7 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode, } *start = delalloc_start; *end = delalloc_end; -out_failed: +return found; }
Signature · 1 line
2.47.2
PATCH 12/19 btrfs: remove out label in btrfs_csum_file_blocks()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/file-item.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/btrfs/file-item.c +8 -8
@@ -1134,7 +1134,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, } ret =PTR_ERR (item);if (ret != -EFBIG && ret != -ENOENT ) - goto out; +return ret;if (ret == -EFBIG ) {u32 item_size;
@@ -1150,7 +1150,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,/* We didn't find a csum item, insert one. */ ret =find_next_csum_offset (root, path, &next_offset);if (ret <0 ) - goto out; +return ret; found_next =1 ; goto insert; }
@@ -1178,7 +1178,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, csum_size, 1); path->search_for_extension = false;if (ret <0 ) - goto out; +return ret;if (ret >0 ) {if (path->slots[0 ] ==0 )
@@ -1234,14 +1234,14 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, btrfs_header_nritems(path->nodes[0])) { ret =find_next_csum_offset (root, path, &next_offset);if (ret <0 ) - goto out; +return ret; found_next =1 ; goto insert; } ret =find_next_csum_offset (root, path, &next_offset);if (ret <0 ) - goto out; +return ret; tmp = (next_offset - bytenr) >> fs_info->sectorsize_bits;if (tmp <=INT_MAX )
@@ -1282,7 +1282,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ret =btrfs_insert_empty_item (trans, root, path, &file_key, ins_size);if (ret <0 ) - goto out; +return ret; leaf = path->nodes[0 ]; csum: item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_csum_item);
@@ -1307,8 +1307,8 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,cond_resched (); goto again; } -out: -return ret; + +return 0 ; } void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
Signature · 1 line
2.47.2
PATCH 13/19 btrfs: remove out label in btrfs_mark_extent_written()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/file.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
fs/btrfs/file.c +15 -15
@@ -565,7 +565,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,int del_nr =0 ;int del_slot =0 ;int recow; -int ret =0 ; +int ret;u64 ino =btrfs_ino (inode); path =btrfs_alloc_path ();
@@ -580,7 +580,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ret =btrfs_search_slot (trans, root, &key, path,-1 ,1 );if (ret <0 ) - goto out; +return ret;if (ret >0 && path->slots[0 ] >0 ) path->slots[0 ]--;
@@ -589,20 +589,20 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,if (unlikely (key.objectid != ino || key.type !=BTRFS_EXTENT_DATA_KEY )) { ret = -EINVAL ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } fi =btrfs_item_ptr (leaf, path->slots[0 ], struct btrfs_file_extent_item);if (unlikely (btrfs_file_extent_type (leaf, fi) !=BTRFS_FILE_EXTENT_PREALLOC )) { ret = -EINVAL ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } extent_end = key.offset +btrfs_file_extent_num_bytes (leaf, fi);if (unlikely (key.offset > start || extent_end < end)) { ret = -EINVAL ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } bytenr =btrfs_file_extent_disk_bytenr (leaf, fi);
@@ -632,7 +632,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, trans->transid);btrfs_set_file_extent_num_bytes (leaf, fi, end - other_start); - goto out; +return 0 ; } }
@@ -660,7 +660,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, other_end - start);btrfs_set_file_extent_offset (leaf, fi, start - orig_offset); - goto out; +return 0 ; } }
@@ -676,7 +676,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, }if (unlikely (ret <0 )) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; } leaf = path->nodes[0 ];
@@ -704,7 +704,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ret =btrfs_inc_extent_ref (trans, &ref);if (unlikely (ret)) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; }if (split == start) {
@@ -713,7 +713,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,if (unlikely (start != key.offset)) { ret = -EINVAL ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } path->slots[0 ]--; extent_end = end;
@@ -744,7 +744,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ret =btrfs_free_extent (trans, &ref);if (unlikely (ret)) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; } } other_start =0 ;
@@ -762,7 +762,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ret =btrfs_free_extent (trans, &ref);if (unlikely (ret)) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; } }if (del_nr ==0 ) {
@@ -783,11 +783,11 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ret =btrfs_del_items (trans, root, path, del_slot, del_nr);if (unlikely (ret <0 )) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; } } -out: -return ret; + +return 0 ; }/*
Signature · 1 line
2.47.2
PATCH 14/19 btrfs: remove out label in lzo_decompress()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/lzo.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
fs/btrfs/lzo.c +6 -9
@@ -486,7 +486,7 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in,size_t in_len;size_t out_len;size_t max_segment_len =workspace_buf_length (fs_info); -int ret =0 ; +int ret;if (unlikely (srclen <LZO_LEN || srclen > max_segment_len +LZO_LEN *2 ))return -EUCLEAN ;
@@ -497,10 +497,8 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in, data_in +=LZO_LEN ; in_len =read_compress_length (data_in); -if (unlikely (in_len != srclen -LZO_LEN *2 )) { - ret = -EUCLEAN ; - goto out; - } +if (unlikely (in_len != srclen -LZO_LEN *2 )) +return -EUCLEAN ; data_in +=LZO_LEN ; out_len = sectorsize;
@@ -512,8 +510,7 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in,"lzo decompression failed, error %d root %llu inode %llu offset %llu" , ret,btrfs_root_id (inode->root),btrfs_ino (inode), folio_pos(dest_folio)); - ret = -EIO ; - goto out; +return -EIO ; }ASSERT (out_len <= sectorsize);
@@ -523,8 +520,8 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in, ret = -EIO ;folio_zero_range (dest_folio, dest_pgoff + out_len, destlen - out_len); } -out: -return ret; + +return 0 ; }const struct btrfs_compress_levels btrfs_lzo_compress = {
Signature · 1 line
2.47.2
PATCH 15/19 btrfs: remove out label in scrub_find_fill_first_stripe()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/scrub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/scrub.c +4 -4
@@ -1696,7 +1696,7 @@ static int scrub_find_fill_first_stripe(struct btrfs_block_group *bg, logical_len);/* Either error or not found. */ if (ret) - goto out; +return ret;get_extent_info (extent_path, &extent_start, &extent_len, &extent_flags, &extent_gen);if (extent_flags &BTRFS_EXTENT_FLAG_TREE_BLOCK )
@@ -1729,7 +1729,7 @@ static int scrub_find_fill_first_stripe(struct btrfs_block_group *bg, ret =find_first_extent_item (extent_root, extent_path, cur_logical, stripe_end - cur_logical +1 );if (ret <0 ) - goto out; +return ret;if (ret >0 ) { ret =0 ;break ;
@@ -1763,7 +1763,7 @@ static int scrub_find_fill_first_stripe(struct btrfs_block_group *bg, stripe->logical, stripe_end, stripe->csums, &csum_bitmap);if (ret <0 ) - goto out; +return ret;if (ret >0 ) ret =0 ;
@@ -1773,7 +1773,7 @@ static int scrub_find_fill_first_stripe(struct btrfs_block_group *bg, } }set_bit (SCRUB_STRIPE_FLAG_INITIALIZED , &stripe->state); -out: +return ret; }
Signature · 1 line
2.47.2
PATCH 16/19 btrfs: remove out label in finish_verity()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/verity.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
fs/btrfs/verity.c +5 -8
@@ -525,23 +525,21 @@ static int finish_verity(struct btrfs_inode *inode, const void *desc, ret =write_key_bytes (inode,BTRFS_VERITY_DESC_ITEM_KEY ,0 , (const char *)&item,sizeof (item));if (ret) - goto out; +return ret;/* Write out the descriptor itself */ ret =write_key_bytes (inode,BTRFS_VERITY_DESC_ITEM_KEY ,1 , desc, desc_size);if (ret) - goto out; +return ret;/* * 1 for updating the inode flag * 1 for deleting the orphan */ trans =btrfs_start_transaction (root,2 ); -if (IS_ERR (trans)) { - ret =PTR_ERR (trans); - goto out; - } +if (IS_ERR (trans)) +return PTR_ERR (trans); inode->ro_flags |=BTRFS_INODE_RO_VERITY ;btrfs_sync_inode_flags_to_i_flags (inode); ret =btrfs_update_inode (trans, inode);
@@ -554,8 +552,7 @@ static int finish_verity(struct btrfs_inode *inode, const void *desc,btrfs_set_fs_compat_ro (root->fs_info,VERITY ); end_trans:btrfs_end_transaction (trans); -out: -return ret; +return 0 ; }
Signature · 1 line
2.47.2
Re: [PATCH 16/19] btrfs: remove out label in finish_verity()
Quoted 5 lines · [email protected] wrote:
From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
Hi everyone,
I'm running the btrfs for-next branch, along with the encryption patch set through my AI review prompts:
https://github.com/masoncl/review-prompts
I'm working on some btrfs specific instructions, but hopefully these reviews are already useful. I've kept the headers to make it easier to double check that I'm actually replying to the right email, but please let me know if any parts of this are incorrect:
commit 61fb7f04ee06e6c7e113a490af1a057f958f1d05
Author: Filipe Manana <[email protected]>
btrfs: remove out label in finish_verity()
This commit refactors the finish_verity() function by removing the 'out' label and making error paths return directly. The goal is to simplify the control flow.
Quoted 4 lines
fs/btrfs/verity.c +0
-0
[ ... ]
fs/btrfs/verity.c static int finish_verity(struct btrfs_inode *inode, const void *desc, · line 556
Quoted 8 lines
fs/btrfs/verity.c +1
-2@@ -554,8 +552,7 @@ static int finish_verity(struct btrfs_inode *inode, const void *desc,btrfs_set_fs_compat_ro (root->fs_info,VERITY ); end_trans:btrfs_end_transaction (trans); -out: -return ret; +return 0 ;
Does this change introduce an error handling regression? When btrfs_update_inode() or del_orphan() fail (lines 546, 549), execution jumps to the end_trans label which now returns 0 instead of returning the error code in 'ret'.
Looking at btrfs_end_enable_verity() at line 632:
ret = finish_verity(inode, desc, desc_size);
if (ret)
goto rollback;If finish_verity incorrectly returns 0 on these failures, the caller will not trigger its rollback mechanism, leaving the inode in an inconsistent state. The verity flag changes (BTRFS_INODE_RO_VERITY set at line 543) would not be persisted to disk and the orphan item would not be properly removed.
The original code correctly returned 'ret' via the 'out' label. Should the end_trans label also return 'ret' instead of 0?
Quoted 1 line
fs/btrfs/verity.c +0
-0}
Re: [PATCH 16/19] btrfs: remove out label in finish_verity()
Quoted 36 lines · Chris Mason
Quoted 5 lines · [email protected] wrote:
From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
Hi everyone,
I'm running the btrfs for-next branch, along with the encryption patch set through my AI review prompts:
https://github.com/masoncl/review-prompts
I'm working on some btrfs specific instructions, but hopefully these reviews are already useful. I've kept the headers to make it easier to double check that I'm actually replying to the right email, but please let me know if any parts of this are incorrect:
commit
61fb7f04ee06e6c7e113a490af1a057f958f1d05
Author: Filipe Manana <[email protected]>btrfs: remove out label in
finish_verity()This commit refactors the
finish_verity()function by removing the 'out' label and making error paths return directly. The goal is to simplify the control flow.Quoted 4 lines
fs/btrfs/verity.c +0
-0[ ... ]
Quoted 13 lines
fs/btrfs/verity.c static int finish_verity(struct btrfs_inode *inode, const void *desc, · line 556
Quoted 8 lines
fs/btrfs/verity.c +1
-2@@ -554,8 +552,7 @@ static int finish_verity(struct btrfs_inode *inode, const void *desc,btrfs_set_fs_compat_ro (root->fs_info,VERITY ); end_trans:btrfs_end_transaction (trans); -out: -return ret; +return 0 ;Does this change introduce an error handling regression? When
btrfs_update_inode()ordel_orphan()fail (lines 546, 549), execution jumps to theend_translabel which now returns 0 instead of returning the error code in 'ret'.
Correct, fix sent here:
Thanks.
Quoted 18 lines
Looking at
btrfs_end_enable_verity()at line 632:ret = finish_verity(inode, desc, desc_size); if (ret) goto rollback;If
finish_verityincorrectly returns 0 on these failures, the caller will not trigger its rollback mechanism, leaving the inode in an inconsistent state. The verity flag changes (BTRFS_INODE_RO_VERITYset at line 543) would not be persisted to disk and the orphan item would not be properly removed.The original code correctly returned 'ret' via the 'out' label. Should the
end_translabel also return 'ret' instead of 0?Quoted 1 line
fs/btrfs/verity.c +0
-0}
PATCH 17/19 btrfs: remove out label in btrfs_check_rw_degradable()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/volumes.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
fs/btrfs/volumes.c +5 -7
@@ -7576,10 +7576,9 @@ bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info, map =btrfs_find_chunk_map (fs_info,0 ,U64_MAX );/* No chunk at all? Return false anyway */ -if (!map) { - ret = false; - goto out; - } +if (!map) +return false; +while (map) {int missing =0 ;int max_tolerated;
@@ -7604,15 +7603,14 @@ bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,"chunk %llu missing %d devices, max tolerance is %d for writable mount" , map->start, missing, max_tolerated);btrfs_free_chunk_map (map); - ret = false; - goto out; +return false; } next_start = map->start + map->chunk_len;btrfs_free_chunk_map (map); map =btrfs_find_chunk_map (fs_info, next_start,U64_MAX - next_start); } -out: +return ret; }
Signature · 1 line
2.47.2
PATCH 18/19 btrfs: remove out label in btrfs_init_space_info()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/space-info.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
fs/btrfs/space-info.c +6 -7
@@ -329,7 +329,7 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info)struct btrfs_super_block *disk_super;u64 features;u64 flags; -int mixed =0 ; +bool mixed = false;int ret; disk_super = fs_info->super_copy;
@@ -338,28 +338,28 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info) features =btrfs_super_incompat_flags (disk_super);if (features &BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS ) - mixed =1 ; + mixed = true; flags =BTRFS_BLOCK_GROUP_SYSTEM ; ret =create_space_info (fs_info, flags);if (ret) - goto out; +return ret;if (mixed) { flags =BTRFS_BLOCK_GROUP_METADATA |BTRFS_BLOCK_GROUP_DATA ; ret =create_space_info (fs_info, flags);if (ret) - goto out; +return ret; }else { flags =BTRFS_BLOCK_GROUP_METADATA ; ret =create_space_info (fs_info, flags);if (ret) - goto out; +return ret; flags =BTRFS_BLOCK_GROUP_DATA ; ret =create_space_info (fs_info, flags);if (ret) - goto out; +return ret; }if (features &BTRFS_FEATURE_INCOMPAT_REMAP_TREE ) {
@@ -367,7 +367,6 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info) ret =create_space_info (fs_info, flags); } -out:return ret; }
Signature · 1 line
2.47.2
PATCH 19/19 btrfs: remove out label in btrfs_wait_for_commit()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/transaction.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/transaction.c +5 -4
@@ -950,7 +950,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid)if (transid) {if (transid <=btrfs_get_last_trans_committed (fs_info)) - goto out; +return 0 ;/* find specified transaction */ spin_lock (&fs_info->trans_lock);
@@ -975,7 +975,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid)if (!cur_trans) {if (transid >btrfs_get_last_trans_committed (fs_info)) ret = -EINVAL ; - goto out; +return ret; } }else {/* find newest transaction that is committing | committed */
@@ -991,14 +991,15 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid) } }spin_unlock (&fs_info->trans_lock); +/* Nothing committing or committed. */ if (!cur_trans) - goto out;/* nothing committing|committed */ +return ret; }wait_for_commit (cur_trans,TRANS_STATE_COMPLETED ); ret = cur_trans->aborted;btrfs_put_transaction (cur_trans); -out: +return ret; }
Signature · 1 line
2.47.2
v2 cover btrfs: fix a return value and remove pointless labels and gotos
In reply to [email protected]From: Filipe Manana <[email protected]>
Remove pointless labels and gotos that can be replaced with a single "return ret" or "return -SOMEERROR", making the code shorter and more straighforward to follow and to not leave such examples for people to copy and keep repeating it. The first patch fixes a bug in an error path where we can end up returning success (0) instead of an error.
V2: Fix a couple wrong return values in send.c and lzo.c.
Filipe Manana (19):
btrfs: qgroup: return correct error when deleting qgroup relation item
btrfs: remove pointless out labels from ioctl.c
btrfs: remove pointless out labels from send.c
btrfs: remove pointless out labels from qgroup.c
btrfs: remove pointless out labels from disk-io.c
btrfs: remove pointless out labels from extent-tree.c
btrfs: remove pointless out labels from free-space-cache.c
btrfs: remove pointless out labels from inode.c
btrfs: remove pointless out labels from uuid-tree.c
btrfs: remove out label in load_extent_tree_free()
btrfs: remove out_failed label in find_lock_delalloc_range()
btrfs: remove out label in btrfs_csum_file_blocks()
btrfs: remove out label in btrfs_mark_extent_written()
btrfs: remove out label in lzo_decompress()
btrfs: remove out label in scrub_find_fill_first_stripe()
btrfs: remove out label in finish_verity()
btrfs: remove out label in btrfs_check_rw_degradable()
btrfs: remove out label in btrfs_init_space_info()
btrfs: remove out label in btrfs_wait_for_commit()
fs/btrfs/block-group.c | 10 ++--- fs/btrfs/disk-io.c | 54 +++++++++++--------------- fs/btrfs/extent-tree.c | 24 +++++------- fs/btrfs/extent_io.c | 5 +-- fs/btrfs/file-item.c | 16 ++++---- fs/btrfs/file.c | 30 +++++++-------- fs/btrfs/free-space-cache.c | 28 ++++++-------- fs/btrfs/inode.c | 21 +++++----- fs/btrfs/ioctl.c | 44 +++++++++------------ fs/btrfs/lzo.c | 17 ++++----- fs/btrfs/qgroup.c | 22 +++++------ fs/btrfs/scrub.c | 8 ++-- fs/btrfs/send.c | 76 ++++++++++++++++--------------------- fs/btrfs/space-info.c | 13 +++---- fs/btrfs/transaction.c | 9 +++-- fs/btrfs/uuid-tree.c | 16 +++----- fs/btrfs/verity.c | 13 +++---- fs/btrfs/volumes.c | 12 +++--- 18 files changed, 179 insertions(+), 239 deletions(-)
Signature · 1 line
2.47.2
PATCH v2 1/19 btrfs: qgroup: return correct error when deleting qgroup relation item
From: Filipe Manana <[email protected]>
If we fail to delete the second qgroup relation item, we end up returning success or -ENOENT in case the first item does not exist, instead of returning the error from the second item deletion.
--- fs/btrfs/qgroup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/qgroup.c +3 -1
@@ -1640,8 +1640,10 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src,if (ret <0 && ret != -ENOENT ) goto out; ret2 =del_qgroup_relation_item (trans, dst, src); -if (ret2 <0 && ret2 != -ENOENT ) +if (ret2 <0 && ret2 != -ENOENT ) { + ret = ret2; goto out; + }/* At least one deletion succeeded, return 0 */ if (!ret || !ret2)
Signature · 1 line
2.47.2
PATCH v2 2/19 btrfs: remove pointless out labels from ioctl.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (__btrfs_ioctl_snap_create(), btrfs_ioctl_subvol_setflags() and copy_to_sk()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting up the 'ret' variable.
--- fs/btrfs/ioctl.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-)
fs/btrfs/ioctl.c +17 -27
@@ -1176,7 +1176,7 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,bool readonly, struct btrfs_qgroup_inherit *inherit) { - int ret = 0; + int ret;struct qstr qname =QSTR_INIT (name,strlen (name));if (!S_ISDIR (file_inode (file)->i_mode))
@@ -1184,7 +1184,7 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file, ret =mnt_want_write_file (file);if (ret) - goto out; +return ret;if (strchr (name,'/' )) { ret = -EINVAL ;
@@ -1236,7 +1236,6 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file, } out_drop_write:mnt_drop_write_file (file); -out:return ret; }
@@ -1352,14 +1351,14 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,struct btrfs_trans_handle *trans;u64 root_flags;u64 flags; -int ret =0 ; +int ret;if (!inode_owner_or_capable (file_mnt_idmap (file), inode))return -EPERM ; ret =mnt_want_write_file (file);if (ret) - goto out; +return ret;if (btrfs_ino (BTRFS_I (inode)) !=BTRFS_FIRST_FREE_OBJECTID ) { ret = -EINVAL ;
@@ -1428,7 +1427,6 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,up_write (&fs_info->subvol_sem); out_drop_write:mnt_drop_write_file (file); -out:return ret; }
@@ -1494,10 +1492,8 @@ static noinline int copy_to_sk(struct btrfs_path *path,continue ;if (sizeof (sh) + item_len > *buf_size) { -if (*num_found) { - ret =1 ; - goto out; - } +if (*num_found) +return 1 ;/* * return one empty item back for v1, which does not
@@ -1509,10 +1505,8 @@ static noinline int copy_to_sk(struct btrfs_path *path, ret = -EOVERFLOW ; } -if (sizeof (sh) + item_len + *sk_offset > *buf_size) { - ret =1 ; - goto out; - } +if (sizeof (sh) + item_len + *sk_offset > *buf_size) +return 1 ; sh.objectid = key->objectid; sh.type = key->type;
@@ -1526,10 +1520,8 @@ static noinline int copy_to_sk(struct btrfs_path *path,* problem. Otherwise we'll fault and then copy the buffer in * properly this next time through */ -if (copy_to_user_nofault (ubuf + *sk_offset, &sh,sizeof (sh))) { - ret =0 ; - goto out; - } +if (copy_to_user_nofault (ubuf + *sk_offset, &sh,sizeof (sh))) +return 0 ; *sk_offset +=sizeof (sh);
@@ -1541,22 +1533,20 @@ static noinline int copy_to_sk(struct btrfs_path *path,*/ if (read_extent_buffer_to_user_nofault (leaf, up, item_off, item_len)) { - ret =0 ; *sk_offset -=sizeof (sh); - goto out; +return 0 ; } *sk_offset += item_len; } (*num_found)++; -if (ret)/* -EOVERFLOW from above */ - goto out; +/* -EOVERFLOW from above. */ +if (ret) +return ret; -if (*num_found >= sk->nr_items) { - ret =1 ; - goto out; - } +if (*num_found >= sk->nr_items) +return 1 ; } advance_key: ret =0 ;
@@ -1576,7 +1566,7 @@ static noinline int copy_to_sk(struct btrfs_path *path, key->objectid++; }else ret =1 ; -out: +/* * 0: all items from this leaf copied, continue with next * 1: * more items can be copied, but unused buffer is too small
Signature · 1 line
2.47.2
PATCH v2 3/19 btrfs: remove pointless out labels from send.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (process_extent(), process_recorded_refs_if_needed(), changed_inode(), compare_refs() and changed_cb()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/send.c | 76 +++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 43 deletions(-)
fs/btrfs/send.c +33 -43
@@ -6449,11 +6449,9 @@ static int process_extent(struct send_ctx *sctx,if (sctx->parent_root && !sctx->cur_inode_new) { ret =is_extent_unchanged (sctx, path, key);if (ret <0 ) - goto out; -if (ret) { - ret =0 ; +return ret; +if (ret) goto out_hole; - } }else {struct btrfs_file_extent_item *ei;u8 type;
@@ -6469,31 +6467,25 @@ static int process_extent(struct send_ctx *sctx,* we have enough commands queued up to justify rev'ing * the send spec. */ -if (type ==BTRFS_FILE_EXTENT_PREALLOC ) { - ret =0 ; - goto out; - } +if (type ==BTRFS_FILE_EXTENT_PREALLOC ) +return 0 ;/* Have a hole, just skip it. */ -if (btrfs_file_extent_disk_bytenr (path->nodes[0 ], ei) ==0 ) { - ret =0 ; - goto out; - } +if (btrfs_file_extent_disk_bytenr (path->nodes[0 ], ei) ==0 ) +return 0 ; } } ret =find_extent_clone (sctx, path, key->objectid, key->offset, sctx->cur_inode_size, &found_clone);if (ret != -ENOENT && ret <0 ) - goto out; +return ret; ret =send_write_or_clone (sctx, path, key, found_clone);if (ret) - goto out; +return ret; out_hole: - ret =maybe_send_hole (sctx, path, key); -out: -return ret; +return maybe_send_hole (sctx, path, key); }static int process_all_extents (struct send_ctx *sctx)
@@ -6535,23 +6527,24 @@ static int process_recorded_refs_if_needed(struct send_ctx *sctx, bool at_end,int *pending_move, int *refs_processed) { - int ret = 0; + int ret;if (sctx->cur_ino ==0 ) - goto out; +return 0 ; +if (!at_end && sctx->cur_ino == sctx->cmp_key->objectid && sctx->cmp_key->type <=BTRFS_INODE_EXTREF_KEY ) - goto out; +return 0 ; +if (list_empty (&sctx->new_refs) &&list_empty (&sctx->deleted_refs)) - goto out; +return 0 ; ret =process_recorded_refs (sctx, pending_move);if (ret <0 ) - goto out; +return ret; *refs_processed =1 ; -out: -return ret; +return 0 ; }static int finish_inode_if_needed (struct send_ctx *sctx,bool at_end)
@@ -6768,7 +6761,7 @@ static void close_current_inode(struct send_ctx *sctx)static int changed_inode (struct send_ctx *sctx,enum btrfs_compare_tree_result result) { -int ret =0 ; +int ret;struct btrfs_key *key = sctx->cmp_key;struct btrfs_inode_item *left_ii =NULL ;struct btrfs_inode_item *right_ii =NULL ;
@@ -6860,7 +6853,7 @@ static int changed_inode(struct send_ctx *sctx,if (result ==BTRFS_COMPARE_TREE_NEW ) {if (btrfs_inode_nlink (sctx->left_path->nodes[0 ], left_ii) ==0 ) { sctx->ignore_cur_inode = true; - goto out; +return 0 ; } sctx->cur_inode_gen = left_gen; sctx->cur_inode_new = true;
@@ -6888,7 +6881,7 @@ static int changed_inode(struct send_ctx *sctx, old_nlinks =btrfs_inode_nlink (sctx->right_path->nodes[0 ], right_ii);if (new_nlinks ==0 && old_nlinks ==0 ) { sctx->ignore_cur_inode = true; - goto out; +return 0 ; }else if (new_nlinks ==0 || old_nlinks ==0 ) { sctx->cur_inode_new_gen =1 ; }
@@ -6914,7 +6907,7 @@ static int changed_inode(struct send_ctx *sctx, ret =process_all_refs (sctx,BTRFS_COMPARE_TREE_DELETED );if (ret <0 ) - goto out; +return ret; }/*
@@ -6935,11 +6928,11 @@ static int changed_inode(struct send_ctx *sctx, left_ii); ret =send_create_inode_if_needed (sctx);if (ret <0 ) - goto out; +return ret; ret =process_all_refs (sctx,BTRFS_COMPARE_TREE_NEW );if (ret <0 ) - goto out; +return ret;/* * Advance send_progress now as we did not get * into process_recorded_refs_if_needed in the
@@ -6953,10 +6946,10 @@ static int changed_inode(struct send_ctx *sctx,*/ ret =process_all_extents (sctx);if (ret <0 ) - goto out; +return ret; ret =process_all_new_xattrs (sctx);if (ret <0 ) - goto out; +return ret; } }else { sctx->cur_inode_gen = left_gen;
@@ -6970,8 +6963,7 @@ static int changed_inode(struct send_ctx *sctx, } } -out: -return ret; +return 0 ; }/*
@@ -7104,20 +7096,20 @@ static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path,u32 item_size;u32 cur_offset =0 ;int ref_name_len; -int ret =0 ;/* Easy case, just check this one dirid */ if (key->type ==BTRFS_INODE_REF_KEY ) { dirid = key->offset; - ret =dir_changed (sctx, dirid); - goto out; +return dir_changed (sctx, dirid); } leaf = path->nodes[0 ]; item_size =btrfs_item_size (leaf, path->slots[0 ]); ptr =btrfs_item_ptr_offset (leaf, path->slots[0 ]);while (cur_offset < item_size) { +int ret; + extref = (struct btrfs_inode_extref *)(ptr + cur_offset); dirid =btrfs_inode_extref_parent (leaf, extref);
@@ -7127,11 +7119,10 @@ static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path,continue ; ret =dir_changed (sctx, dirid);if (ret) -break ; +return ret; last_dirid = dirid; } -out: -return ret; +return 0 ; }/*
@@ -7212,12 +7203,12 @@ static int changed_cb(struct btrfs_path *left_path, ret =finish_inode_if_needed (sctx,0 );if (ret <0 ) - goto out; +return ret;/* Ignore non-FS objects */ if (key->objectid ==BTRFS_FREE_INO_OBJECTID || key->objectid ==BTRFS_FREE_SPACE_OBJECTID ) - goto out; +return 0 ;if (key->type ==BTRFS_INODE_ITEM_KEY ) { ret =changed_inode (sctx, result);
@@ -7234,7 +7225,6 @@ static int changed_cb(struct btrfs_path *left_path, ret =changed_verity (sctx, result); } -out:return ret; }
Signature · 1 line
2.47.2
PATCH v2 4/19 btrfs: remove pointless out labels from qgroup.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (__del_qgroup_relation() and qgroup_trace_new_subtree_blocks()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/qgroup.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
fs/btrfs/qgroup.c +10 -16
@@ -1613,10 +1613,8 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src,int ret =0 ;int ret2; -if (!fs_info->quota_root) { - ret = -ENOTCONN ; - goto out; - } +if (!fs_info->quota_root) +return -ENOTCONN ; member =find_qgroup_rb (fs_info, src); parent =find_qgroup_rb (fs_info, dst);
@@ -1638,12 +1636,10 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src, delete_item: ret =del_qgroup_relation_item (trans, src, dst);if (ret <0 && ret != -ENOENT ) - goto out; +return ret; ret2 =del_qgroup_relation_item (trans, dst, src); -if (ret2 <0 && ret2 != -ENOENT ) { - ret = ret2; - goto out; - } +if (ret2 <0 && ret2 != -ENOENT ) +return ret2;/* At least one deletion succeeded, return 0 */ if (!ret || !ret2)
@@ -1657,7 +1653,7 @@ static int __del_qgroup_relation(struct btrfs_trans_handle *trans, u64 src,squota_check_parent_usage (fs_info, parent);spin_unlock (&fs_info->qgroup_lock); } -out: +return ret; }
@@ -2490,13 +2486,11 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans,/* This node is old, no need to trace */ if (child_gen < last_snapshot) - goto out; +return ret; eb =btrfs_read_node_slot (eb, parent_slot); -if (IS_ERR (eb)) { - ret =PTR_ERR (eb); - goto out; - } +if (IS_ERR (eb)) +return PTR_ERR (eb); dst_path->nodes[cur_level] = eb; dst_path->slots[cur_level] =0 ;
@@ -2541,7 +2535,7 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans, dst_path->slots[cur_level] =0 ; dst_path->locks[cur_level] =0 ; } -out: +return ret; }
Signature · 1 line
2.47.2
PATCH v2 5/19 btrfs: remove pointless out labels from disk-io.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (btrfs_validate_extent_buffer() and btrfs_start_pre_rw_mount()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/disk-io.c | 54 +++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 32 deletions(-)
fs/btrfs/disk-io.c +22 -32
@@ -369,22 +369,19 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,btrfs_err_rl (fs_info,"bad tree block start, mirror %u want %llu have %llu" , eb->read_mirror, eb->start, found_start); - ret = -EIO ; - goto out; +return -EIO ; }if (unlikely (check_tree_block_fsid (eb))) {btrfs_err_rl (fs_info,"bad fsid on logical %llu mirror %u" , eb->start, eb->read_mirror); - ret = -EIO ; - goto out; +return -EIO ; } found_level =btrfs_header_level (eb);if (unlikely (found_level >=BTRFS_MAX_LEVEL )) {btrfs_err (fs_info,"bad tree block level, mirror %u level %d on logical %llu" , eb->read_mirror,btrfs_header_level (eb), eb->start); - ret = -EIO ; - goto out; +return -EIO ; }csum_tree_block (eb, result);
@@ -399,18 +396,15 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,BTRFS_CSUM_FMT_VALUE (csum_size, result),btrfs_header_level (eb), ignore_csum ? ", ignored" : ""); -if (unlikely (!ignore_csum)) { - ret = -EUCLEAN ; - goto out; - } +if (unlikely (!ignore_csum)) +return -EUCLEAN ; }if (unlikely (found_level != check->level)) {btrfs_err (fs_info,"level verify failed on logical %llu mirror %u wanted %u found %u" , eb->start, eb->read_mirror, check->level, found_level); - ret = -EIO ; - goto out; +return -EIO ; }if (unlikely (check->transid &&btrfs_header_generation (eb) != check->transid)) {
@@ -418,8 +412,7 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,"parent transid verify failed on logical %llu mirror %u wanted %llu found %llu" , eb->start, eb->read_mirror, check->transid, btrfs_header_generation(eb)); - ret = -EIO ; - goto out; +return -EIO ; }if (check->has_first_key) {const struct btrfs_key *expect_key = &check->first_key;
@@ -437,14 +430,13 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb, expect_key->type, expect_key->offset, found_key.objectid, found_key.type, found_key.offset); - ret = -EUCLEAN ; - goto out; +return -EUCLEAN ; } }if (check->owner_root) { ret =btrfs_check_eb_owner (eb, check->owner_root);if (ret <0 ) - goto out; +return ret; }/* If this is a leaf block and it is corrupt, just return -EIO. */
@@ -458,7 +450,6 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb,btrfs_err (fs_info,"read time tree block corruption detected on logical %llu mirror %u" , eb->start, eb->read_mirror); -out:return ret; }
@@ -3075,7 +3066,7 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)if (ret) {btrfs_warn (fs_info,"failed to rebuild free space tree: %d" , ret); - goto out; +return ret; } }
@@ -3086,7 +3077,7 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)if (ret) {btrfs_warn (fs_info,"failed to disable free space tree: %d" , ret); - goto out; +return ret; } }
@@ -3097,7 +3088,7 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info) ret =btrfs_delete_orphan_free_space_entries (fs_info);if (ret <0 ) {btrfs_err (fs_info,"failed to delete orphan free space tree entries: %d" , ret); - goto out; +return ret; }/* * btrfs_find_orphan_roots() is responsible for finding all the dead
@@ -3112,17 +3103,17 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)*/ ret =btrfs_find_orphan_roots (fs_info);if (ret) - goto out; +return ret; ret =btrfs_cleanup_fs_roots (fs_info);if (ret) - goto out; +return ret;down_read (&fs_info->cleanup_work_sem);if ((ret =btrfs_orphan_cleanup (fs_info->fs_root)) || (ret =btrfs_orphan_cleanup (fs_info->tree_root))) {up_read (&fs_info->cleanup_work_sem); - goto out; +return ret; }up_read (&fs_info->cleanup_work_sem);
@@ -3131,7 +3122,7 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)mutex_unlock (&fs_info->cleaner_mutex);if (ret <0 ) {btrfs_warn (fs_info,"failed to recover relocation: %d" , ret); - goto out; +return ret; } if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) &&
@@ -3141,24 +3132,24 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)if (ret) {btrfs_warn (fs_info,"failed to create free space tree: %d" , ret); - goto out; +return ret; } }if (cache_opt !=btrfs_free_space_cache_v1_active (fs_info)) { ret =btrfs_set_free_space_cache_v1_active (fs_info, cache_opt);if (ret) - goto out; +return ret; } ret =btrfs_resume_balance_async (fs_info);if (ret) - goto out; +return ret; ret =btrfs_resume_dev_replace_async (fs_info);if (ret) {btrfs_warn (fs_info,"failed to resume dev_replace" ); - goto out; +return ret; }btrfs_qgroup_rescan_resume (fs_info);
@@ -3169,12 +3160,11 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)if (ret) {btrfs_warn (fs_info,"failed to create the UUID tree %d" , ret); - goto out; +return ret; } } -out: -return ret; +return 0 ; }/*
Signature · 1 line
2.47.2
PATCH v2 6/19 btrfs: remove pointless out labels from extent-tree.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (lookup_extent_data_ref(), __btrfs_mod_ref() and btrfs_free_tree_block()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/extent-tree.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
fs/btrfs/extent-tree.c +10 -14
@@ -477,7 +477,7 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,btrfs_item_key_to_cpu (leaf, &key, path->slots[0 ]);if (key.objectid != bytenr || key.type !=BTRFS_EXTENT_DATA_REF_KEY ) - goto fail; +return ret; ref =btrfs_item_ptr (leaf, path->slots[0 ], struct btrfs_extent_data_ref);
@@ -488,12 +488,11 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,btrfs_release_path (path); goto again; } - ret =0 ; -break ; +return 0 ; } path->slots[0 ]++; } -fail: +return ret; }
@@ -2501,7 +2500,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,int i;int action;int level; -int ret =0 ; +int ret;if (btrfs_is_testing (fs_info))return 0 ;
@@ -2553,7 +2552,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,else ret =btrfs_free_extent (trans, &ref);if (ret) - goto fail; +return ret; }else {/* We don't know the owning_root, leave as 0. */ ref.bytenr =btrfs_node_blockptr (buf, i);
@@ -2566,12 +2565,10 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,else ret =btrfs_free_extent (trans, &ref);if (ret) - goto fail; +return ret; } }return 0 ; -fail: -return ret; } int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
@@ -3575,12 +3572,12 @@ int btrfs_free_tree_block(struct btrfs_trans_handle *trans,return 0 ;if (btrfs_header_generation (buf) != trans->transid) - goto out; +return 0 ;if (root_id !=BTRFS_TREE_LOG_OBJECTID ) { ret =check_ref_cleanup (trans, buf->start);if (!ret) - goto out; +return 0 ; } bg =btrfs_lookup_block_group (fs_info, buf->start);
@@ -3588,7 +3585,7 @@ int btrfs_free_tree_block(struct btrfs_trans_handle *trans,if (btrfs_header_flag (buf,BTRFS_HEADER_FLAG_WRITTEN )) {pin_down_extent (trans, bg, buf->start, buf->len, true);btrfs_put_block_group (bg); - goto out; +return 0 ; }/*
@@ -3612,7 +3609,7 @@ int btrfs_free_tree_block(struct btrfs_trans_handle *trans, || btrfs_is_zoned(fs_info)) {pin_down_extent (trans, bg, buf->start, buf->len, true);btrfs_put_block_group (bg); - goto out; +return 0 ; }WARN_ON (test_bit (EXTENT_BUFFER_DIRTY , &buf->bflags));
@@ -3622,7 +3619,6 @@ int btrfs_free_tree_block(struct btrfs_trans_handle *trans,btrfs_put_block_group (bg);trace_btrfs_reserved_extent_free (fs_info, buf->start, buf->len); -out:return 0 ; }
Signature · 1 line
2.47.2
PATCH v2 7/19 btrfs: remove pointless out labels from free-space-cache.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (update_cache_item(), find_free_space(), trim_bitmaps(), btrfs_remove_free_space() and cleanup_free_space_cache_v1()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/free-space-cache.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)
fs/btrfs/free-space-cache.c +12 -16
@@ -1162,7 +1162,7 @@ update_cache_item(struct btrfs_trans_handle *trans,if (ret <0 ) {btrfs_clear_extent_bit (&BTRFS_I (inode)->io_tree,0 , inode->i_size -1 ,EXTENT_DELALLOC ,NULL ); - goto fail; +return ret; } leaf = path->nodes[0 ];if (ret >0 ) {
@@ -1176,7 +1176,7 @@ update_cache_item(struct btrfs_trans_handle *trans, inode->i_size -1 ,EXTENT_DELALLOC , NULL);btrfs_release_path (path); - goto fail; +return -ENOENT ; } }
@@ -1189,9 +1189,6 @@ update_cache_item(struct btrfs_trans_handle *trans,btrfs_release_path (path);return 0 ; - -fail: -return -1 ; } static noinline_for_stack int write_pinned_extent_entries(
@@ -2017,7 +2014,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes,int ret;if (!ctl->free_space_offset.rb_node) - goto out; +return NULL ; again:if (use_bytes_index) { node =rb_first_cached (&ctl->free_space_bytes);
@@ -2025,7 +2022,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, entry =tree_search_offset (ctl,offset_to_bitmap (ctl, *offset),0 ,1 );if (!entry) - goto out; +return NULL ; node = &entry->offset_index; }
@@ -2109,7 +2106,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, *bytes = entry->bytes - align_off;return entry; } -out: +return NULL ; }
@@ -2894,7 +2891,7 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group, old_end - (offset + bytes), info->trim_state);WARN_ON (ret); - goto out; +return ret; } }
@@ -2906,7 +2903,7 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group, out_lock:btrfs_discard_update_discardable (block_group);spin_unlock (&ctl->tree_lock); -out: +return ret; }
@@ -4007,7 +4004,7 @@ static int trim_bitmaps(struct btrfs_block_group *block_group,if (async && *total_trimmed) {spin_unlock (&ctl->tree_lock);mutex_unlock (&ctl->cache_writeout_mutex); - goto out; +return ret; } bytes =min (bytes, end - start);
@@ -4068,7 +4065,6 @@ static int trim_bitmaps(struct btrfs_block_group *block_group,if (offset >= end) block_group->discard_cursor = end; -out:return ret; }
@@ -4161,20 +4157,20 @@ static int cleanup_free_space_cache_v1(struct btrfs_fs_info *fs_info, {struct btrfs_block_group *block_group;struct rb_node *node; -int ret =0 ;btrfs_info (fs_info,"cleaning free space cache v1" ); node =rb_first_cached (&fs_info->block_group_cache_tree);while (node) { +int ret; + block_group = rb_entry(node, struct btrfs_block_group, cache_node); ret =btrfs_remove_free_space_inode (trans,NULL , block_group);if (ret) - goto out; +return ret; node =rb_next (node); } -out: -return ret; +return 0 ; }int btrfs_set_free_space_cache_v1_active (struct btrfs_fs_info *fs_info,bool active)
Signature · 1 line
2.47.2
PATCH v2 8/19 btrfs: remove pointless out labels from inode.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (insert_inline_extent() and insert_reserved_file_extent()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/inode.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
fs/btrfs/inode.c +9 -12
@@ -507,7 +507,7 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans, ret =btrfs_insert_empty_item (trans, root, path, &key, datasize);if (ret) - goto fail; +return ret; } leaf = path->nodes[0 ]; ei = btrfs_item_ptr(leaf, path->slots[0],
@@ -546,7 +546,7 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans, ret =btrfs_inode_set_file_extent_range (inode,0 ,ALIGN (size, root->fs_info->sectorsize));if (ret) - goto fail; +return ret;/* * We're an inline extent, so nobody can extend the file past i_size
@@ -562,8 +562,7 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans, } inode->disk_i_size = i_size; -fail: -return ret; +return 0 ; } static bool can_cow_file_range_inline(struct btrfs_inode *inode,
@@ -3037,7 +3036,7 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, drop_args.extent_item_size =sizeof (*stack_fi); ret =btrfs_drop_extents (trans, root, inode, &drop_args);if (ret) - goto out; +return ret;if (!drop_args.extent_inserted) { ins.objectid =btrfs_ino (inode);
@@ -3047,7 +3046,7 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, ret =btrfs_insert_empty_item (trans, root, path, &ins,sizeof (*stack_fi));if (ret) - goto out; +return ret; } leaf = path->nodes[0 ];btrfs_set_stack_file_extent_generation (stack_fi, trans->transid);
@@ -3082,13 +3081,11 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, ret =btrfs_inode_set_file_extent_range (inode, file_pos, ram_bytes);if (ret) - goto out; +return ret; - ret =btrfs_alloc_reserved_file_extent (trans, root,btrfs_ino (inode), - file_pos - offset, - qgroup_reserved, &ins); -out: -return ret; +return btrfs_alloc_reserved_file_extent (trans, root,btrfs_ino (inode), + file_pos - offset, + qgroup_reserved, &ins); } static void btrfs_release_delalloc_bytes(struct btrfs_fs_info *fs_info,
Signature · 1 line
2.47.2
PATCH v2 9/19 btrfs: remove pointless out labels from uuid-tree.c
In reply to [email protected]From: Filipe Manana <[email protected]>
Some functions (btrfs_uuid_iter_rem() and btrfs_check_uuid_tree_entry()) have an 'out' label that does nothing but return, making it pointless. Simplify this by removing the label and returning instead of gotos plus setting the 'ret' variable.
--- fs/btrfs/uuid-tree.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
fs/btrfs/uuid-tree.c +6 -10
@@ -207,15 +207,11 @@ static int btrfs_uuid_iter_rem(struct btrfs_root *uuid_root, u8 *uuid, u8 type,/* 1 - for the uuid item */ trans =btrfs_start_transaction (uuid_root,1 ); -if (IS_ERR (trans)) { - ret =PTR_ERR (trans); - goto out; - } +if (IS_ERR (trans)) +return PTR_ERR (trans); ret =btrfs_uuid_tree_remove (trans, uuid, type, subid);btrfs_end_transaction (trans); - -out:return ret; }
@@ -235,14 +231,14 @@ static int btrfs_check_uuid_tree_entry(struct btrfs_fs_info *fs_info,if (type !=BTRFS_UUID_KEY_SUBVOL && type !=BTRFS_UUID_KEY_RECEIVED_SUBVOL ) - goto out; +return 0 ; subvol_root =btrfs_get_fs_root (fs_info, subvolid, true);if (IS_ERR (subvol_root)) { ret =PTR_ERR (subvol_root);if (ret == -ENOENT ) - ret =1 ; - goto out; +return 1 ; +return ret; }switch (type) {
@@ -257,7 +253,7 @@ static int btrfs_check_uuid_tree_entry(struct btrfs_fs_info *fs_info,break ; }btrfs_put_root (subvol_root); -out: +return ret; }
Signature · 1 line
2.47.2
PATCH v2 10/19 btrfs: remove out label in load_extent_tree_free()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/block-group.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/btrfs/block-group.c +4 -6
@@ -761,7 +761,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) next: ret =btrfs_search_slot (NULL , extent_root, &key, path,0 ,0 );if (ret <0 ) - goto out; +return ret; leaf = path->nodes[0 ]; nritems =btrfs_header_nritems (leaf);
@@ -792,7 +792,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) ret =btrfs_next_leaf (extent_root, path);if (ret <0 ) - goto out; +return ret;if (ret)break ; leaf = path->nodes[0 ];
@@ -823,7 +823,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) ret =btrfs_add_new_free_space (block_group, last, key.objectid, &space_added);if (ret) - goto out; +return ret; total_found += space_added;if (key.type ==BTRFS_METADATA_ITEM_KEY ) last = key.objectid +
@@ -842,9 +842,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl) path->slots[0 ]++; } - ret =btrfs_add_new_free_space (block_group, last, block_group_end,NULL ); -out: -return ret; +return btrfs_add_new_free_space (block_group, last, block_group_end,NULL ); }static inline void btrfs_free_excluded_extents (const struct btrfs_block_group *bg)
Signature · 1 line
2.47.2
PATCH v2 11/19 btrfs: remove out_failed label in find_lock_delalloc_range()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'found' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/extent_io.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/extent_io.c +2 -3
@@ -440,8 +440,7 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode, loops =1 ; goto again; }else { - found = false; - goto out_failed; +return false; } }
@@ -461,7 +460,7 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode, } *start = delalloc_start; *end = delalloc_end; -out_failed: +return found; }
Signature · 1 line
2.47.2
PATCH v2 12/19 btrfs: remove out label in btrfs_csum_file_blocks()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/file-item.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/btrfs/file-item.c +8 -8
@@ -1134,7 +1134,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, } ret =PTR_ERR (item);if (ret != -EFBIG && ret != -ENOENT ) - goto out; +return ret;if (ret == -EFBIG ) {u32 item_size;
@@ -1150,7 +1150,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,/* We didn't find a csum item, insert one. */ ret =find_next_csum_offset (root, path, &next_offset);if (ret <0 ) - goto out; +return ret; found_next =1 ; goto insert; }
@@ -1178,7 +1178,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, csum_size, 1); path->search_for_extension = false;if (ret <0 ) - goto out; +return ret;if (ret >0 ) {if (path->slots[0 ] ==0 )
@@ -1234,14 +1234,14 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, btrfs_header_nritems(path->nodes[0])) { ret =find_next_csum_offset (root, path, &next_offset);if (ret <0 ) - goto out; +return ret; found_next =1 ; goto insert; } ret =find_next_csum_offset (root, path, &next_offset);if (ret <0 ) - goto out; +return ret; tmp = (next_offset - bytenr) >> fs_info->sectorsize_bits;if (tmp <=INT_MAX )
@@ -1282,7 +1282,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ret =btrfs_insert_empty_item (trans, root, path, &file_key, ins_size);if (ret <0 ) - goto out; +return ret; leaf = path->nodes[0 ]; csum: item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_csum_item);
@@ -1307,8 +1307,8 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,cond_resched (); goto again; } -out: -return ret; + +return 0 ; } void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
Signature · 1 line
2.47.2
PATCH v2 13/19 btrfs: remove out label in btrfs_mark_extent_written()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/file.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
fs/btrfs/file.c +15 -15
@@ -565,7 +565,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,int del_nr =0 ;int del_slot =0 ;int recow; -int ret =0 ; +int ret;u64 ino =btrfs_ino (inode); path =btrfs_alloc_path ();
@@ -580,7 +580,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ret =btrfs_search_slot (trans, root, &key, path,-1 ,1 );if (ret <0 ) - goto out; +return ret;if (ret >0 && path->slots[0 ] >0 ) path->slots[0 ]--;
@@ -589,20 +589,20 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,if (unlikely (key.objectid != ino || key.type !=BTRFS_EXTENT_DATA_KEY )) { ret = -EINVAL ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } fi =btrfs_item_ptr (leaf, path->slots[0 ], struct btrfs_file_extent_item);if (unlikely (btrfs_file_extent_type (leaf, fi) !=BTRFS_FILE_EXTENT_PREALLOC )) { ret = -EINVAL ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } extent_end = key.offset +btrfs_file_extent_num_bytes (leaf, fi);if (unlikely (key.offset > start || extent_end < end)) { ret = -EINVAL ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } bytenr =btrfs_file_extent_disk_bytenr (leaf, fi);
@@ -632,7 +632,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, trans->transid);btrfs_set_file_extent_num_bytes (leaf, fi, end - other_start); - goto out; +return 0 ; } }
@@ -660,7 +660,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, other_end - start);btrfs_set_file_extent_offset (leaf, fi, start - orig_offset); - goto out; +return 0 ; } }
@@ -676,7 +676,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, }if (unlikely (ret <0 )) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; } leaf = path->nodes[0 ];
@@ -704,7 +704,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ret =btrfs_inc_extent_ref (trans, &ref);if (unlikely (ret)) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; }if (split == start) {
@@ -713,7 +713,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,if (unlikely (start != key.offset)) { ret = -EINVAL ;btrfs_abort_transaction (trans, ret); - goto out; +return ret; } path->slots[0 ]--; extent_end = end;
@@ -744,7 +744,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ret =btrfs_free_extent (trans, &ref);if (unlikely (ret)) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; } } other_start =0 ;
@@ -762,7 +762,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ret =btrfs_free_extent (trans, &ref);if (unlikely (ret)) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; } }if (del_nr ==0 ) {
@@ -783,11 +783,11 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ret =btrfs_del_items (trans, root, path, del_slot, del_nr);if (unlikely (ret <0 )) {btrfs_abort_transaction (trans, ret); - goto out; +return ret; } } -out: -return ret; + +return 0 ; }/*
Signature · 1 line
2.47.2
PATCH v2 14/19 btrfs: remove out label in lzo_decompress()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/lzo.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
fs/btrfs/lzo.c +7 -10
@@ -486,7 +486,7 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in,size_t in_len;size_t out_len;size_t max_segment_len =workspace_buf_length (fs_info); -int ret =0 ; +int ret;if (unlikely (srclen <LZO_LEN || srclen > max_segment_len +LZO_LEN *2 ))return -EUCLEAN ;
@@ -497,10 +497,8 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in, data_in +=LZO_LEN ; in_len =read_compress_length (data_in); -if (unlikely (in_len != srclen -LZO_LEN *2 )) { - ret = -EUCLEAN ; - goto out; - } +if (unlikely (in_len != srclen -LZO_LEN *2 )) +return -EUCLEAN ; data_in +=LZO_LEN ; out_len = sectorsize;
@@ -512,19 +510,18 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in,"lzo decompression failed, error %d root %llu inode %llu offset %llu" , ret,btrfs_root_id (inode->root),btrfs_ino (inode), folio_pos(dest_folio)); - ret = -EIO ; - goto out; +return -EIO ; }ASSERT (out_len <= sectorsize);memcpy_to_folio (dest_folio, dest_pgoff, workspace->buf, out_len);/* Early end, considered as an error. */ if (unlikely (out_len < destlen)) { - ret = -EIO ;folio_zero_range (dest_folio, dest_pgoff + out_len, destlen - out_len); +return -EIO ; } -out: -return ret; + +return 0 ; }const struct btrfs_compress_levels btrfs_lzo_compress = {
Signature · 1 line
2.47.2
PATCH v2 15/19 btrfs: remove out label in scrub_find_fill_first_stripe()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/scrub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/scrub.c +4 -4
@@ -1696,7 +1696,7 @@ static int scrub_find_fill_first_stripe(struct btrfs_block_group *bg, logical_len);/* Either error or not found. */ if (ret) - goto out; +return ret;get_extent_info (extent_path, &extent_start, &extent_len, &extent_flags, &extent_gen);if (extent_flags &BTRFS_EXTENT_FLAG_TREE_BLOCK )
@@ -1729,7 +1729,7 @@ static int scrub_find_fill_first_stripe(struct btrfs_block_group *bg, ret =find_first_extent_item (extent_root, extent_path, cur_logical, stripe_end - cur_logical +1 );if (ret <0 ) - goto out; +return ret;if (ret >0 ) { ret =0 ;break ;
@@ -1763,7 +1763,7 @@ static int scrub_find_fill_first_stripe(struct btrfs_block_group *bg, stripe->logical, stripe_end, stripe->csums, &csum_bitmap);if (ret <0 ) - goto out; +return ret;if (ret >0 ) ret =0 ;
@@ -1773,7 +1773,7 @@ static int scrub_find_fill_first_stripe(struct btrfs_block_group *bg, } }set_bit (SCRUB_STRIPE_FLAG_INITIALIZED , &stripe->state); -out: +return ret; }
Signature · 1 line
2.47.2
PATCH v2 16/19 btrfs: remove out label in finish_verity()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/verity.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
fs/btrfs/verity.c +5 -8
@@ -525,23 +525,21 @@ static int finish_verity(struct btrfs_inode *inode, const void *desc, ret =write_key_bytes (inode,BTRFS_VERITY_DESC_ITEM_KEY ,0 , (const char *)&item,sizeof (item));if (ret) - goto out; +return ret;/* Write out the descriptor itself */ ret =write_key_bytes (inode,BTRFS_VERITY_DESC_ITEM_KEY ,1 , desc, desc_size);if (ret) - goto out; +return ret;/* * 1 for updating the inode flag * 1 for deleting the orphan */ trans =btrfs_start_transaction (root,2 ); -if (IS_ERR (trans)) { - ret =PTR_ERR (trans); - goto out; - } +if (IS_ERR (trans)) +return PTR_ERR (trans); inode->ro_flags |=BTRFS_INODE_RO_VERITY ;btrfs_sync_inode_flags_to_i_flags (inode); ret =btrfs_update_inode (trans, inode);
@@ -554,8 +552,7 @@ static int finish_verity(struct btrfs_inode *inode, const void *desc,btrfs_set_fs_compat_ro (root->fs_info,VERITY ); end_trans:btrfs_end_transaction (trans); -out: -return ret; +return 0 ; }
Signature · 1 line
2.47.2
PATCH v2 17/19 btrfs: remove out label in btrfs_check_rw_degradable()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/volumes.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
fs/btrfs/volumes.c +5 -7
@@ -7576,10 +7576,9 @@ bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info, map =btrfs_find_chunk_map (fs_info,0 ,U64_MAX );/* No chunk at all? Return false anyway */ -if (!map) { - ret = false; - goto out; - } +if (!map) +return false; +while (map) {int missing =0 ;int max_tolerated;
@@ -7604,15 +7603,14 @@ bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,"chunk %llu missing %d devices, max tolerance is %d for writable mount" , map->start, missing, max_tolerated);btrfs_free_chunk_map (map); - ret = false; - goto out; +return false; } next_start = map->start + map->chunk_len;btrfs_free_chunk_map (map); map =btrfs_find_chunk_map (fs_info, next_start,U64_MAX - next_start); } -out: +return ret; }
Signature · 1 line
2.47.2
PATCH v2 18/19 btrfs: remove out label in btrfs_init_space_info()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/space-info.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
fs/btrfs/space-info.c +6 -7
@@ -329,7 +329,7 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info)struct btrfs_super_block *disk_super;u64 features;u64 flags; -int mixed =0 ; +bool mixed = false;int ret; disk_super = fs_info->super_copy;
@@ -338,28 +338,28 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info) features =btrfs_super_incompat_flags (disk_super);if (features &BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS ) - mixed =1 ; + mixed = true; flags =BTRFS_BLOCK_GROUP_SYSTEM ; ret =create_space_info (fs_info, flags);if (ret) - goto out; +return ret;if (mixed) { flags =BTRFS_BLOCK_GROUP_METADATA |BTRFS_BLOCK_GROUP_DATA ; ret =create_space_info (fs_info, flags);if (ret) - goto out; +return ret; }else { flags =BTRFS_BLOCK_GROUP_METADATA ; ret =create_space_info (fs_info, flags);if (ret) - goto out; +return ret; flags =BTRFS_BLOCK_GROUP_DATA ; ret =create_space_info (fs_info, flags);if (ret) - goto out; +return ret; }if (features &BTRFS_FEATURE_INCOMPAT_REMAP_TREE ) {
@@ -367,7 +367,6 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info) ret =create_space_info (fs_info, flags); } -out:return ret; }
Signature · 1 line
2.47.2
PATCH v2 19/19 btrfs: remove out label in btrfs_wait_for_commit()
In reply to [email protected]From: Filipe Manana <[email protected]>
There is no point in having the label since all it does is return the value in the 'ret' variable. Instead make every goto return directly and remove the label.
--- fs/btrfs/transaction.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/transaction.c +5 -4
@@ -950,7 +950,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid)if (transid) {if (transid <=btrfs_get_last_trans_committed (fs_info)) - goto out; +return 0 ;/* find specified transaction */ spin_lock (&fs_info->trans_lock);
@@ -975,7 +975,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid)if (!cur_trans) {if (transid >btrfs_get_last_trans_committed (fs_info)) ret = -EINVAL ; - goto out; +return ret; } }else {/* find newest transaction that is committing | committed */
@@ -991,14 +991,15 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid) } }spin_unlock (&fs_info->trans_lock); +/* Nothing committing or committed. */ if (!cur_trans) - goto out;/* nothing committing|committed */ +return ret; }wait_for_commit (cur_trans,TRANS_STATE_COMPLETED ); ret = cur_trans->aborted;btrfs_put_transaction (cur_trans); -out: +return ret; }
Signature · 1 line
2.47.2
Quoted 42 lines · On 1/21/26 8:00 PM, [email protected] wrote:
From: Filipe Manana <[email protected]>
Remove pointless labels and gotos that can be replaced with a single "return ret" or "return -SOMEERROR", making the code shorter and more straighforward to follow and to not leave such examples for people to copy and keep repeating it. The first patch fixes a bug in an error path where we can end up returning success (0) instead of an error.
V2: Fix a couple wrong return values in
send.candlzo.c.Filipe Manana (19):
btrfs: qgroup: return correct error when deleting qgroup relation item
btrfs: remove pointless out labels fromioctl.c
btrfs: remove pointless out labels fromsend.c
btrfs: remove pointless out labels fromqgroup.c
btrfs: remove pointless out labels fromdisk-io.c
btrfs: remove pointless out labels fromextent-tree.c
btrfs: remove pointless out labels fromfree-space-cache.c
btrfs: remove pointless out labels frominode.c
btrfs: remove pointless out labels fromuuid-tree.c
btrfs: remove out label inload_extent_tree_free()
btrfs: removeout_failedlabel infind_lock_delalloc_range()
btrfs: remove out label inbtrfs_csum_file_blocks()
btrfs: remove out label inbtrfs_mark_extent_written()
btrfs: remove out label inlzo_decompress()
btrfs: remove out label inscrub_find_fill_first_stripe()
btrfs: remove out label infinish_verity()
btrfs: remove out label inbtrfs_check_rw_degradable()
btrfs: remove out label inbtrfs_init_space_info()
btrfs: remove out label inbtrfs_wait_for_commit()fs/btrfs/block-group.c | 10 ++--- fs/btrfs/disk-io.c | 54 +++++++++++--------------- fs/btrfs/extent-tree.c | 24 +++++------- fs/btrfs/extent_io.c | 5 +-- fs/btrfs/file-item.c | 16 ++++---- fs/btrfs/file.c | 30 +++++++-------- fs/btrfs/free-space-cache.c | 28 ++++++-------- fs/btrfs/inode.c | 21 +++++----- fs/btrfs/ioctl.c | 44 +++++++++------------ fs/btrfs/lzo.c | 17 ++++----- fs/btrfs/qgroup.c | 22 +++++------
Quoted 9 lines
fs/btrfs/scrub.c | 8 ++-- fs/btrfs/send.c | 76 ++++++++++++++++--------------------- fs/btrfs/space-info.c | 13 +++---- fs/btrfs/transaction.c | 9 +++-- fs/btrfs/uuid-tree.c | 16 +++----- fs/btrfs/verity.c | 13 +++---- fs/btrfs/volumes.c | 12 +++--- 18 files changed, 179 insertions(+), 239 deletions(-)
Looks good,
Would be nice though if there would be consistent newlines after each return statement.