[PATCH 1/2] bitops: Guard GENMASK and GENMASK_ULL against prior defines

Ilias Apalodimas ilias.apalodimas at linaro.org
Tue May 5 08:28:57 CEST 2026


On Thu, 30 Apr 2026 at 14:39, Simon Glass <sjg at chromium.org> wrote:
>
> Some headers - notably the ec_commands.h synced from upstream
> Chrome OS EC - define GENMASK and GENMASK_ULL themselves before
> linux/bitops.h is pulled in. The unguarded definitions here then trigger
> a 'redefined' warning at the second site, even though both spellings
> produce the same mask.
>
> Wrap the two macros in '#ifndef' guards so a pre-existing definition
> wins. The U-Boot expressions are unchanged.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---

Reviewed-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>

>
>  include/linux/bitops.h | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index 29e0da48de8..8b381c916cf 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -26,6 +26,7 @@
>   * position @h. For example
>   * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
>   */
> +#ifndef GENMASK
>  #ifdef CONFIG_SANDBOX
>  #define GENMASK(h, l) \
>         (((~0UL) << (l)) & (~0UL >> (CONFIG_SANDBOX_BITS_PER_LONG - 1 - (h))))
> @@ -33,9 +34,12 @@
>  #define GENMASK(h, l) \
>         (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
>  #endif
> +#endif
>
> +#ifndef GENMASK_ULL
>  #define GENMASK_ULL(h, l) \
>         (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
> +#endif
>
>  /*
>   * ffs: find first bit set. This is defined the same way as
> --
> 2.43.0
>


More information about the U-Boot mailing list