diff mbox series

[4/4] btrfs: replace unnecessary goto with direct return

Message ID 7ccae9fc6975246cbb2be58c83d9ca6e3fcbb123.1655391633.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

Commit Message

Naohiro Aota June 16, 2022, 3:45 p.m. UTC
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>
---
 fs/btrfs/inode.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Filipe Manana June 17, 2022, 10:13 a.m. UTC | #1
On Fri, Jun 17, 2022 at 12:45:42AM +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>

The subject is too generic, just adding "... at cow_file_range()" would make
it much more clear without being too long.

Thanks.

> ---
>  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 cae15924fc99..055c573e2eb3 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -1253,7 +1253,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;
>  		}
> @@ -1366,8 +1366,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);
> @@ -1425,7 +1424,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
>  					     page_ops);
>  		start += cur_alloc_size;
>  		if (start >= end)
> -			goto out;
> +			return ret;
>  	}
>  
>  	/*
> @@ -1437,7 +1436,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;
>  }
>  
>  /*
> -- 
> 2.35.1
>
Naohiro Aota June 20, 2022, 2:22 a.m. UTC | #2
On Fri, Jun 17, 2022 at 11:13:18AM +0100, Filipe Manana wrote:
> On Fri, Jun 17, 2022 at 12:45:42AM +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>
> 
> The subject is too generic, just adding "... at cow_file_range()" would make
> it much more clear without being too long.

Yeah, that sounds better. I'll rephrase the subject.

> Thanks.
> 
> > ---
> >  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 cae15924fc99..055c573e2eb3 100644
> > --- a/fs/btrfs/inode.c
> > +++ b/fs/btrfs/inode.c
> > @@ -1253,7 +1253,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;
> >  		}
> > @@ -1366,8 +1366,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);
> > @@ -1425,7 +1424,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
> >  					     page_ops);
> >  		start += cur_alloc_size;
> >  		if (start >= end)
> > -			goto out;
> > +			return ret;
> >  	}
> >  
> >  	/*
> > @@ -1437,7 +1436,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;
> >  }
> >  
> >  /*
> > -- 
> > 2.35.1
> >
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index cae15924fc99..055c573e2eb3 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1253,7 +1253,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;
 		}
@@ -1366,8 +1366,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);
@@ -1425,7 +1424,7 @@  static noinline int cow_file_range(struct btrfs_inode *inode,
 					     page_ops);
 		start += cur_alloc_size;
 		if (start >= end)
-			goto out;
+			return ret;
 	}
 
 	/*
@@ -1437,7 +1436,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;
 }
 
 /*