Message ID | 20221211065424.806478-4-bmeng@tinylab.org |
---|---|
State | Accepted |
Headers | show |
Series | [v3,1/5] lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers | expand |
On 12/11/22 00:54, Bin Meng wrote: > plic->num_src holds the number of interrupt sources without interrupt > source 0 but the interrupt enable register includes a bit for the > interrupt source 0 in the first word. On the other hand, it is not really feasible to exclude the first bit here, so maybe it makes sense to leave patch 1 as it is for consistency. > Fixes: 415ecf28f7ad ("lib: irqchip/plic: Add context save/restore helpers") > Signed-off-by: Bin Meng <bmeng@tinylab.org> > Reviewed-by: Anup Patel <anup@brainfault.org> > > --- > > (no changes since v2) > > Changes in v2: > - new patch: lib: utils/irqchip: plic: Fix the off-by-one error in context save/restore helpers > > lib/utils/irqchip/plic.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) Reviewed-by: Samuel Holland <samuel@sholland.org>
On Sun, Dec 11, 2022 at 12:24 PM Bin Meng <bmeng@tinylab.org> wrote: > > plic->num_src holds the number of interrupt sources without interrupt > source 0 but the interrupt enable register includes a bit for the > interrupt source 0 in the first word. > > Fixes: 415ecf28f7ad ("lib: irqchip/plic: Add context save/restore helpers") > Signed-off-by: Bin Meng <bmeng@tinylab.org> > Reviewed-by: Anup Patel <anup@brainfault.org> Applied this patch to the riscv/opensbi repo. Thanks, Anup > > --- > > (no changes since v2) > > Changes in v2: > - new patch: lib: utils/irqchip: plic: Fix the off-by-one error in context save/restore helpers > > lib/utils/irqchip/plic.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/lib/utils/irqchip/plic.c b/lib/utils/irqchip/plic.c > index 568f814..b152bb7 100644 > --- a/lib/utils/irqchip/plic.c > +++ b/lib/utils/irqchip/plic.c > @@ -100,7 +100,7 @@ static void plic_set_ie(const struct plic_data *plic, u32 cntxid, > void plic_context_save(const struct plic_data *plic, int context_id, > u32 *enable, u32 *threshold) > { > - u32 ie_words = (plic->num_src + 31) / 32; > + u32 ie_words = plic->num_src / 32 + 1; > > for (u32 i = 0; i < ie_words; i++) > enable[i] = plic_get_ie(plic, context_id, i); > @@ -111,7 +111,7 @@ void plic_context_save(const struct plic_data *plic, int context_id, > void plic_context_restore(const struct plic_data *plic, int context_id, > const u32 *enable, u32 threshold) > { > - u32 ie_words = (plic->num_src + 31) / 32; > + u32 ie_words = plic->num_src / 32 + 1; > > for (u32 i = 0; i < ie_words; i++) > plic_set_ie(plic, context_id, i, enable[i]); > -- > 2.34.1 >
diff --git a/lib/utils/irqchip/plic.c b/lib/utils/irqchip/plic.c index 568f814..b152bb7 100644 --- a/lib/utils/irqchip/plic.c +++ b/lib/utils/irqchip/plic.c @@ -100,7 +100,7 @@ static void plic_set_ie(const struct plic_data *plic, u32 cntxid, void plic_context_save(const struct plic_data *plic, int context_id, u32 *enable, u32 *threshold) { - u32 ie_words = (plic->num_src + 31) / 32; + u32 ie_words = plic->num_src / 32 + 1; for (u32 i = 0; i < ie_words; i++) enable[i] = plic_get_ie(plic, context_id, i); @@ -111,7 +111,7 @@ void plic_context_save(const struct plic_data *plic, int context_id, void plic_context_restore(const struct plic_data *plic, int context_id, const u32 *enable, u32 threshold) { - u32 ie_words = (plic->num_src + 31) / 32; + u32 ie_words = plic->num_src / 32 + 1; for (u32 i = 0; i < ie_words; i++) plic_set_ie(plic, context_id, i, enable[i]);