diff mbox series

[2/3] btrfs-progs: dump_super: drop the label out and variable ret

Message ID d59136fcbb28ead308886d5219ccb630530c4b37.1687854248.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: dump-super: fix dump-super on aarch64 | expand

Commit Message

Anand Jain June 27, 2023, 8:53 a.m. UTC
In cmd_inspect_dump_super(), at the label 'out', nothing much happens
other than returning ret.

At the goto statement to the label, in the for loop, we perform close(fd).
However, moving the close(fd) to 'out' as well is not a good idea because
close(fd) doesn't make sense outside the for loop.

Instead, simply return 1 instead of ret=1 and then returning it. Drop both
the 'out' label and ret.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds/inspect-dump-super.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

Comments

Qu Wenruo June 27, 2023, 9:16 a.m. UTC | #1
On 2023/6/27 16:53, Anand Jain wrote:
> In cmd_inspect_dump_super(), at the label 'out', nothing much happens
> other than returning ret.
>
> At the goto statement to the label, in the for loop, we perform close(fd).
> However, moving the close(fd) to 'out' as well is not a good idea because
> close(fd) doesn't make sense outside the for loop.
>
> Instead, simply return 1 instead of ret=1 and then returning it. Drop both
> the 'out' label and ret.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   cmds/inspect-dump-super.c | 13 ++++---------
>   1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/cmds/inspect-dump-super.c b/cmds/inspect-dump-super.c
> index 4529b2308d7e..f32c67fd5c4d 100644
> --- a/cmds/inspect-dump-super.c
> +++ b/cmds/inspect-dump-super.c
> @@ -84,7 +84,6 @@ static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
>   	char *filename;
>   	int fd = -1;
>   	int i;
> -	int ret = 0;
>   	u64 arg;
>   	u64 sb_bytenr = btrfs_sb_offset(0);
>
> @@ -156,8 +155,7 @@ static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
>   		fd = open(filename, O_RDONLY);
>   		if (fd < 0) {
>   			error("cannot open %s: %m", filename);
> -			ret = 1;
> -			goto out;
> +			return 1;
>   		}
>
>   		if (all) {
> @@ -168,8 +166,7 @@ static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
>   				if (load_and_dump_sb(filename, fd,
>   						sb_bytenr, full, force)) {
>   					close(fd);
> -					ret = 1;
> -					goto out;
> +					return 1;
>   				}
>
>   				putchar('\n');
> @@ -177,15 +174,13 @@ static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
>   		} else {
>   			if (load_and_dump_sb(filename, fd, sb_bytenr, full, force)) {
>   				close(fd);
> -				ret = 1;
> -				goto out;
> +				return 1;
>   			}
>   			putchar('\n');
>   		}
>   		close(fd);
>   	}
>
> -out:
> -	return ret;
> +	return 0;
>   }
>   DEFINE_SIMPLE_COMMAND(inspect_dump_super, "dump-super");
diff mbox series

Patch

diff --git a/cmds/inspect-dump-super.c b/cmds/inspect-dump-super.c
index 4529b2308d7e..f32c67fd5c4d 100644
--- a/cmds/inspect-dump-super.c
+++ b/cmds/inspect-dump-super.c
@@ -84,7 +84,6 @@  static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
 	char *filename;
 	int fd = -1;
 	int i;
-	int ret = 0;
 	u64 arg;
 	u64 sb_bytenr = btrfs_sb_offset(0);
 
@@ -156,8 +155,7 @@  static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
 		fd = open(filename, O_RDONLY);
 		if (fd < 0) {
 			error("cannot open %s: %m", filename);
-			ret = 1;
-			goto out;
+			return 1;
 		}
 
 		if (all) {
@@ -168,8 +166,7 @@  static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
 				if (load_and_dump_sb(filename, fd,
 						sb_bytenr, full, force)) {
 					close(fd);
-					ret = 1;
-					goto out;
+					return 1;
 				}
 
 				putchar('\n');
@@ -177,15 +174,13 @@  static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
 		} else {
 			if (load_and_dump_sb(filename, fd, sb_bytenr, full, force)) {
 				close(fd);
-				ret = 1;
-				goto out;
+				return 1;
 			}
 			putchar('\n');
 		}
 		close(fd);
 	}
 
-out:
-	return ret;
+	return 0;
 }
 DEFINE_SIMPLE_COMMAND(inspect_dump_super, "dump-super");