sched/irq: Fix array overrun in coverity check

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-04-05 14:57:47 +08:00 committed by Alan Carvalho de Assis
parent aed5dadc3d
commit 51ffa3edb0

View File

@ -39,6 +39,12 @@
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
# define NUSER_IRQS CONFIG_ARCH_NUSER_INTERRUPTS
#else
# define NUSER_IRQS NR_IRQS
#endif
/* INCR_COUNT - Increment the count of interrupts taken on this IRQ number */
#ifndef CONFIG_SCHED_IRQMONITOR
@ -81,9 +87,13 @@
vector(irq, context, arg); \
elapsed = up_perf_gettime() - start; \
up_perf_convert(elapsed, &delta); \
if (delta.tv_nsec > g_irqvector[ndx].time) \
if (ndx < NUSER_IRQS) \
{ \
g_irqvector[ndx].time = delta.tv_nsec; \
INCR_COUNT(ndx); \
if (delta.tv_nsec > g_irqvector[ndx].time) \
{ \
g_irqvector[ndx].time = delta.tv_nsec; \
} \
} \
if (CONFIG_SCHED_CRITMONITOR_MAXTIME_IRQ > 0 && \
elapsed > CONFIG_SCHED_CRITMONITOR_MAXTIME_IRQ) \
@ -130,8 +140,6 @@ void irq_dispatch(int irq, FAR void *context)
vector = g_irqvector[ndx].handler;
arg = g_irqvector[ndx].arg;
}
INCR_COUNT(ndx);
}
#else
if (g_irqvector[ndx].handler)
@ -139,8 +147,6 @@ void irq_dispatch(int irq, FAR void *context)
vector = g_irqvector[ndx].handler;
arg = g_irqvector[ndx].arg;
}
INCR_COUNT(ndx);
#endif
}
#endif