From patchwork Sat Oct 20 22:09:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10650633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F33BA17D4 for ; Sat, 20 Oct 2018 22:10:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D77992868C for ; Sat, 20 Oct 2018 22:10:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C62A2286BD; Sat, 20 Oct 2018 22:10:33 +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,DKIM_SIGNED, DKIM_VALID,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 396952868C for ; Sat, 20 Oct 2018 22:10:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726829AbeJUGV6 (ORCPT ); Sun, 21 Oct 2018 02:21:58 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33968 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726432AbeJUGV5 (ORCPT ); Sun, 21 Oct 2018 02:21:57 -0400 Received: by mail-wr1-f67.google.com with SMTP id l6-v6so40543548wrt.1 for ; Sat, 20 Oct 2018 15:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=DQPfYTeJT1zRChYCDTnPeEBah2R+Ieqvgt0nAJjUPhI=; b=Dr8Usv8c5ZTtY7xQyN6FFUsC2wrlWdHtgj1OMHqmu5tBSfnPOQHyfd5l9SVJpUcNpX 82iQqkdT9Q3JKMY4o5w+zU+3aYLM0POierhFBz+inyLTgZ+vqbO7qIofQlbftllkHRAR 13EM54Q+Zm8fZ1xKL3Kb7aYt/FlsdyUBgYGifzeR0SA/fztB60PUkfbRr9l7bWMwRN5N KYnEpxXGnTSoI1SRth4TlmFXmnLT0hNclsI08s8AJ6G8vUtEEvercDp7BUCC0Gs+jTy2 +7swbNyxEYisgK1wL3r+57IaKd432A2EuFGcbejTshmSNxai61nTiluZQUWYbyEuprl1 4dWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=DQPfYTeJT1zRChYCDTnPeEBah2R+Ieqvgt0nAJjUPhI=; b=spY/4J+Z3Vtej1V6qnFk4cLvoFzYWB0g6sIrgUYsaFK1XE7/EO+wHTKjRwHScFMTNs nOKRS4ox17OIl5Pr3R6Liau4ADhMm32UWG6u0dsYzsF7Llzd6QHXKi1UazWoangv2rwj 2yn3rBChEMAIEld2OGYCY5J8qYAeh0WzHxP1w2yNvtw6g/3oRpvsanV15+Cyi6g08rED zfL3z7yOf8l9C1ShS16cDJQJ09qfC21/xq2RScSGs2I5GcRQUGpqf2Ti9o6TOWk506GF KTTpjKooD0pv846rdViDBlBTn2vE9ugKA8d4J2HvZDTlWnXBwTYXygsuZ8rRs9uG56jl KJ6w== X-Gm-Message-State: ABuFfoicwI7oUBbYpTbaSWG7u5cf4MhjeZ/hG6Yjglr8K31/sB4QLLvI x8QP9FmGzVT9S3vEVbK1JaBfxw== X-Google-Smtp-Source: ACcGV63L25CjCNRinPw+fA78eCWzJgWXiArlzYuDxifXfiLL+A2CZijO5FWOdVlUABjOd3qDVtU2Ow== X-Received: by 2002:adf:ae41:: with SMTP id u1-v6mr37824379wrd.43.1540073399265; Sat, 20 Oct 2018 15:09:59 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id 64-v6sm24915336wrr.64.2018.10.20.15.09.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Oct 2018 15:09:58 -0700 (PDT) Date: Sat, 20 Oct 2018 23:09:57 +0100 From: Phillip Potter To: dushistov@mail.ru Cc: viro@zeniv.linux.org.uk, David.Laight@aculab.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH] fs: ufs: Remove switch statement from ufs_set_de_type function Message-ID: <20181020220957.GA7267@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove switch statement from ufs_set_de_type function in fs/ufs/util.h header and replace with simple assignment. For each case, S_IFx >> 12 is equal to DT_x, so in valid cases (mode & S_IFMT) >> 12 should give us the correct file type. It is expected that for *nix compatibility reasons, the relation between S_IFx and DT_x will not change. For cases where the mode is invalid, upper layer validation catches this anyway, so this improves readability and arguably performance by assigning (mode & S_IFMT) >> 12 directly without any jump table or conditional logic. Signed-off-by: Phillip Potter --- fs/ufs/util.h | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/fs/ufs/util.h b/fs/ufs/util.h index 1fd3011ea623..7e0c0878b9f9 100644 --- a/fs/ufs/util.h +++ b/fs/ufs/util.h @@ -16,6 +16,7 @@ * some useful macros */ #define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len)) +#define S_SHIFT 12 /* * functions used for retyping @@ -158,34 +159,7 @@ ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode) if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) != UFS_DE_44BSD) return; - /* - * TODO turn this into a table lookup - */ - switch (mode & S_IFMT) { - case S_IFSOCK: - de->d_u.d_44.d_type = DT_SOCK; - break; - case S_IFLNK: - de->d_u.d_44.d_type = DT_LNK; - break; - case S_IFREG: - de->d_u.d_44.d_type = DT_REG; - break; - case S_IFBLK: - de->d_u.d_44.d_type = DT_BLK; - break; - case S_IFDIR: - de->d_u.d_44.d_type = DT_DIR; - break; - case S_IFCHR: - de->d_u.d_44.d_type = DT_CHR; - break; - case S_IFIFO: - de->d_u.d_44.d_type = DT_FIFO; - break; - default: - de->d_u.d_44.d_type = DT_UNKNOWN; - } + de->d_u.d_44.d_type = (mode & S_IFMT) >> S_SHIFT; } static inline u32