From mboxrd@z Thu Jan 1 00:00:00 1970 From: Theodore Ts'o Subject: Re: Unsigned widening casts of binary "not" operations.. Date: Tue, 23 Apr 2013 11:52:12 -0400 Message-ID: <20130423155212.GI31170@thunk.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: David Laight , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , David Miller , Linux Kernel Mailing List , the arch/x86 maintainers , Network Development , "linux-ext4@vger.kernel.org" To: Linus Torvalds Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-ext4.vger.kernel.org On Tue, Apr 23, 2013 at 08:42:49AM -0700, Linus Torvalds wrote: > The best case is for code that does bitmasking ops like this to avoid > any casts (implicit or explicit) by just avoiding mixed types. That > was, to a large degree, my hope for the sparse patch, but it's > nontrivial. Many types are rather "natural" (ie constants have a > natural "int" type, sizeof() is size_t, etc) and in other cases you > want to do the same ops for two different types (with the case that > caused me to start to look at it being the "align to page boundary" > for a virtual address vs a PAE phys_addr_t) so you can't really avoid > mixing things in some circumstances. Maybe it's worth creating a magic helper function, called something like mask_out() that handles the casting automatically, and it makes it clear to a reader what you're trying to do? - Ted