[PATCH v3 1/5] lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers

Samuel Holland samuel at sholland.org
Sun Dec 11 22:40:20 PST 2022


On 12/11/22 04:18, Bin Meng wrote:
> On Sun, Dec 11, 2022 at 6:08 PM Andreas Schwab <schwab at linux-m68k.org> wrote:
>>
>> On Dez 11 2022, Bin Meng wrote:
>>
>>> diff --git a/lib/utils/irqchip/plic.c b/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 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 needs to adjust the index into the priority array.
> 
> Does that help anything? It just confuses people more.
> 
> I added function parameter descriptions in patch 2 to make it crystal
> clear, that the priority array needs to include interrupt source 0.

To me, it is more confusing that when I ask to save the priority for N
sources, I need to allocate an array with >N elements. And leaving array
element 0 unused wastes memory.

Regards,
Samuel




More information about the opensbi mailing list