zephyr/arch/common/sw_isr_common.c
Yong Cong Sin f3da086ac3 arch: common: sw_isr: make sure that the table index is within range
Assert that the `local_irq` of each levels should only ranges
from `0` to `CONFIG_MAX_IRQ_PER_AGGREGATOR`, so that it doesn't
overflow the other aggregators.

Also, assert that the output of `z_get_sw_isr_table_idx` shouldn't
overflow the ISR table.

Update the `sw_isr_table` tests to test the range of
`CONFIG_MAX_IRQ_PER_AGGREGATOR` instead of the entire range of
level bits.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-12-08 08:40:41 -05:00

24 lines
489 B
C

/*
* Copyright (c) 2018 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sw_isr_common.h"
#include <zephyr/sw_isr_table.h>
#include <zephyr/irq.h>
#include <zephyr/sys/__assert.h>
/*
* Common code for arches that use software ISR tables (CONFIG_GEN_ISR_TABLES)
*/
unsigned int __weak z_get_sw_isr_table_idx(unsigned int irq)
{
unsigned int table_idx = irq - CONFIG_GEN_IRQ_START_VECTOR;
__ASSERT_NO_MSG(table_idx < IRQ_TABLE_SIZE);
return table_idx;
}