lkml.org 
[lkml]   [2019]   [Aug]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs
On Wed, Jul 31, 2019 at 12:27:38PM -0700, Joe Perches wrote:
> On Wed, 2019-07-31 at 21:03 +0200, Rikard Falkeborn wrote:
> > GENMASK() and GENMASK_ULL() are supposed to be called with the high bit
> > as the first argument and the low bit as the second argument. Mixing
> > them will return a mask with zero bits set.
>
> A few things:
>
> o Reading the final code is a bit confusing.
> Perhaps add a comment description saying it's not checked
> in asm .h uses.

Comment added.

> o Maybe use:
> #define GENMASK_INPUT_CHECK(h, l) UL(0)

Sure.

> o The compiler error message when the arguments are in the
> wrong order isn't obvious. Is there some way to improve
> the compiler error output, maybe by using BUILD_BUG_ON_MSG
> or some other mechanism?

Not that I could find. BUILD_BUG_ON_MSG can not be used if the macros
should be usable in e.g. a structure initializer (this seems to be the
whole reason BUILD_BUG_ON_ZERO exists).

\
 
 \ /
  Last update: 2019-08-02 01:04    [W:0.243 / U:0.548 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site