lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <5257288.LvFx2qVVIh@workhorse>
Date: Wed, 17 Dec 2025 14:22:32 +0100
From: Nicolas Frattaroli <nicolas.frattaroli@...labora.com>
To: Yury Norov <yury.norov@...il.com>,
 Rasmus Villemoes <linux@...musvillemoes.dk>, linux-kernel@...r.kernel.org,
 linux-usb@...r.kernel.org, Geert Uytterhoeven <geert+renesas@...der.be>,
 Alexandre Belloni <alexandre.belloni@...tlin.com>,
 Jonathan Cameron <Jonathan.Cameron@...wei.com>, Crt Mori <cmo@...exis.com>,
 Richard Genoud <richard.genoud@...tlin.com>,
 Andy Shevchenko <andriy.shevchenko@...el.com>,
 Luo Jie <quic_luoj@...cinc.com>, Peter Zijlstra <peterz@...radead.org>,
 Jakub Kicinski <kuba@...nel.org>, netdev@...r.kernel.org,
 "David S . Miller" <davem@...emloft.net>,
 Mika Westerberg <mika.westerberg@...ux.intel.com>,
 Andreas Noever <andreas.noever@...il.com>,
 Yehezkel Bernat <YehezkelShB@...il.com>, david.laight.linux@...il.com
Cc: David Laight <david.laight.linux@...il.com>
Subject:
 Re: [PATCH v2 03/16] bitmap: Use FIELD_PREP() in expansion of
 FIELD_PREP_WM16()

On Friday, 12 December 2025 20:37:08 Central European Standard Time david.laight.linux@...il.com wrote:
> From: David Laight <david.laight.linux@...il.com>
> 
> Instead of directly expanding __BF_FIELD_CHECK() (which really ought
> not be used outside bitfield) and open-coding the generation of the
> masked value, just call FIELD_PREP() and add an extra check for
> the mask being at most 16 bits.
> The extra check is added after calling FIELD_PREP() to get a sane
> error message if 'mask' isn't constant.
> 
> Remove the leading _ from the formal parameter names.
> Prefix the local variables with _wm16_ to hopefully make them
> unique.
> 
> Signed-off-by: David Laight <david.laight.linux@...il.com>
> ---
> 
> Changes for v2:
> - Update kerneldoc to match changed formal parameter names.
> - Change local variables to not collide with those in FIELD_PREP().
> 
> Most of the examples are constants and get optimised away.
> 
>  include/linux/hw_bitfield.h | 21 ++++++++++-----------
>  1 file changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/include/linux/hw_bitfield.h b/include/linux/hw_bitfield.h
> index df202e167ce4..0bd1040a5f93 100644
> --- a/include/linux/hw_bitfield.h
> +++ b/include/linux/hw_bitfield.h
> @@ -12,8 +12,8 @@
>  
>  /**
>   * FIELD_PREP_WM16() - prepare a bitfield element with a mask in the upper half
> - * @_mask: shifted mask defining the field's length and position
> - * @_val:  value to put in the field
> + * @mask: shifted mask defining the field's length and position
> + * @val:  value to put in the field
>   *
>   * FIELD_PREP_WM16() masks and shifts up the value, as well as bitwise ORs the
>   * result with the mask shifted up by 16.
> @@ -23,15 +23,14 @@
>   * register, a bit in the lower half is only updated if the corresponding bit
>   * in the upper half is high.
>   */
> -#define FIELD_PREP_WM16(_mask, _val)					     \
> -	({								     \
> -		typeof(_val) __val = _val;				     \
> -		typeof(_mask) __mask = _mask;				     \
> -		__BF_FIELD_CHECK(__mask, ((u16)0U), __val,		     \
> -				 "HWORD_UPDATE: ");			     \
> -		(((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask)) | \
> -		((__mask) << 16);					     \
> -	})
> +#define FIELD_PREP_WM16(mask, val)				\
> +({								\
> +	__auto_type _wm16_mask = mask;				\
> +	u32 _wm16_val = FIELD_PREP(_wm16_mask, val);		\
> +	BUILD_BUG_ON_MSG(_wm16_mask > 0xffffu,			\
> +			 "FIELD_PREP_WM16: mask too large");	\
> +	_wm16_val | (_wm16_mask << 16);				\
> +})
>  
>  /**
>   * FIELD_PREP_WM16_CONST() - prepare a constant bitfield element with a mask in
> 

Tested-by: Nicolas Frattaroli <nicolas.frattaroli@...labora.com>

Compiled it with my usual config and booted it on a board that uses
drivers that make use of these macros, and checked that things are
working.

Thank you!

Kind regards,
Nicolas Frattaroli



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ