Re: [PATCH next 08/14] bits: simplify GENMASK_TYPE()

From: Yury Norov

Date: Sat Feb 07 2026 - 21:37:15 EST


On Wed, Jan 21, 2026 at 02:57:25PM +0000, david.laight.linux@xxxxxxxxx wrote:
> From: David Laight <david.laight.linux@xxxxxxxxx>
>
> Since the type is always unsigned (T)-1 is always the correct value
> so there is no need to use type_max().
>
> Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>

Here you implicitly add a new restriction that all types passed in
GENMASK_TYPE() must be unsigned. Can you enforce it with
is_signed_type(), or at lease with a corresponding comment?

> ---
> include/linux/bits.h | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/include/linux/bits.h b/include/linux/bits.h
> index a40cc861b3a7..697318f2a47d 100644
> --- a/include/linux/bits.h
> +++ b/include/linux/bits.h
> @@ -45,8 +45,7 @@
> */
> #define GENMASK_TYPE(t, h, l) \
> ((t)(GENMASK_INPUT_CHECK(h, l) + \
> - (type_max(t) << (l) & \
> - type_max(t) >> (BITS_PER_TYPE(t) - 1 - (h)))))
> + ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h)))))
>
> #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l)
> #define GENMASK_ULL(h, l) GENMASK_TYPE(unsigned long long, h, l)
> --
> 2.39.5