All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Yipeng Zou <zouyipeng@huawei.com>
Cc: linux@armlinux.org.uk, ndesaulniers@google.com, morbo@google.com,
	justinstitt@google.com, linus.walleij@linaro.org,
	ssantosh@kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH-next] arm: fix clang build warning in include/asm/memory.h
Date: Tue, 19 Mar 2024 07:46:53 -0700	[thread overview]
Message-ID: <20240319144653.GA2322975@dev-arch.thelio-3990X> (raw)
In-Reply-To: <633653e9-c464-e135-6060-a092ea6f4fce@huawei.com>

On Tue, Mar 19, 2024 at 11:38:02AM +0800, Yipeng Zou wrote:
> 
> 在 2024/3/19 11:16, Yipeng Zou 写道:
> > 
> > 在 2024/3/15 8:43, Nathan Chancellor 写道:
> > > 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@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;
> > >       }
> > >       return addr;
> > 
> > It absolutely works for it and yes, It's a better way to avoiding that.
> > 
> > Will fix it in that way.
> > 
> But I notice that, this way can not silence it when compile, it only can
> avoid it in running time.

Yeah, I actually tested my suggestion and saw the same thing. Sometimes
diagnostics will be hidden by '0 &&' but it seems like that is not the
case here. It is not the end of the world, I think that diff looks fine
for the issue at hand.

> So, maybe we still need to silence it in ifdef's.
> 
> Other than that, IDMAP_INVALID_ADDR was used in other place, need to keep it
> defined.
> 
> diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
> index 158ad13e9f6a..7143147cd7cc 100644
> --- a/arch/arm/include/asm/memory.h
> +++ b/arch/arm/include/asm/memory.h
> @@ -351,8 +351,10 @@ 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;
>  }
> 
> > > _______________________________________________
> > > linux-arm-kernel mailing list
> > > linux-arm-kernel@lists.infradead.org
> > > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> > 
> -- 
> Regards,
> Yipeng Zou
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      reply	other threads:[~2024-03-19 14:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14  7:54 [PATCH-next] arm: fix clang build warning in include/asm/memory.h Yipeng Zou
2024-03-15  0:43 ` Nathan Chancellor
2024-03-15  7:40   ` Linus Walleij
2024-03-15 10:08     ` Russell King (Oracle)
2024-03-15 13:16       ` Linus Walleij
2024-03-15 14:46         ` Russell King (Oracle)
2024-03-19  3:13     ` Yipeng Zou
2024-03-19  3:16   ` Yipeng Zou
2024-03-19  3:38     ` Yipeng Zou
2024-03-19 14:46       ` Nathan Chancellor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240319144653.GA2322975@dev-arch.thelio-3990X \
    --to=nathan@kernel.org \
    --cc=justinstitt@google.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=morbo@google.com \
    --cc=ndesaulniers@google.com \
    --cc=ssantosh@kernel.org \
    --cc=zouyipeng@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.