Skip to contentSkip to conversation

btrfs: send: Simplify send_create_inode_if_needed

PATCH In review Marcos Paulo de Souza 5 participants 5 messages Aug 1, 2021 – Aug 19, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: send: Simplify send_create_inode_if_needed

The out label is being overused, we can simply return if the condition permits.

No functional changes.

---
 fs/btrfs/send.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
fs/btrfs/send.c +4 -11
index 75cff564dedf..17cd67e41d3a 100644
@@ -2727,19 +2727,12 @@ static int send_create_inode_if_needed(struct send_ctx *sctx)
 	if (S_ISDIR(sctx->cur_inode_mode)) {
 		ret = did_create_dir(sctx, sctx->cur_ino);
 		if (ret < 0)
-			goto out;
-		if (ret) {
-			ret = 0;
-			goto out;
-		}
+			return ret;
+		if (ret > 0)
+			return 0;
 	}
 
-	ret = send_create_inode(sctx, sctx->cur_ino);
-	if (ret < 0)
-		goto out;
-
-out:
-	return ret;
+	return send_create_inode(sctx, sctx->cur_ino);
 }
 
 struct recorded_ref {
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Marcos Paulo de Souza

The out label is being overused, we can simply return if the condition permits.

No functional changes.

--
Su

Quoted 33 lines
---
 fs/btrfs/send.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
fs/btrfs/send.c +4 -11
index 75cff564dedf..17cd67e41d3a 100644
@@ -2727,19 +2727,12 @@ static int 
 send_create_inode_if_needed(struct send_ctx *sctx)
 	if (S_ISDIR(sctx->cur_inode_mode)) {
 		ret = did_create_dir(sctx, sctx->cur_ino);
 		if (ret < 0)
-			goto out;
-		if (ret) {
-			ret = 0;
-			goto out;
-		}
+			return ret;
+		if (ret > 0)
+			return 0;
 	}
 
-	ret = send_create_inode(sctx, sctx->cur_ino);
-	if (ret < 0)
-		goto out;
-
-out:
-	return ret;
+	return send_create_inode(sctx, sctx->cur_ino);
 }
 

struct recorded_ref {

Reviewed-by on v1 1/1
#2 lore raw
In reply to Marcos Paulo de Souza
Quoted 6 lines · Marcos Paulo de Souza

The out label is being overused, we can simply return if the condition permits.

No functional changes.

Quoted 10 lines
---
 fs/btrfs/send.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
fs/btrfs/send.c +0 -0
index 75cff564dedf..17cd67e41d3a 100644
@@ -2727,19 +2727,12 @@ static int send_create_inode_if_needed(struct send_ctx *sctx)
 	if (S_ISDIR(sctx->cur_inode_mode)) {

fs/btrfs/send.c static int send_create_inode_if_needed(struct send_ctx *sctx) · line 2732

Quoted 10 lines
fs/btrfs/send.c +3 -5
 		ret = did_create_dir(sctx, sctx->cur_ino);
 		if (ret < 0)
-			goto out;
-		if (ret) {
-			ret = 0;
-			goto out;
-		}
+			return ret;
+		if (ret > 0)
+			return 0;

nit: Personally I'd prefer in such cases to use an if/else if construct since which branch is taken is dependent on the same value. To me using an if/else if is a more explicit way to say "those 2 branches are directly related). However it's not a big deal.

Quoted 13 lines
fs/btrfs/send.c +1 -6
 	}
 
-	ret = send_create_inode(sctx, sctx->cur_ino);
-	if (ret < 0)
-		goto out;
-
-out:
-	return ret;
+	return send_create_inode(sctx, sctx->cur_ino);
 }
 
 struct recorded_ref {
#3 lore raw
Quoted 31 lines · Nikolay Borisov
Quoted 7 lines · Marcos Paulo de Souza

The out label is being overused, we can simply return if the condition
permits.

No functional changes.

Quoted 20 lines
---
 fs/btrfs/send.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
fs/btrfs/send.c +2 -5
index 75cff564dedf..17cd67e41d3a 100644
@@ -2727,19 +2727,12 @@ static int
 send_create_inode_if_needed(struct send_ctx *sctx)
 	if (S_ISDIR(sctx->cur_inode_mode)) {
 		ret = did_create_dir(sctx, sctx->cur_ino);
 		if (ret < 0)
-			goto out;
-		if (ret) {
-			ret = 0;
-			goto out;
-		}
+			return ret;
+		if (ret > 0)
Quoted 8 lines

fs/btrfs/send.c static int send_create_inode_if_needed(struct send_ctx *sctx) · line 2732

Quoted 1 line
fs/btrfs/send.c +1 -0
+			return 0;

nit: Personally I'd prefer in such cases to use an if/else if construct
since which branch is taken is dependent on the same value. To me using
an if/else if is a more explicit way to say "those 2 branches are directly related). However it's not a big deal.

Indeed, it's better. Should I send a v2 in this case or david can just add an 'else' to the last if clause?

Thanks

Quoted 14 lines
Quoted 14 lines
fs/btrfs/send.c +1 -6
 	}
 
-	ret = send_create_inode(sctx, sctx->cur_ino);
-	if (ret < 0)
-		goto out;
-
-out:
-	return ret;
+	return send_create_inode(sctx, sctx->cur_ino);
 }
 

struct recorded_ref {