Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932271Ab0AFQUs (ORCPT ); Wed, 6 Jan 2010 11:20:48 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932237Ab0AFQUs (ORCPT ); Wed, 6 Jan 2010 11:20:48 -0500 Received: from mail2.shareable.org ([80.68.89.115]:33092 "EHLO mail2.shareable.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932227Ab0AFQUr (ORCPT ); Wed, 6 Jan 2010 11:20:47 -0500 Date: Wed, 6 Jan 2010 16:20:04 +0000 From: Jamie Lokier To: Roland Dreier Cc: Wu Fengguang , Andrew Morton , David Miller , Stephen Rothwell , Al Viro , Christoph Hellwig , Eric Paris , LKML , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH] fs: O_* bit numbers uniqueness check Message-ID: <20100106162004.GA11773@shareable.org> References: <20100106065526.GB11368@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.13 (2006-08-11) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1217 Lines: 32 Roland Dreier wrote: > > > + /* please add new bits here to ensure allocation uniqueness */ > > + BUG_ON(20 != hweight32( > > + O_RDONLY | O_WRONLY | O_RDWR | > > I wonder if there's a way to make this BUILD_BUG_ON(), so the problem is > caught at compile time (a change like adding an O_ flag is often compile > tested only for obscure archs). One could create a compile-time > macro-ized version of hweight32() and use that, I guess, although I'm > not sure it's worth the ugliness. Not ugly at all: #define hweight32(x) __builtin_popcount(x) Checked GCC 3.4.3 / 4.1 / 4.4: It expands as a compile-time constant if the argument is a compile-time constant, so can be used in BUILD_BUG_ON() and even for array sizes etc. If GCC's __builtin_popcount() isn't good enough for non-constant values, the macro would be more involved: #define hweight32(x) (__builtin_constant_p(x) ? __builtin_popcount(x) \ : hweight32_nonconstant(x)) -- Jamie -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/