[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <93116379-7a82-733a-6957-4e01b3572d8f@users.sourceforge.net>
Date: Mon, 21 Aug 2017 14:42:40 +0200
From: SF Markus Elfring <elfring@...rs.sourceforge.net>
To: linux-btrfs@...r.kernel.org, Chris Mason <clm@...com>,
David Sterba <dsterba@...e.com>, Josef Bacik <jbacik@...com>
Cc: LKML <linux-kernel@...r.kernel.org>,
kernel-janitors@...r.kernel.org
Subject: [PATCH 5/5] btrfs: Use common error handling code in
btrfs_mark_extent_written()
From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Mon, 21 Aug 2017 14:15:23 +0200
Add jump targets 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@...rs.sourceforge.net>
---
fs/btrfs/file.c | 62 ++++++++++++++++++++++-----------------------------------
1 file changed, 24 insertions(+), 38 deletions(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 74fd7756cff3..675683051cbc 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1122,25 +1122,17 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
leaf = path->nodes[0];
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
- if (key.objectid != ino ||
- key.type != BTRFS_EXTENT_DATA_KEY) {
- ret = -EINVAL;
- btrfs_abort_transaction(trans, ret);
- goto out;
- }
+ if (key.objectid != ino || key.type != BTRFS_EXTENT_DATA_KEY)
+ goto e_inval;
+
fi = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item);
- if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_PREALLOC) {
- ret = -EINVAL;
- btrfs_abort_transaction(trans, ret);
- goto out;
- }
+ if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_PREALLOC)
+ goto e_inval;
+
extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi);
- if (key.offset > start || extent_end < end) {
- ret = -EINVAL;
- btrfs_abort_transaction(trans, ret);
- goto out;
- }
+ if (key.offset > start || extent_end < end)
+ goto e_inval;
bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi);
@@ -1213,10 +1205,8 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
btrfs_release_path(path);
goto again;
}
- if (ret < 0) {
- btrfs_abort_transaction(trans, ret);
- goto out;
- }
+ if (ret < 0)
+ goto abort_transaction;
leaf = path->nodes[0];
fi = btrfs_item_ptr(leaf, path->slots[0] - 1,
@@ -1237,18 +1227,15 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
ret = btrfs_inc_extent_ref(trans, fs_info, bytenr, num_bytes,
0, root->root_key.objectid,
ino, orig_offset);
- if (ret) {
- btrfs_abort_transaction(trans, ret);
- goto out;
- }
+ if (ret)
+ goto abort_transaction;
if (split == start) {
key.offset = start;
} else {
if (start != key.offset) {
ret = -EINVAL;
- btrfs_abort_transaction(trans, ret);
- goto out;
+ goto abort_transaction;
}
path->slots[0]--;
extent_end = end;
@@ -1271,10 +1258,8 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
ret = btrfs_free_extent(trans, fs_info, bytenr, num_bytes,
0, root->root_key.objectid,
ino, orig_offset);
- if (ret) {
- btrfs_abort_transaction(trans, ret);
- goto out;
- }
+ if (ret)
+ goto abort_transaction;
}
other_start = 0;
other_end = start;
@@ -1291,10 +1276,8 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
ret = btrfs_free_extent(trans, fs_info, bytenr, num_bytes,
0, root->root_key.objectid,
ino, orig_offset);
- if (ret) {
- btrfs_abort_transaction(trans, ret);
- goto out;
- }
+ if (ret)
+ goto abort_transaction;
}
if (del_nr == 0) {
fi = btrfs_item_ptr(leaf, path->slots[0],
@@ -1314,14 +1297,17 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
btrfs_mark_buffer_dirty(leaf);
ret = btrfs_del_items(trans, root, path, del_slot, del_nr);
- if (ret < 0) {
- btrfs_abort_transaction(trans, ret);
- goto out;
- }
+ if (ret < 0)
+ goto abort_transaction;
}
out:
btrfs_free_path(path);
return 0;
+e_inval:
+ ret = -EINVAL;
+abort_transaction:
+ btrfs_abort_transaction(trans, ret);
+ goto out;
}
/*
--
2.14.0
Powered by blists - more mailing lists