diff mbox series

[v2,06/11] btrfs: btrfs_recover_relocation rename ret to ret2 and err to ret

Message ID a98d6d4d3ac16aaf0e464dfeb9551b4c141a13f0.1713370757.git.anand.jain@oracle.com (mailing list archive)
State New
Headers show
Series part2 trivial adjustments for return variable coding style | expand

Commit Message

Anand Jain April 18, 2024, 7:08 a.m. UTC
Fix the code style for the return variable. First, rename ret to ret2,
compile it, and then rename err to ret. This method of changing helped
confirm that there are no instances of the old ret not renamed to ret2.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: no change from v1

 fs/btrfs/relocation.c | 64 +++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

Comments

David Sterba April 19, 2024, 5:12 p.m. UTC | #1
On Thu, Apr 18, 2024 at 03:08:38PM +0800, Anand Jain wrote:
> Fix the code style for the return variable. First, rename ret to ret2,
> compile it, and then rename err to ret. This method of changing helped
> confirm that there are no instances of the old ret not renamed to ret2.

There's only one place where the ret2 would make sense.

> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v2: no change from v1
> 
>  fs/btrfs/relocation.c | 64 +++++++++++++++++++++----------------------
>  1 file changed, 32 insertions(+), 32 deletions(-)
> 
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index bd573a0ec270..0b802d0c5a65 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -4222,8 +4222,8 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  	struct extent_buffer *leaf;
>  	struct reloc_control *rc = NULL;
>  	struct btrfs_trans_handle *trans;
> -	int ret;
> -	int err = 0;
> +	int ret2;
> +	int ret = 0;
>  
>  	path = btrfs_alloc_path();
>  	if (!path)
> @@ -4235,13 +4235,13 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  	key.offset = (u64)-1;
>  
>  	while (1) {
> -		ret = btrfs_search_slot(NULL, fs_info->tree_root, &key,
> +		ret2 = btrfs_search_slot(NULL, fs_info->tree_root, &key,
>  					path, 0, 0);
> -		if (ret < 0) {
> -			err = ret;
> +		if (ret2 < 0) {
> +			ret = ret2;

If you do just ret = ret2 then it's not needed, ret is always reset and
then is some check and 'goto out'. Using ret2 should be only for cases
where the previous value must be preserved.

>  			goto out;
>  		}
> -		if (ret > 0) {
> +		if (ret2 > 0) {
>  			if (path->slots[0] == 0)
>  				break;
>  			path->slots[0]--;
> @@ -4256,7 +4256,7 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  
>  		reloc_root = btrfs_read_tree_root(fs_info->tree_root, &key);
>  		if (IS_ERR(reloc_root)) {
> -			err = PTR_ERR(reloc_root);
> +			ret = PTR_ERR(reloc_root);
>  			goto out;
>  		}
>  
> @@ -4267,14 +4267,14 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  			fs_root = btrfs_get_fs_root(fs_info,
>  					reloc_root->root_key.offset, false);
>  			if (IS_ERR(fs_root)) {
> -				ret = PTR_ERR(fs_root);
> -				if (ret != -ENOENT) {
> -					err = ret;
> +				ret2 = PTR_ERR(fs_root);
> +				if (ret2 != -ENOENT) {
> +					ret = ret2;

Same.

>  					goto out;
>  				}
> -				ret = mark_garbage_root(reloc_root);
> -				if (ret < 0) {
> -					err = ret;
> +				ret2 = mark_garbage_root(reloc_root);
> +				if (ret2 < 0) {
> +					ret = ret2;

And here.

>  					goto out;
>  				}
>  			} else {
> @@ -4294,13 +4294,13 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  
>  	rc = alloc_reloc_control(fs_info);
>  	if (!rc) {
> -		err = -ENOMEM;
> +		ret = -ENOMEM;
>  		goto out;
>  	}
>  
> -	ret = reloc_chunk_start(fs_info);
> -	if (ret < 0) {
> -		err = ret;
> +	ret2 = reloc_chunk_start(fs_info);
> +	if (ret2 < 0) {
> +		ret = ret2;
>  		goto out_end;
>  	}
>  
> @@ -4310,7 +4310,7 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  
>  	trans = btrfs_join_transaction(rc->extent_root);
>  	if (IS_ERR(trans)) {
> -		err = PTR_ERR(trans);
> +		ret = PTR_ERR(trans);
>  		goto out_unset;
>  	}
>  
> @@ -4330,15 +4330,15 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  		fs_root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
>  					    false);
>  		if (IS_ERR(fs_root)) {
> -			err = PTR_ERR(fs_root);
> +			ret = PTR_ERR(fs_root);
>  			list_add_tail(&reloc_root->root_list, &reloc_roots);
>  			btrfs_end_transaction(trans);
>  			goto out_unset;
>  		}
>  
> -		err = __add_reloc_root(reloc_root);
> -		ASSERT(err != -EEXIST);
> -		if (err) {
> +		ret = __add_reloc_root(reloc_root);
> +		ASSERT(ret != -EEXIST);
> +		if (ret) {
>  			list_add_tail(&reloc_root->root_list, &reloc_roots);
>  			btrfs_put_root(fs_root);
>  			btrfs_end_transaction(trans);
> @@ -4348,8 +4348,8 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  		btrfs_put_root(fs_root);
>  	}
>  
> -	err = btrfs_commit_transaction(trans);
> -	if (err)
> +	ret = btrfs_commit_transaction(trans);
> +	if (ret)
>  		goto out_unset;
>  
>  	merge_reloc_roots(rc);
> @@ -4358,14 +4358,14 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
>  
>  	trans = btrfs_join_transaction(rc->extent_root);
>  	if (IS_ERR(trans)) {
> -		err = PTR_ERR(trans);
> +		ret = PTR_ERR(trans);
>  		goto out_clean;
>  	}
> -	err = btrfs_commit_transaction(trans);
> +	ret = btrfs_commit_transaction(trans);
>  out_clean:
> -	ret = clean_dirty_subvols(rc);
> -	if (ret < 0 && !err)
> -		err = ret;
> +	ret2 = clean_dirty_subvols(rc);
> +	if (ret2 < 0 && !ret)
> +		ret = ret2;

This is probably the only place where it makes sense but only because
the original code does not directly handle btrfs_commit_transaction()
and calls clean_dirty_subvols(), so the two values have to be checked.

Changing the logic here should be a separate patch so ret2 can stay
otherwise the whole function can use single ret for everything as far as
I can see.
diff mbox series

Patch

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index bd573a0ec270..0b802d0c5a65 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -4222,8 +4222,8 @@  int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
 	struct extent_buffer *leaf;
 	struct reloc_control *rc = NULL;
 	struct btrfs_trans_handle *trans;
-	int ret;
-	int err = 0;
+	int ret2;
+	int ret = 0;
 
 	path = btrfs_alloc_path();
 	if (!path)
@@ -4235,13 +4235,13 @@  int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
 	key.offset = (u64)-1;
 
 	while (1) {
-		ret = btrfs_search_slot(NULL, fs_info->tree_root, &key,
+		ret2 = btrfs_search_slot(NULL, fs_info->tree_root, &key,
 					path, 0, 0);
-		if (ret < 0) {
-			err = ret;
+		if (ret2 < 0) {
+			ret = ret2;
 			goto out;
 		}
-		if (ret > 0) {
+		if (ret2 > 0) {
 			if (path->slots[0] == 0)
 				break;
 			path->slots[0]--;
@@ -4256,7 +4256,7 @@  int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
 
 		reloc_root = btrfs_read_tree_root(fs_info->tree_root, &key);
 		if (IS_ERR(reloc_root)) {
-			err = PTR_ERR(reloc_root);
+			ret = PTR_ERR(reloc_root);
 			goto out;
 		}
 
@@ -4267,14 +4267,14 @@  int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
 			fs_root = btrfs_get_fs_root(fs_info,
 					reloc_root->root_key.offset, false);
 			if (IS_ERR(fs_root)) {
-				ret = PTR_ERR(fs_root);
-				if (ret != -ENOENT) {
-					err = ret;
+				ret2 = PTR_ERR(fs_root);
+				if (ret2 != -ENOENT) {
+					ret = ret2;
 					goto out;
 				}
-				ret = mark_garbage_root(reloc_root);
-				if (ret < 0) {
-					err = ret;
+				ret2 = mark_garbage_root(reloc_root);
+				if (ret2 < 0) {
+					ret = ret2;
 					goto out;
 				}
 			} else {
@@ -4294,13 +4294,13 @@  int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
 
 	rc = alloc_reloc_control(fs_info);
 	if (!rc) {
-		err = -ENOMEM;
+		ret = -ENOMEM;
 		goto out;
 	}
 
-	ret = reloc_chunk_start(fs_info);
-	if (ret < 0) {
-		err = ret;
+	ret2 = reloc_chunk_start(fs_info);
+	if (ret2 < 0) {
+		ret = ret2;
 		goto out_end;
 	}
 
@@ -4310,7 +4310,7 @@  int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
 
 	trans = btrfs_join_transaction(rc->extent_root);
 	if (IS_ERR(trans)) {
-		err = PTR_ERR(trans);
+		ret = PTR_ERR(trans);
 		goto out_unset;
 	}
 
@@ -4330,15 +4330,15 @@  int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
 		fs_root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
 					    false);
 		if (IS_ERR(fs_root)) {
-			err = PTR_ERR(fs_root);
+			ret = PTR_ERR(fs_root);
 			list_add_tail(&reloc_root->root_list, &reloc_roots);
 			btrfs_end_transaction(trans);
 			goto out_unset;
 		}
 
-		err = __add_reloc_root(reloc_root);
-		ASSERT(err != -EEXIST);
-		if (err) {
+		ret = __add_reloc_root(reloc_root);
+		ASSERT(ret != -EEXIST);
+		if (ret) {
 			list_add_tail(&reloc_root->root_list, &reloc_roots);
 			btrfs_put_root(fs_root);
 			btrfs_end_transaction(trans);
@@ -4348,8 +4348,8 @@  int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
 		btrfs_put_root(fs_root);
 	}
 
-	err = btrfs_commit_transaction(trans);
-	if (err)
+	ret = btrfs_commit_transaction(trans);
+	if (ret)
 		goto out_unset;
 
 	merge_reloc_roots(rc);
@@ -4358,14 +4358,14 @@  int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
 
 	trans = btrfs_join_transaction(rc->extent_root);
 	if (IS_ERR(trans)) {
-		err = PTR_ERR(trans);
+		ret = PTR_ERR(trans);
 		goto out_clean;
 	}
-	err = btrfs_commit_transaction(trans);
+	ret = btrfs_commit_transaction(trans);
 out_clean:
-	ret = clean_dirty_subvols(rc);
-	if (ret < 0 && !err)
-		err = ret;
+	ret2 = clean_dirty_subvols(rc);
+	if (ret2 < 0 && !ret)
+		ret = ret2;
 out_unset:
 	unset_reloc_control(rc);
 out_end:
@@ -4376,14 +4376,14 @@  int btrfs_recover_relocation(struct btrfs_fs_info *fs_info)
 
 	btrfs_free_path(path);
 
-	if (err == 0) {
+	if (ret == 0) {
 		/* cleanup orphan inode in data relocation tree */
 		fs_root = btrfs_grab_root(fs_info->data_reloc_root);
 		ASSERT(fs_root);
-		err = btrfs_orphan_cleanup(fs_root);
+		ret = btrfs_orphan_cleanup(fs_root);
 		btrfs_put_root(fs_root);
 	}
-	return err;
+	return ret;
 }
 
 /*