sched/irq: Fix type mismatch in irq_dispatch (MISRA C-2012 Rule 10.3)

IRQ_TO_NDX() returns int (can be negative on error), but was assigned
to unsigned int variable 'ndx', violating MISRA C-2012 Rule 10.3.

This also improves the condition check: instead of checking 'irq >= 0 && irq < NR_IRQS',
we now check 'ndx >= 0' which properly handles the error case where IRQ_TO_NDX()
returns a negative error code.

Changes:
- Change 'ndx' type from unsigned int to int
- Simplify condition from 'irq >= 0 && irq < NR_IRQS' to 'ndx >= 0'

This ensures type correctness and proper error handling.

Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>
This commit is contained in:
pangzhen1
2025-08-28 20:46:19 +08:00
committed by Xiang Xiao
parent c2eb22d29e
commit ce743a22ee
+2 -2
View File
@@ -102,10 +102,10 @@ void irq_dispatch(int irq, FAR void *context)
#endif
xcpt_t vector = irq_unexpected_isr;
FAR void *arg = NULL;
unsigned int ndx = IRQ_TO_NDX(irq);
int ndx = IRQ_TO_NDX(irq);
#if NR_IRQS > 0
if (irq >= 0 && irq < NR_IRQS)
if (ndx >= 0)
{
#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
if (ndx < CONFIG_ARCH_NUSER_INTERRUPTS)