diff mbox

[RFC,01/29] xen/arm: lr must be included in range [0-nr_lr[

Message ID dbdc34acd8d2270c8828d9cf9a03fbf6a4404f77.1367188423.git.julien.grall@linaro.org
State Changes Requested, archived
Headers show

Commit Message

Julien Grall April 28, 2013, 11:01 p.m. UTC
Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/arch/arm/gic.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Ian Campbell April 29, 2013, 2:55 p.m. UTC | #1
On Mon, 2013-04-29 at 00:01 +0100, Julien Grall wrote:

Typo in subject, [ at the end, did you mean ] or ) ? ( I can never
remember which one is inclusive)

> Signed-off-by: Julien Grall <julien.grall@linaro.org>
> ---
>  xen/arch/arm/gic.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c
> index bc8faf2..bac2af2 100644
> --- a/xen/arch/arm/gic.c
> +++ b/xen/arch/arm/gic.c
> @@ -512,7 +512,9 @@ static inline void gic_set_lr(int lr, unsigned int virtual_irq,
>  {
>      int maintenance_int = GICH_LR_MAINTENANCE_IRQ;
>  
> -    BUG_ON(lr > nr_lrs);
> +    BUG_ON(lr >= nr_lrs);
> +    BUG_ON(lr < 0);

> +    BUG_ON(state & ~(GICH_LR_STATE_MASK<<GICH_LR_STATE_SHIFT));

This suggests that STATE_MASK is inconveniently defined, it'd be more
normal to include the SHIFT in the mask.

The same is true of all the other GICH_LR_*_MASK/SHIFT defines. The only
one which is used is GICH_LR_VIRTUAL_MASK+SHIFT, and I guess I can see
why in that case. 

Acked-by: Ian Campbell <ian.campbell@citrix.com>

Ian.

>  
>      GICH[GICH_LR + lr] = state |
>          maintenance_int |
Julien Grall April 29, 2013, 3:13 p.m. UTC | #2
On 04/29/2013 03:55 PM, Ian Campbell wrote:

> On Mon, 2013-04-29 at 00:01 +0100, Julien Grall wrote:
> 
> Typo in subject, [ at the end, did you mean ] or ) ? ( I can never
> remember which one is inclusive)

I mean ). But [ is also accepted even if it's non-standard.
http://mathworld.wolfram.com/OpenInterval.html
I will fix it.

>> Signed-off-by: Julien Grall <julien.grall@linaro.org>
>> ---
>>  xen/arch/arm/gic.c |    4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c
>> index bc8faf2..bac2af2 100644
>> --- a/xen/arch/arm/gic.c
>> +++ b/xen/arch/arm/gic.c
>> @@ -512,7 +512,9 @@ static inline void gic_set_lr(int lr, unsigned int virtual_irq,
>>  {
>>      int maintenance_int = GICH_LR_MAINTENANCE_IRQ;
>>  
>> -    BUG_ON(lr > nr_lrs);
>> +    BUG_ON(lr >= nr_lrs);
>> +    BUG_ON(lr < 0);
> 
>> +    BUG_ON(state & ~(GICH_LR_STATE_MASK<<GICH_LR_STATE_SHIFT));
> 
> This suggests that STATE_MASK is inconveniently defined, it'd be more
> normal to include the SHIFT in the mask.
> 
> The same is true of all the other GICH_LR_*_MASK/SHIFT defines. The only
> one which is used is GICH_LR_VIRTUAL_MASK+SHIFT, and I guess I can see
> why in that case. 
>


I think all GICH_LR_*_MASK must be consistent. If we modify
GICH_LR_STATE_* we need to modify all the others.

This is basically the same for GICH_LR_PRIORITY_MASK/SHIFT but
it's seems we don't use the mask.
diff mbox

Patch

diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c
index bc8faf2..bac2af2 100644
--- a/xen/arch/arm/gic.c
+++ b/xen/arch/arm/gic.c
@@ -512,7 +512,9 @@  static inline void gic_set_lr(int lr, unsigned int virtual_irq,
 {
     int maintenance_int = GICH_LR_MAINTENANCE_IRQ;
 
-    BUG_ON(lr > nr_lrs);
+    BUG_ON(lr >= nr_lrs);
+    BUG_ON(lr < 0);
+    BUG_ON(state & ~(GICH_LR_STATE_MASK<<GICH_LR_STATE_SHIFT));
 
     GICH[GICH_LR + lr] = state |
         maintenance_int |