Message ID | a294ac30ec431016710e8dda1e778e18bfeff9c5.1655791781.git.naohiro.aota@wdc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: fix error handling of cow_file_range(unlock = 0) | expand |
On Tue, Jun 21, 2022 at 03:41:02PM +0900, Naohiro Aota wrote: > The "goto out;"s in cow_file_range() just results in a simple "return > ret;" which are not really useful. Replace them with proper direct > "return"s. It also makes the success path vs failure path stands out. > > Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> > Reviewed-by: Filipe Manana <fdmanana@suse.com> > --- > fs/btrfs/inode.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > index 38d8e6d78e77..b9633b35a35f 100644 > --- a/fs/btrfs/inode.c > +++ b/fs/btrfs/inode.c > @@ -1250,7 +1250,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, > * inline extent or a compressed extent. > */ > unlock_page(locked_page); > - goto out; > + return 0; This return is too easy to miss, I'd rather keep it there. This is the anti-pattern where there are gotos and returns mixed so it's not obvious what's the flow and breaks reading the function top-down. > } else if (ret < 0) { > goto out_unlock; > } > @@ -1359,8 +1359,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, > if (ret) > goto out_unlock; > } > -out: > - return ret; > + return 0; > > out_drop_extent_cache: > btrfs_drop_extent_cache(inode, start, start + ram_size - 1, 0); > @@ -1418,7 +1417,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, > page_ops); > start += cur_alloc_size; > if (start >= end) > - goto out; > + return ret; > } > > /* > @@ -1430,7 +1429,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, > extent_clear_unlock_delalloc(inode, start, end, locked_page, > clear_bits | EXTENT_CLEAR_DATA_RESV, > page_ops); > - goto out; > + return ret; These two are in the exit block, so jumping back is indeed worth cleaning up. > } > > /* > -- > 2.35.1
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 38d8e6d78e77..b9633b35a35f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1250,7 +1250,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, * inline extent or a compressed extent. */ unlock_page(locked_page); - goto out; + return 0; } else if (ret < 0) { goto out_unlock; } @@ -1359,8 +1359,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, if (ret) goto out_unlock; } -out: - return ret; + return 0; out_drop_extent_cache: btrfs_drop_extent_cache(inode, start, start + ram_size - 1, 0); @@ -1418,7 +1417,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, page_ops); start += cur_alloc_size; if (start >= end) - goto out; + return ret; } /* @@ -1430,7 +1429,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, extent_clear_unlock_delalloc(inode, start, end, locked_page, clear_bits | EXTENT_CLEAR_DATA_RESV, page_ops); - goto out; + return ret; } /*