All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers
@ 2022-11-28 13:21 Bin Meng
  2022-11-28 13:36 ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Bin Meng @ 2022-11-28 13:21 UTC (permalink / raw)
  To: opensbi

Interrupt source 0 is reserved. Hence the irq should start from 1.

Fixes: 2b79b694a805 ("lib: irqchip/plic: Add priority save/restore helpers")
Signed-off-by: Bin Meng <bmeng@tinylab.org>
---

 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 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);
 }
 
 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]);
 }
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers
  2022-11-28 13:21 [PATCH] lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers Bin Meng
@ 2022-11-28 13:36 ` Andreas Schwab
  2022-11-28 13:50   ` Bin Meng
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2022-11-28 13:36 UTC (permalink / raw)
  To: opensbi

On Nov 28 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 requires updating the size of the priority array.

-- 
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."


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers
  2022-11-28 13:36 ` Andreas Schwab
@ 2022-11-28 13:50   ` Bin Meng
  0 siblings, 0 replies; 3+ messages in thread
From: Bin Meng @ 2022-11-28 13:50 UTC (permalink / raw)
  To: opensbi

On 2022/11/28 21:36:24, "Andreas Schwab" <schwab@suse.de> wrote:

>On Nov 28 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 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-28 13:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-28 13:21 [PATCH] lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore helpers Bin Meng
2022-11-28 13:36 ` Andreas Schwab
2022-11-28 13:50   ` Bin Meng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.