diff mbox series

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

Message ID 20240314075409.2797149-1-zouyipeng@huawei.com (mailing list archive)
State New, archived
Headers show
Series [PATCH-next] arm: fix clang build warning in include/asm/memory.h | expand

Commit Message

Yipeng Zou March 14, 2024, 7:54 a.m. UTC
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(+)

Comments

Nathan Chancellor March 15, 2024, 12:43 a.m. UTC | #1
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;
Linus Walleij March 15, 2024, 7:40 a.m. UTC | #2
On Fri, Mar 15, 2024 at 1:43 AM Nathan Chancellor <nathan@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@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
Russell King (Oracle) March 15, 2024, 10:08 a.m. UTC | #3
On Fri, Mar 15, 2024 at 08:40:28AM +0100, Linus Walleij wrote:
> +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).

... which is _not_ the same as (u32)~0, so using PHYS_ADDR_MAX is not
appropriate.
Linus Walleij March 15, 2024, 1:16 p.m. UTC | #4
On Fri, Mar 15, 2024 at 11:08 AM Russell King (Oracle)
<linux@armlinux.org.uk> wrote:
> On Fri, Mar 15, 2024 at 08:40:28AM +0100, Linus Walleij wrote:
> > +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).
>
> ... which is _not_ the same as (u32)~0, so using PHYS_ADDR_MAX is not
> appropriate.

Attention to detail! Thanks Russell.

However U32_MAX is
#define U32_MAX         ((u32)~0U)

So that should work and also convey the attention I think?

Yours,
Linus Walleij
Russell King (Oracle) March 15, 2024, 2:46 p.m. UTC | #5
On Fri, Mar 15, 2024 at 02:16:23PM +0100, Linus Walleij wrote:
> On Fri, Mar 15, 2024 at 11:08 AM Russell King (Oracle)
> <linux@armlinux.org.uk> wrote:
> > On Fri, Mar 15, 2024 at 08:40:28AM +0100, Linus Walleij wrote:
> > > +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).
> >
> > ... which is _not_ the same as (u32)~0, so using PHYS_ADDR_MAX is not
> > appropriate.
> 
> Attention to detail! Thanks Russell.
> 
> However U32_MAX is
> #define U32_MAX         ((u32)~0U)
> 
> So that should work and also convey the attention I think?

If you want to use that to define IDMAP_INVALID_ADDR then yes. If you're
thinking about getting rid of IDMAP_INVALID_ADDR, then I think that
would reduce code readability, because the idea here is that addresses
above the 32-bit virtual space are invalid for IDMAP, and just using
U32_MAX is a rather opaque way to convey that.
Yipeng Zou March 19, 2024, 3:13 a.m. UTC | #6
在 2024/3/15 15:40, Linus Walleij 写道:
> On Fri, Mar 15, 2024 at 1:43 AM Nathan Chancellor <nathan@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@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.

Yes, indeed, It's clearer to indicate what is going on.

Will fix it in that way.

> PHYS_ADDR_MAX is defined to (~(phys_addr_t)0) which on
> ARM is (~(u32)0).
>
> Yours,
> Linus Walleij
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Yipeng Zou March 19, 2024, 3:16 a.m. UTC | #7
在 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.

> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Yipeng Zou March 19, 2024, 3:38 a.m. UTC | #8
在 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.

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
>
Nathan Chancellor March 19, 2024, 2:46 p.m. UTC | #9
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
>
diff mbox series

Patch

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;
 }