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

From: David Laight <[email-masked]>
Date: Wed, 17 Dec 2025 22:31:55 +0000

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:
> 
> > From: David Laight <[email-masked]>
> > 
> > Simplify the check for 'reg' being large enough to hold 'mask' using
> > sizeof (reg) rather than a convoluted scheme to generate an unsigned
> > type the same size as 'reg'.
> > 
> > Signed-off-by: David Laight <[email-masked]>  
> Hi David,
> 
> Just one really trivial comment inline. Feel free to ignore.
> 
> Jonathan
> 
> > ---
> > @@ -75,8 +59,8 @@
> >  	})
> >  
> >  #define __BF_FIELD_CHECK_REG(mask, reg, pfx)				\
> > -	BUILD_BUG_ON_MSG(__bf_cast_unsigned(mask, mask) >		\
> > -			 __bf_cast_unsigned(reg, ~0ull),		\
> > +	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)'.

	David

> 
> >  			 pfx "type of reg too small for mask")
> >  
> >  #define __BF_FIELD_CHECK(mask, reg, val, pfx)				\  
>