[PATCH-next] arm: fix clang build warning in include/asm/memory.h

Linus Walleij linus.walleij at linaro.org
Fri Mar 15 00:40:28 PDT 2024


On Fri, Mar 15, 2024 at 1:43 AM Nathan Chancellor <nathan at kernel.org> wrote:
> On Thu, Mar 14, 2024 at 03:54:09PM +0800, Yipeng Zou wrote:
> > There is a build error has been founded with build in clang-15.0.4:
> >
> > ./arch/arm/include/asm/memory.h:358:12: error: result of comparison "phys addr_t’ (aka 'unsigned int’) > 4294967295 is always false [-Werror, -Wtautological-type-limit-compare]
> >                              if (addr > (u32)~0)
> >                                  ~~~~ ^ ~~~~~~~
> >
> > It will be always goes fail without CONFIG_PHYS_ADDR_T_64BIT.
> >
> > Directly silence it by Use CONFIG_PHYS_ADDR_T_64BIT.
> >
> > Fixes: 981b6714dbd2 ("ARM: provide improved virt_to_idmap() functionality")
> > Signed-off-by: Yipeng Zou <zouyipeng at huawei.com>
> > ---
> >  arch/arm/include/asm/memory.h | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
> > index ef2aa79ece5a..64ced9eb42ff 100644
> > --- a/arch/arm/include/asm/memory.h
> > +++ b/arch/arm/include/asm/memory.h
> > @@ -347,14 +347,18 @@ static inline bool arm_has_idmap_alias(void)
> >       return IS_ENABLED(CONFIG_MMU) && arch_phys_to_idmap_offset != 0;
> >  }
> >
> > +#ifdef CONFIG_PHYS_ADDR_T_64BIT
> >  #define IDMAP_INVALID_ADDR ((u32)~0)
> > +#endif
> >
> >  static inline unsigned long phys_to_idmap(phys_addr_t addr)
> >  {
> >       if (IS_ENABLED(CONFIG_MMU) && arch_phys_to_idmap_offset) {
> >               addr += arch_phys_to_idmap_offset;
> > +#ifdef CONFIG_PHYS_ADDR_T_64BIT
> >               if (addr > (u32)~0)
> >                       addr = IDMAP_INVALID_ADDR;
> > +#endif
> >       }
> >       return addr;
> >  }
> > --
> > 2.34.1
> >
>
> Would it be better to avoid the ifdef's here and just use IS_ENABLED()?
> I can't see why this would not work for avoiding that warning.
>
> diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
> index ef2aa79ece5a..fbff07bc3b28 100644
> --- a/arch/arm/include/asm/memory.h
> +++ b/arch/arm/include/asm/memory.h
> @@ -353,7 +353,7 @@ static inline unsigned long phys_to_idmap(phys_addr_t addr)
>  {
>         if (IS_ENABLED(CONFIG_MMU) && arch_phys_to_idmap_offset) {
>                 addr += arch_phys_to_idmap_offset;
> -               if (addr > (u32)~0)
> +               if (IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT) && addr > (u32)~0)
>                         addr = IDMAP_INVALID_ADDR;

+1 and I would probably use this as well:

<linux/limits.h>

#define IDMAP_INVALID_ADDR    PHYS_ADDR_MAX

if (IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT) && addr > PHYS_ADDR_MAX)
    addr = IDMAP_INVALID_ADDR;

Because then it is clear what is going on: we are capping to the max physical
address.

PHYS_ADDR_MAX is defined to (~(phys_addr_t)0) which on
ARM is (~(u32)0).

Yours,
Linus Walleij



More information about the linux-arm-kernel mailing list