From patchwork Wed Oct 17 12:34:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10645407 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 A8323109C for ; Wed, 17 Oct 2018 12:34:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E3DB2AE7D for ; Wed, 17 Oct 2018 12:34:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 922BD2AEBE; Wed, 17 Oct 2018 12:34:32 +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 632F42AE7D for ; Wed, 17 Oct 2018 12:34:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727028AbeJQUaA (ORCPT ); Wed, 17 Oct 2018 16:30:00 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55572 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726974AbeJQU37 (ORCPT ); Wed, 17 Oct 2018 16:29:59 -0400 Received: by mail-wm1-f68.google.com with SMTP id 206-v6so1839177wmb.5 for ; Wed, 17 Oct 2018 05:34:28 -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=93GEonh2nb+KSw9E8OqrNKqrDbLN5DYI6s6C3SX4j0o=; b=BGh1+CfSvYdajb3WC5LnthQpp536zLE00hBiMOi7g7c/QXZoIo1p/SGJec0A3dfJGL M3zVi31L1kD2CKaBI8y2KqoSyrS/6OEwj8l5V3tEZ11g8opI6dXAM76SVi6UcVfQBQ1C RwvfE1YbtMyDpWjvRTcE0HIJxu1x6+VlE9VEvdsB7FXNd8Q2zOPAGVDHd1vXOAQQ/crN MF0wHMQOr71WCKJSAwo45oHCh8/VwSbLbO36+5q4l/xklXhLFw3uYaTr+4okT5cuTbmH 20PQsw58AomioKKOEthrxgUbbcjR2C9dQ/d2No1gNNa8bzdhmO6dBdNBBiNJzqDEUFwY DqZw== 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=93GEonh2nb+KSw9E8OqrNKqrDbLN5DYI6s6C3SX4j0o=; b=cNasbR/4dms7FcD8kWqt0OpkZ+jHcYSsFZrnreHlhX5hAXhKWLAQ3selGz0GJyLIvW ahlBrC0xxxpzjZqEA5zb7Xb7HNw4de/uepE8OTiOaMVf90NefL4ZpsPbRYI/Y7VH3dsN 9+YeTsXMNEBcWHl4jVxsvMpnuUQk5iG+/kVz+F0a5LauWayWPqNj2OBRykDqC6a1ReTZ OD8zQi14rf9zAmC6T/1PBnz7o2SXJQDcU0nC26FuPyhs1nZjFyQ/80E/Qzsgm+HsIHhI RS20RjlaGoixoEXbzUFw0gt/8bmMdFmB3gzJp/LeDFEzkqJQmQrx387KTC76clsWcHOs 1z8w== X-Gm-Message-State: ABuFfogDNtr9I2rwY7LRHYhMH78J64dvMXRIeLyrjqJa5X67C1Uf/HHw zVzPBlW5pEXlvy5tFlXGvsHifg== X-Google-Smtp-Source: ACcGV60rVhUsTkj6qXgExSfjklpEt2Hv4jwKsMcxzVDNBJeU0EFDnc4ibz3aLGVhEawF9vPPnktaTg== X-Received: by 2002:a1c:1d6:: with SMTP id 205-v6mr2770990wmb.0.1539779667845; Wed, 17 Oct 2018 05:34:27 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id k23-v6sm15476332wrd.85.2018.10.17.05.34.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Oct 2018 05:34:27 -0700 (PDT) Date: Wed, 17 Oct 2018 13:34:26 +0100 From: Phillip Potter To: dushistov@mail.ru, David.Laight@aculab.com Cc: 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: <20181017123426.GA17296@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. This is verified at compile-time with BUILD_BUG_ON macro calls. For invalid cases, upper layer validation catches this anyway, so this improves readability and arguably performance by assigning (mode & S_IFMT) >> 12 directly. Signed-off-by: Phillip Potter --- fs/ufs/util.h | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/fs/ufs/util.h b/fs/ufs/util.h index 1fd3011ea623..dcf86829edc2 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,16 @@ 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; - } + /* Compile-time assertions that S_IFx >> S_SHIFT == DT_x */ + BUILD_BUG_ON(S_IFIFO >> S_SHIFT != DT_FIFO); + BUILD_BUG_ON(S_IFCHR >> S_SHIFT != DT_CHR); + BUILD_BUG_ON(S_IFDIR >> S_SHIFT != DT_DIR); + BUILD_BUG_ON(S_IFBLK >> S_SHIFT != DT_BLK); + BUILD_BUG_ON(S_IFREG >> S_SHIFT != DT_REG); + BUILD_BUG_ON(S_IFLNK >> S_SHIFT != DT_LNK); + BUILD_BUG_ON(S_IFSOCK >> S_SHIFT != DT_SOCK); + + de->d_u.d_44.d_type = (mode & S_IFMT) >> S_SHIFT; } static inline u32