From patchwork Tue Apr 3 08:59:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10320851 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 599C060116 for ; Tue, 3 Apr 2018 08:59:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 498ED2889A for ; Tue, 3 Apr 2018 08:59:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E09E28958; Tue, 3 Apr 2018 08:59:50 +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,DKIM_SIGNED, DKIM_VALID,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 E99382889A for ; Tue, 3 Apr 2018 08:59:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755236AbeDCI7g (ORCPT ); Tue, 3 Apr 2018 04:59:36 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:50327 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751226AbeDCI7f (ORCPT ); Tue, 3 Apr 2018 04:59:35 -0400 Received: by mail-wm0-f67.google.com with SMTP id t67so11962991wmt.0 for ; Tue, 03 Apr 2018 01:59:34 -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=1xce86gN0FquKVfn4gs6daYZSh/8fD493E4TTonx/Fs=; b=T+tTKf4i57LsLurCo3zBLdz1lVVHGCmPUtVn8SjTR4iTi7CEhn4ilbJWlk0/MSAvTN dgLmCyL/bc5zBastVpIYMrSRS/zZx03cMWmXnvqNqf0+6OhtsBRfH6SzMnJboRATkjQ3 vdXA2LOAyn+UG5RgcuiwL2uwMG9OfuS84wBkVDEsO5KKdrGYkyHU91pc8djQxLwPQfr3 bPe9p+jaBDtb9xnmvWCqnqo2b8SE+c9GP9Rx1vsoolgGkjhjcYL1EpOCuPt0EGW8J6za GK+bfs+48l6fPjs7iJfkiCmKevAz2+L16W6g/7yO6X6jI7DP7bgVU9rynRUGFL/f55hA miqQ== 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=1xce86gN0FquKVfn4gs6daYZSh/8fD493E4TTonx/Fs=; b=W9Vanv5Tdadc8QYyWtz2PtuxDF6Y/3TV/gaKVqWcuvr0ZYtsiqv78vMPBnfFDU9e2x twskcBdljxYg6TaS3yVRtJfFJZtlVRRfgFc4DnRwfgFnS44szGdivISJcyDyWeu0QDqn y70ZsQnm06xgsFFM4kj2NrHNBtr+qcxYCf8VVsp072b4NJo+VXS9XaigagfBeXcqzbUe hr7znv0jyk7YzZZA6swfHVufZ4G0We5yFRzuEhz9CH/oBRjxz5vD+GAeNpuB03DpIeqI R6jDR0O/H9nU3X69OCQ3a8YzNFytrlEATrIJcL/Afoqysn0lwjxH5Gz6N0d5JjOBzofj 2CyA== X-Gm-Message-State: ALQs6tBLpDXeGUO29ENi4LKOPHWHjQiKb9ntcynRkyf9KwZUS8p3bGok 5+dTpMecBsKDfqoSKP2IwpPNGfUW0cM= X-Google-Smtp-Source: AIpwx4/Ony4XtXjH67YrCPPn96DcU28ST3yiXwrWNBk8IO37oPMRZfitTsXl0Q0bf5dTGoul/a8gzQ== X-Received: by 10.28.124.8 with SMTP id x8mr3254186wmc.36.1522745974063; Tue, 03 Apr 2018 01:59:34 -0700 (PDT) Received: from pathfinder (62-64-243-127.dynamic.dsl.as9105.com. [62.64.243.127]) by smtp.gmail.com with ESMTPSA id z16sm3010790wrc.70.2018.04.03.01.59.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Apr 2018 01:59:33 -0700 (PDT) Date: Tue, 3 Apr 2018 09:59:32 +0100 From: Phillip Potter To: dushistov@mail.ru Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH] fs: ufs: Convert ufs_set_de_type to use lookup table Message-ID: <20180403085932.GA2710@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) 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 Modify ufs_set_de_type function in fs/ufs/util.h to use a lookup table rather than a switch statement, as per the TODO comment. Signed-off-by: Phillip Potter --- fs/ufs/util.h | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/fs/ufs/util.h b/fs/ufs/util.h index 1907be6d5808..1edf4c6454e3 100644 --- a/fs/ufs/util.h +++ b/fs/ufs/util.h @@ -155,37 +155,31 @@ ufs_set_de_namlen(struct super_block *sb, struct ufs_dir_entry *de, u16 value) static inline void ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode) { + /* type lookup table, DT_UNKNOWN is default type if no case holds */ + const int mode_table[] = { + DT_UNKNOWN, + DT_FIFO, /* mode & S_IFMT == S_IFIFO case */ + DT_CHR, /* mode & S_IFMT == S_IFCHR case */ + DT_UNKNOWN, + DT_DIR, /* mode & S_IFMT == S_IFDIR case */ + DT_UNKNOWN, + DT_BLK, /* mode & S_IFMT == S_IFBLK case */ + DT_UNKNOWN, + DT_REG, /* mode & S_IFMT == S_IFREG case */ + DT_UNKNOWN, + DT_LNK, /* mode & S_IFMT == S_IFLNK case */ + DT_UNKNOWN, + DT_SOCK, /* mode & S_IFMT == S_IFSOCK case */ + DT_UNKNOWN, + DT_UNKNOWN, + DT_UNKNOWN + }; + 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; - } + /* shift (mode & S_IFMT) right 12 bits to index into table */ + de->d_u.d_44.d_type = mode_table[(mode & S_IFMT) >> 12]; } static inline u32