lib: utils/irqchip: plic: Ensure no out-of-bound access in context save/restore helpers

Currently the context save/restore helpers writes/reads the provided
array using an index whose maximum value is determined by PLIC, which
potentially may disagree with the caller to these helpers.

Add a parameter to ask the caller to provide the size limit of the
array to ensure no out-of-bound access happens.

Signed-off-by: Bin Meng <bmeng@tinylab.org>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Bin Meng
2022-12-11 14:54:24 +08:00
committed by Anup Patel
parent fabbc00668
commit 9a2eeb4aae
5 changed files with 23 additions and 14 deletions

View File

@@ -38,22 +38,23 @@ void fdt_plic_priority_restore(const u8 *priority, u32 num)
plic_priority_restore(plic, priority, num);
}
void fdt_plic_context_save(bool smode, u32 *enable, u32 *threshold)
void fdt_plic_context_save(bool smode, u32 *enable, u32 *threshold, u32 num)
{
u32 hartid = current_hartid();
plic_context_save(plic_hartid2data[hartid],
plic_hartid2context[hartid][smode],
enable, threshold);
enable, threshold, num);
}
void fdt_plic_context_restore(bool smode, const u32 *enable, u32 threshold)
void fdt_plic_context_restore(bool smode, const u32 *enable, u32 threshold,
u32 num)
{
u32 hartid = current_hartid();
plic_context_restore(plic_hartid2data[hartid],
plic_hartid2context[hartid][smode],
enable, threshold);
enable, threshold, num);
}
static int irqchip_plic_warm_init(void)