From patchwork Tue Jul 17 16:11:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10530125 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 1C1E1603ED for ; Tue, 17 Jul 2018 16:35:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02AFC29507 for ; Tue, 17 Jul 2018 16:35:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9EEA2960D; Tue, 17 Jul 2018 16:34:59 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 9061C29507 for ; Tue, 17 Jul 2018 16:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729620AbeGQRI0 (ORCPT ); Tue, 17 Jul 2018 13:08:26 -0400 Received: from gateway22.websitewelcome.com ([192.185.47.144]:42211 "EHLO gateway22.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729461AbeGQRI0 (ORCPT ); Tue, 17 Jul 2018 13:08:26 -0400 X-Greylist: delayed 1385 seconds by postgrey-1.27 at vger.kernel.org; Tue, 17 Jul 2018 13:08:26 EDT Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 162211226F for ; Tue, 17 Jul 2018 11:11:58 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id fSZWf44SsbXuJfSZnfBwon; Tue, 17 Jul 2018 11:11:57 -0500 X-Authority-Reason: nr=8 Received: from [189.250.65.56] (port=46576 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1ffSZV-002jyk-0c; Tue, 17 Jul 2018 11:11:29 -0500 Date: Tue, 17 Jul 2018 11:11:27 -0500 From: "Gustavo A. R. Silva" To: "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] xfs: use swap macro in xfs_dir2_leafn_rebalance Message-ID: <20180717161127.GA16337@embeddedor.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.65.56 X-Source-L: No X-Exim-ID: 1ffSZV-002jyk-0c X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.65.56]:46576 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 2 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make use of the swap macro and remove unnecessary variable *tmp*. This makes the code easier to read and maintain. Also, slightly refactor some code. This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_node.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c index 2daf874..f1bb343 100644 --- a/fs/xfs/libxfs/xfs_dir2_node.c +++ b/fs/xfs/libxfs/xfs_dir2_node.c @@ -1012,7 +1012,7 @@ xfs_dir2_leafn_rebalance( int oldstale; /* old count of stale leaves */ #endif int oldsum; /* old total leaf count */ - int swap; /* swapped leaf blocks */ + int swap_blocks; /* swapped leaf blocks */ struct xfs_dir2_leaf_entry *ents1; struct xfs_dir2_leaf_entry *ents2; struct xfs_dir3_icleaf_hdr hdr1; @@ -1023,13 +1023,10 @@ xfs_dir2_leafn_rebalance( /* * If the block order is wrong, swap the arguments. */ - if ((swap = xfs_dir2_leafn_order(dp, blk1->bp, blk2->bp))) { - xfs_da_state_blk_t *tmp; /* temp for block swap */ + swap_blocks = xfs_dir2_leafn_order(dp, blk1->bp, blk2->bp); + if (swap_blocks) + swap(blk1, blk2); - tmp = blk1; - blk1 = blk2; - blk2 = tmp; - } leaf1 = blk1->bp->b_addr; leaf2 = blk2->bp->b_addr; dp->d_ops->leaf_hdr_from_disk(&hdr1, leaf1); @@ -1093,11 +1090,11 @@ xfs_dir2_leafn_rebalance( * Mark whether we're inserting into the old or new leaf. */ if (hdr1.count < hdr2.count) - state->inleaf = swap; + state->inleaf = swap_blocks; else if (hdr1.count > hdr2.count) - state->inleaf = !swap; + state->inleaf = !swap_blocks; else - state->inleaf = swap ^ (blk1->index <= hdr1.count); + state->inleaf = swap_blocks ^ (blk1->index <= hdr1.count); /* * Adjust the expected index for insertion. */