Subject: Re: [PATCH v2 08/16] bitfield: Simplify __BF_FIELD_CHECK_REG()

From: David Laight <[email-masked]>
Date: Sun, 28 Dec 2025 22:50:04 +0000

On Sun, 28 Dec 2025 20:53:45 +0200
Andy Shevchenko <[email-masked]> wrote:

> On Wed, Dec 17, 2025 at 10:31:55PM +0000, David Laight wrote:
> > On Wed, 17 Dec 2025 10:26:18 +0000
> > Jonathan Cameron <[email-masked]> wrote:  
> > > On Fri, 12 Dec 2025 19:37:13 +0000
> > > [email-masked] wrote:  
> 
> ...
> 
> > > > +	BUILD_BUG_ON_MSG((mask) + 0U + 0UL + 0ULL >			\
> > > > +			 ~0ULL >> (64 - 8 * sizeof (reg)),		\    
> > > 
> > > Trivial.  sizeof(reg) is much more comment syntax in kernel code.  
> >                                      (common)
> > 
> > Hmm. sizeof is an operator not a function.
> > Its argument is either a variable/expression or a bracketed type
> > (I don't usually put variables in brackets).
> > So 'sizeof(reg)' is nearly as bad as 'return(reg)'.  
> 
> Yet, it's a style used de facto in the Linux kernel. I am with Jonathan on this.

Not hard to change :-)

There is a more interesting question as to whether that check is
needed at all?
It is only really the sanity checks (and the fact that __builtin_ffs() is
sub-optimal) that stop the functions being 'reasonable' for non-constant
values.

	David