From patchwork Mon Aug 21 12:42:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9912439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C6BD1602D8 for ; Mon, 21 Aug 2017 12:43:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC58228745 for ; Mon, 21 Aug 2017 12:43:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B11E82877F; Mon, 21 Aug 2017 12:43:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCC302874F for ; Mon, 21 Aug 2017 12:43:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753719AbdHUMmv (ORCPT ); Mon, 21 Aug 2017 08:42:51 -0400 Received: from mout.web.de ([212.227.15.14]:63037 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753021AbdHUMmu (ORCPT ); Mon, 21 Aug 2017 08:42:50 -0400 Received: from [192.168.1.2] ([85.182.36.210]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Ljgd6-1d8FQn2oeW-00bdAr; Mon, 21 Aug 2017 14:42:41 +0200 Subject: [PATCH 5/5] btrfs: Use common error handling code in btrfs_mark_extent_written() From: SF Markus Elfring To: linux-btrfs@vger.kernel.org, Chris Mason , David Sterba , Josef Bacik Cc: LKML , kernel-janitors@vger.kernel.org References: <1e8e1da2-a9e3-9dc7-6ffe-6c32f8464337@users.sourceforge.net> Message-ID: <93116379-7a82-733a-6957-4e01b3572d8f@users.sourceforge.net> Date: Mon, 21 Aug 2017 14:42:40 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1e8e1da2-a9e3-9dc7-6ffe-6c32f8464337@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:U6AM4HFXvWkcjwbU3LVQe+H7PD/ycSrs1PLcN1z9iiP45KcRd8I xWpvijampA+4kZNJCHufMm6/toEHaZ19Tak/BOUCoU9n16jtTGzDLx/k6TRs6r4TE8DB5I8 Xqk3DG1/xrIN+WgiqbCvb7KzqkTIErfkXyeE4hMfk9cnKOcybW6NxEKE85AxoVu3m37eMQS d7vV8S04OfZ8KZLwoTqvg== X-UI-Out-Filterresults: notjunk:1; V01:K0:ShXfNEDzLeo=:v55Gq6DrpRNfsS4Cpm9TBu 2Us2bfbQXY8xVP1c4nrfwMXZscEK1Fk8PlWwdimvEfsg6iElEZ8pblH6XfwIZI+crNze9IPKV i1Jo0rSv5UzSu3yn+5+Hh9vT3HGENsR9zWfASA/vBR/Dz/mQwQN9SxPKY4ndaXfxUSqXZtX22 h4eJ2ttQ1WYKXNURyYtSo2jLiStLg1KtcTSbNa21hpWTQi5IRcwMLPW3/wujZGOEy1Tn0c5K8 qSBmG0qinb5k17AdllO4/lfzrj5zDwZ8RgtwPbapuc9re6O80Xr31tToRknDHB5lNnCFGSsVm odSevM7ilySWbx8SqN92GV3AZXbr0BqZjwQm2eCdujXisK2tB0x+EIewYZ3vC9PljMDqQsnN/ ONsM83pGnGmoGCX3eRtw3hnP37Df8rnJ0cO8/nLa6nMu91A3NU/w5bTDEnACoOVeEPKP/LkoU xyta2UE+6KeW1W0eAXNLaDpzglDlaO7VyRKXu2qeYYBQ/f11hO5BzUs45xwzWBjU29QxOqdoD hWi42UEYKI4Q7mhT/qBI22EX9CWKEIe0/2kwR4Xl2nV1jArUDL6uTxR2kVyj1wrWWV10FyTqr 0eGRcOhviEg5oaT3hvdRBu9qcJtzn+xjETXK8nSQFZHKgx5NXeGDS9e9tplD21UCI4RHtO0wr tIFjuFOgsNsRnqJ3f05ob9DP/ijLuRtAmhAqVPYzdPcH+x9BJ3syfscUNuSJ7GmGNos8Mdnd+ C8TaBKznBgJ6VLhPi9cO5qjurKMoecUUxRLpz35eRvokWfstjeThAEL4YyFzG9XOg3cJ6K4MX 2Bkr2kUAHPXBVez26JFWk3Or+rS9MA0a/jAwvB1YcQ/yT0CyZqAt2ci5ZCYCevqmuE0kMm6 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring 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 --- 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; } /*