From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:55246 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726861AbeJQSGr (ORCPT ); Wed, 17 Oct 2018 14:06:47 -0400 From: David Laight To: 'Phillip Potter' , "dushistov@mail.ru" CC: "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" Subject: RE: [PATCH] fs: ufs: Remove switch statement from ufs_set_de_type function Date: Wed, 17 Oct 2018 10:11:47 +0000 Message-ID: References: <20181017100809.GA9070@pathfinder> In-Reply-To: <20181017100809.GA9070@pathfinder> Content-Language: en-US MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Phillip Potter > Sent: 17 October 2018 11:08 > > 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. For invalid cases, upper layer validation > catches this anyway, so this improves readability and arguably > performance by assigning (mode & S_IFMT) >> 12 directly. > ... > - 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; This requires that the two sets of constants are correctly aligned. If they aren't defined in terms of each other then you probably ought to add compile-time asserts that the values match. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)