Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1716421

[PATCH 3/5] btrfs: Use common error handling code in btrfs_update_root()

From SF Markus Elfring <elfring@users.sourceforge.net>
Newsgroups linux.kernel
Subject [PATCH 3/5] btrfs: Use common error handling code in btrfs_update_root()
Date 2017-08-21 14:50 +0200
Message-ID <ugUjx-4pR-31@gated-at.bofh.it> (permalink)
References <ugU9P-4ml-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 21 Aug 2017 13:10:15 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/btrfs/root-tree.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 5b488af6f25e..bc497ba9d9d1 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -145,10 +145,8 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
 		return -ENOMEM;
 
 	ret = btrfs_search_slot(trans, root, key, path, 0, 1);
-	if (ret < 0) {
-		btrfs_abort_transaction(trans, ret);
-		goto out;
-	}
+	if (ret < 0)
+		goto abort_transaction;
 
 	if (ret != 0) {
 		btrfs_print_leaf(path->nodes[0]);
@@ -171,23 +169,17 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
 		btrfs_release_path(path);
 		ret = btrfs_search_slot(trans, root, key, path,
 				-1, 1);
-		if (ret < 0) {
-			btrfs_abort_transaction(trans, ret);
-			goto out;
-		}
+		if (ret < 0)
+			goto abort_transaction;
 
 		ret = btrfs_del_item(trans, root, path);
-		if (ret < 0) {
-			btrfs_abort_transaction(trans, ret);
-			goto out;
-		}
+		if (ret < 0)
+			goto abort_transaction;
 		btrfs_release_path(path);
 		ret = btrfs_insert_empty_item(trans, root, path,
 				key, sizeof(*item));
-		if (ret < 0) {
-			btrfs_abort_transaction(trans, ret);
-			goto out;
-		}
+		if (ret < 0)
+			goto abort_transaction;
 		l = path->nodes[0];
 		slot = path->slots[0];
 		ptr = btrfs_item_ptr_offset(l, slot);
@@ -204,6 +196,9 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
 out:
 	btrfs_free_path(path);
 	return ret;
+abort_transaction:
+	btrfs_abort_transaction(trans, ret);
+	goto out;
 }
 
 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
-- 
2.14.0

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/5] BTRFS: Fine-tuning for five function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-21 14:40 +0200
  [PATCH 2/5] btrfs: Use common error handling code in  __btrfs_free_extent() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-21 14:40 +0200
    Re: [PATCH 2/5] btrfs: Use common error handling code in  __btrfs_free_extent() Jeff Mahoney <jeffm@suse.com> - 2017-08-21 15:10 +0200
      Re: [PATCH 2/5] btrfs: Use common error handling code in  __btrfs_free_extent() Dan Carpenter <dan.carpenter@oracle.com> - 2017-08-21 15:20 +0200
  [PATCH 4/5] btrfs: Use common error handling code in  update_ref_path() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-21 14:50 +0200
    Re: [PATCH 4/5] btrfs: Use common error handling code in  update_ref_path() Jeff Mahoney <jeffm@suse.com> - 2017-08-21 15:10 +0200
      Re: [PATCH 4/5] btrfs: Use common error handling code in  update_ref_path() Dan Carpenter <dan.carpenter@oracle.com> - 2017-08-21 15:50 +0200
        [PATCH v2] btrfs: Use common error handling code in update_ref_path() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-21 16:00 +0200
  [PATCH 5/5] btrfs: Use common error handling code in  btrfs_mark_extent_written() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-21 14:50 +0200
    Re: [PATCH 5/5] btrfs: Use common error handling code in  btrfs_mark_extent_written() Jeff Mahoney <jeffm@suse.com> - 2017-08-21 15:10 +0200
  [PATCH 3/5] btrfs: Use common error handling code in  btrfs_update_root() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-21 14:50 +0200
    Re: [PATCH 3/5] btrfs: Use common error handling code in  btrfs_update_root() Jeff Mahoney <jeffm@suse.com> - 2017-08-21 15:10 +0200
  Re: [PATCH 0/5] BTRFS: Fine-tuning for five function implementations David Sterba <dsterba@suse.cz> - 2017-08-21 15:30 +0200

csiph-web