lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers
PATCH 1/1 lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers
Interrupt source 0 is reserved. Hence the irq should start from 1.
---
lib/utils/irqchip/plic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/utils/irqchip/plic.c +2 -2
@@ -38,13 +38,13 @@ static void plic_set_priority(const struct plic_data *plic, u32 source, u32 val)void plic_priority_save (const struct plic_data *plic,u8 *priority) { -for (u32 i =0 ; i < plic->num_src; i++) +for (u32 i =1 ; i <= plic->num_src; i++) priority[i] =plic_get_priority (plic, i); }void plic_priority_restore (const struct plic_data *plic,const u8 *priority) { -for (u32 i =0 ; i < plic->num_src; i++) +for (u32 i =1 ; i <= plic->num_src; i++)plic_set_priority (plic, i, priority[i]); }
Signature · 1 line
2.34.1
PATCH 1/1 lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers
lib/utils/irqchip/plic.c static void plic_set_priority(const struct plic_data *plic, u32 source, u32 val) · line 42
Quoted 11 lines · Bin Meng
lib/utils/irqchip/plic.c +1
-1@@ -38,13 +38,13 @@ static void plic_set_priority(const struct plic_data *plic, u32 source, u32 val)void plic_priority_save (const struct plic_data *plic,u8 *priority) { -for (u32 i =0 ; i < plic->num_src; i++) +for (u32 i =1 ; i <= plic->num_src; i++) priority[i] =plic_get_priority (plic, i);
That requires updating the size of the priority array.
Signature · 3 lines
Andreas Schwab, SUSE Labs, schwab at suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."
PATCH 1/1 lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers
Quoted 8 lines · Andreas Schwab
Quoted 6 lines · Bin Meng
diff --git
a/lib/utils/irqchip/plic.cb/lib/utils/irqchip/plic.c
index 73d7788..4df9020 100644
---a/lib/utils/irqchip/plic.c
+++b/lib/utils/irqchip/plic.c
@@ -38,13 +38,13 @@ static voidplic_set_priority(const struct plic_data *plic, u32 source, u32 val)
Quoted 7 lines
Quoted 5 lines
void
plic_priority_save(const struct plic_data *plic, u8 *priority){
- for (u32 i = 0; i <plic->num_src; i++)
+ for (u32 i = 1; i <=plic->num_src; i++)
priority[i] =plic_get_priority(plic, i);That requires updating the size of the priority array.
These 2 APIs are really poorly designed. The index to the priority array is controlled by plic->num_src which comes from DTS, so there is potentially a mismatch between the DTS property value and the size of the priority array.
Currently the only user of these 2 APIs in OpenSBI is D1 and the size of the priority array is set to 176. There is no problem if DTS provides a less than 176 value. Otherwise it can cause out-of-bound access in OpenSBI.
Regards,
Bin