diff mbox series

Arm64: adjust __irq_to_desc() to fix build with gcc14

Message ID 9cc9e16d-a4b0-4902-9f12-a7cb337b1763@suse.com (mailing list archive)
State New
Headers show
Series Arm64: adjust __irq_to_desc() to fix build with gcc14 | expand

Commit Message

Jan Beulich Aug. 29, 2024, 5:55 a.m. UTC
With the original code I observe

In function ‘__irq_to_desc’,
    inlined from ‘route_irq_to_guest’ at arch/arm/irq.c:465:12:
arch/arm/irq.c:54:16: error: array subscript -2 is below array bounds of ‘irq_desc_t[32]’ {aka ‘struct irq_desc[32]’} [-Werror=array-bounds=]
   54 |         return &this_cpu(local_irq_desc)[irq];
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

which looks pretty bogus: How in the world does the compiler arrive at
-2 when compiling route_irq_to_guest()? Yet independent of that the
function's parameter wants to be of unsigned type anyway, as shown by
a vast majority of callers (others use plain int when they really mean
non-negative quantities). With that adjustment the code compiles fine
again.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116519

Comments

Michal Orzel Aug. 29, 2024, 7:28 a.m. UTC | #1
On 29/08/2024 07:55, Jan Beulich wrote:
> 
> 
> With the original code I observe
> 
> In function ‘__irq_to_desc’,
>     inlined from ‘route_irq_to_guest’ at arch/arm/irq.c:465:12:
> arch/arm/irq.c:54:16: error: array subscript -2 is below array bounds of ‘irq_desc_t[32]’ {aka ‘struct irq_desc[32]’} [-Werror=array-bounds=]
>    54 |         return &this_cpu(local_irq_desc)[irq];
>       |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> which looks pretty bogus: How in the world does the compiler arrive at
> -2 when compiling route_irq_to_guest()? Yet independent of that the
> function's parameter wants to be of unsigned type anyway, as shown by
> a vast majority of callers (others use plain int when they really mean
> non-negative quantities). With that adjustment the code compiles fine
> again.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Michal Orzel <michal.orzel@amd.com>

Are there any places where we still require irq member of irq_desc to be signed?

~Michal
Jan Beulich Aug. 29, 2024, 7:36 a.m. UTC | #2
On 29.08.2024 09:28, Michal Orzel wrote:
> On 29/08/2024 07:55, Jan Beulich wrote:
>> With the original code I observe
>>
>> In function ‘__irq_to_desc’,
>>     inlined from ‘route_irq_to_guest’ at arch/arm/irq.c:465:12:
>> arch/arm/irq.c:54:16: error: array subscript -2 is below array bounds of ‘irq_desc_t[32]’ {aka ‘struct irq_desc[32]’} [-Werror=array-bounds=]
>>    54 |         return &this_cpu(local_irq_desc)[irq];
>>       |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> which looks pretty bogus: How in the world does the compiler arrive at
>> -2 when compiling route_irq_to_guest()? Yet independent of that the
>> function's parameter wants to be of unsigned type anyway, as shown by
>> a vast majority of callers (others use plain int when they really mean
>> non-negative quantities). With that adjustment the code compiles fine
>> again.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> Acked-by: Michal Orzel <michal.orzel@amd.com>

Thanks.

> Are there any places where we still require irq member of irq_desc to be signed?

I can't spot any. On x86 we store negated values, but only in ->arch.irq.

Jan
diff mbox series

Patch

--- a/xen/arch/arm/include/asm/irq.h
+++ b/xen/arch/arm/include/asm/irq.h
@@ -56,7 +56,7 @@  extern const unsigned int nr_irqs;
 struct irq_desc;
 struct irqaction;
 
-struct irq_desc *__irq_to_desc(int irq);
+struct irq_desc *__irq_to_desc(unsigned int irq);
 
 #define irq_to_desc(irq)    __irq_to_desc(irq)
 
--- unstable.orig/xen/arch/arm/irq.c	2024-06-28 15:56:44.000000000 +0200
+++ unstable/xen/arch/arm/irq.c	2024-08-28 15:12:10.333607505 +0200
@@ -48,7 +48,7 @@  void irq_end_none(struct irq_desc *irq)
 static irq_desc_t irq_desc[NR_IRQS];
 static DEFINE_PER_CPU(irq_desc_t[NR_LOCAL_IRQS], local_irq_desc);
 
-struct irq_desc *__irq_to_desc(int irq)
+struct irq_desc *__irq_to_desc(unsigned int irq)
 {
     if ( irq < NR_LOCAL_IRQS )
         return &this_cpu(local_irq_desc)[irq];