diff mbox series

[Xen-devel,09/12] xen/arm: guest_walk: Avoid theoritical unitialized value in get_top_bit

Message ID 20190327184531.30986-10-julien.grall@arm.com
State New
Headers show
Series xen/arm: Add support to build with clang | expand

Commit Message

Julien Grall March 27, 2019, 6:45 p.m. UTC
Clang 8.0 throws an error in the get_top_bit function:

guest_walk.c:328:15: error: variable 'topbit' is used uninitialized
whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
    else if ( is_64bit_domain(d) )
              ^~~~~~~~~~~~~~~~~~

This is happening because clang thinks that is_32bit_domain(d) is not
the exact inverse of is_64bit_domain(d). So it expects a else case to
handle the case where the latter call is false.

In other part of the code, dealing with difference between 32-bit and
64-bit domain, we usually use if ( is_XXbit_domain ) ... else ...

So use the same pattern here.

Signed-off-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/guest_walk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Stabellini April 17, 2019, 8:31 p.m. UTC | #1
On Wed, 27 Mar 2019, Julien Grall wrote:
> Clang 8.0 throws an error in the get_top_bit function:
> 
> guest_walk.c:328:15: error: variable 'topbit' is used uninitialized
> whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
>     else if ( is_64bit_domain(d) )
>               ^~~~~~~~~~~~~~~~~~
> 
> This is happening because clang thinks that is_32bit_domain(d) is not
> the exact inverse of is_64bit_domain(d). So it expects a else case to
> handle the case where the latter call is false.
> 
> In other part of the code, dealing with difference between 32-bit and
> 64-bit domain, we usually use if ( is_XXbit_domain ) ... else ...
> 
> So use the same pattern here.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
>  xen/arch/arm/guest_walk.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c
> index 7db7a7321b..1bee198777 100644
> --- a/xen/arch/arm/guest_walk.c
> +++ b/xen/arch/arm/guest_walk.c
> @@ -325,7 +325,7 @@ static unsigned int get_top_bit(struct domain *d, vaddr_t gva, register_t tcr)
>       */
>      if ( is_32bit_domain(d) )
>          topbit = 31;
> -    else if ( is_64bit_domain(d) )
> +    else
>      {
>          if ( ((gva & BIT_ULL(55)) && (tcr & TCR_EL1_TBI1)) ||
>               (!(gva & BIT_ULL(55)) && (tcr & TCR_EL1_TBI0)) )
> -- 
> 2.11.0
>
diff mbox series

Patch

diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c
index 7db7a7321b..1bee198777 100644
--- a/xen/arch/arm/guest_walk.c
+++ b/xen/arch/arm/guest_walk.c
@@ -325,7 +325,7 @@  static unsigned int get_top_bit(struct domain *d, vaddr_t gva, register_t tcr)
      */
     if ( is_32bit_domain(d) )
         topbit = 31;
-    else if ( is_64bit_domain(d) )
+    else
     {
         if ( ((gva & BIT_ULL(55)) && (tcr & TCR_EL1_TBI1)) ||
              (!(gva & BIT_ULL(55)) && (tcr & TCR_EL1_TBI0)) )