diff mbox series

[3/3] xen/arm: fix unitialized use warning

Message ID 20230414185714.292881-4-stewart.hildebrand@amd.com (mailing list archive)
State New, archived
Headers show
Series xen/arm: fix build errors with -Og | expand

Commit Message

Stewart Hildebrand April 14, 2023, 6:57 p.m. UTC
When building the hypervisor with -Og, we encounter the following error:

arch/arm/domain_build.c: In function ‘make_cpus_node’:
arch/arm/domain_build.c:2040:12: error: ‘clock_valid’ may be used uninitialized [-Werror=maybe-uninitialized]
 2040 |         if ( clock_valid )
      |            ^
arch/arm/domain_build.c:1947:10: note: ‘clock_valid’ was declared here
 1947 |     bool clock_valid;
      |          ^~~~~~~~~~~
cc1: all warnings being treated as errors

Fix it by initializing the variable.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
---
See previous discussion here
https://lists.xenproject.org/archives/html/xen-devel/2022-10/msg00741.html
---
 xen/arch/arm/domain_build.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Henry Wang April 15, 2023, 5 a.m. UTC | #1
Hi Stewart,

> -----Original Message-----
> Subject: [PATCH 3/3] xen/arm: fix unitialized use warning
> 
> When building the hypervisor with -Og, we encounter the following error:
> 
> arch/arm/domain_build.c: In function ‘make_cpus_node’:
> arch/arm/domain_build.c:2040:12: error: ‘clock_valid’ may be used
> uninitialized [-Werror=maybe-uninitialized]
>  2040 |         if ( clock_valid )
>       |            ^
> arch/arm/domain_build.c:1947:10: note: ‘clock_valid’ was declared here
>  1947 |     bool clock_valid;
>       |          ^~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> Fix it by initializing the variable.
> 
> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>

Reviewed-by: Henry Wang <Henry.Wang@arm.com>

Kind regards,
Henry
Julien Grall April 16, 2023, 12:53 p.m. UTC | #2
Hi Stewart,

On 14/04/2023 19:57, Stewart Hildebrand wrote:
> When building the hypervisor with -Og, we encounter the following error:

Is this with GCC 12 as well?

> arch/arm/domain_build.c: In function ‘make_cpus_node’:
> arch/arm/domain_build.c:2040:12: error: ‘clock_valid’ may be used uninitialized [-Werror=maybe-uninitialized]
>   2040 |         if ( clock_valid )
>        |            ^
> arch/arm/domain_build.c:1947:10: note: ‘clock_valid’ was declared here
>   1947 |     bool clock_valid;
>        |          ^~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> Fix it by initializing the variable.
> 
> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
> ---
> See previous discussion here
> https://lists.xenproject.org/archives/html/xen-devel/2022-10/msg00741.html
> ---
>   xen/arch/arm/domain_build.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index 4f9d4f9d8867..18b350734a8e 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -1944,7 +1944,7 @@ static int __init make_cpus_node(const struct domain *d, void *fdt)
>       /* Placeholder for cpu@ + a 32-bit hexadecimal number + \0 */
>       char buf[13];
>       u32 clock_frequency;
> -    bool clock_valid;
> +    bool clock_valid = false;

NIT: I would add "Keep the compiler happy with -Og"

I am happy to add it while committing if you agree.

Reviewed-by: Julien Grall <jgrall@amazon.com>

Cheers,
Stewart Hildebrand April 17, 2023, 2:03 a.m. UTC | #3
On 4/16/23 08:53, Julien Grall wrote:
> Hi Stewart,

Hi Julien,

> On 14/04/2023 19:57, Stewart Hildebrand wrote:
>> When building the hypervisor with -Og, we encounter the following error:
> 
> Is this with GCC 12 as well?

Yes. If my memory serves me correctly this particular one occurs with both GCC 11 and 12.

>> arch/arm/domain_build.c: In function ‘make_cpus_node’:
>> arch/arm/domain_build.c:2040:12: error: ‘clock_valid’ may be used uninitialized [-Werror=maybe-uninitialized]
>>   2040 |         if ( clock_valid )
>>        |            ^
>> arch/arm/domain_build.c:1947:10: note: ‘clock_valid’ was declared here
>>   1947 |     bool clock_valid;
>>        |          ^~~~~~~~~~~
>> cc1: all warnings being treated as errors
>>
>> Fix it by initializing the variable.
>>
>> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
>> ---
>> See previous discussion here
>> https://lists.xenproject.org/archives/html/xen-devel/2022-10/msg00741.html
>> ---
>>   xen/arch/arm/domain_build.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
>> index 4f9d4f9d8867..18b350734a8e 100644
>> --- a/xen/arch/arm/domain_build.c
>> +++ b/xen/arch/arm/domain_build.c
>> @@ -1944,7 +1944,7 @@ static int __init make_cpus_node(const struct domain *d, void *fdt)
>>       /* Placeholder for cpu@ + a 32-bit hexadecimal number + \0 */
>>       char buf[13];
>>       u32 clock_frequency;
>> -    bool clock_valid;
>> +    bool clock_valid = false;
> 
> NIT: I would add "Keep the compiler happy with -Og"
> 
> I am happy to add it while committing if you agree.

Yes, please do. Thanks.

> Reviewed-by: Julien Grall <jgrall@amazon.com>
> 
> Cheers,
> 
> -- 
> Julien Grall
Stewart Hildebrand April 17, 2023, 2:08 a.m. UTC | #4
On 4/16/23 22:03, Stewart Hildebrand wrote:
> On 4/16/23 08:53, Julien Grall wrote:
>> Hi Stewart,
> 
> Hi Julien,
> 
>> On 14/04/2023 19:57, Stewart Hildebrand wrote:
>>> When building the hypervisor with -Og, we encounter the following error:
>>
>> Is this with GCC 12 as well?
> 
> Yes. If my memory serves me correctly this particular one occurs with both GCC 11 and 12.
> 
>>> arch/arm/domain_build.c: In function ‘make_cpus_node’:
>>> arch/arm/domain_build.c:2040:12: error: ‘clock_valid’ may be used uninitialized [-Werror=maybe-uninitialized]
>>>   2040 |         if ( clock_valid )
>>>        |            ^
>>> arch/arm/domain_build.c:1947:10: note: ‘clock_valid’ was declared here
>>>   1947 |     bool clock_valid;
>>>        |          ^~~~~~~~~~~
>>> cc1: all warnings being treated as errors
>>>
>>> Fix it by initializing the variable.
>>>
>>> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
>>> ---
>>> See previous discussion here
>>> https://lists.xenproject.org/archives/html/xen-devel/2022-10/msg00741.html
>>> ---
>>>   xen/arch/arm/domain_build.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
>>> index 4f9d4f9d8867..18b350734a8e 100644
>>> --- a/xen/arch/arm/domain_build.c
>>> +++ b/xen/arch/arm/domain_build.c
>>> @@ -1944,7 +1944,7 @@ static int __init make_cpus_node(const struct domain *d, void *fdt)
>>>       /* Placeholder for cpu@ + a 32-bit hexadecimal number + \0 */
>>>       char buf[13];
>>>       u32 clock_frequency;
>>> -    bool clock_valid;
>>> +    bool clock_valid = false;
>>
>> NIT: I would add "Keep the compiler happy with -Og"
>>
>> I am happy to add it while committing if you agree.
> 
> Yes, please do. Thanks.

One more thing, there is a typo in the subject, if you are willing to correct it while committing. s/unitialized/uninitialized/

>> Reviewed-by: Julien Grall <jgrall@amazon.com>
>>
>> Cheers,
>>
>> --
>> Julien Grall
>
Julien Grall April 19, 2023, 6:26 p.m. UTC | #5
Hi Stewart,

On 17/04/2023 03:08, Stewart Hildebrand wrote:
> On 4/16/23 22:03, Stewart Hildebrand wrote:
>> On 4/16/23 08:53, Julien Grall wrote:
>>> Hi Stewart,
>>
>> Hi Julien,
>>
>>> On 14/04/2023 19:57, Stewart Hildebrand wrote:
>>>> When building the hypervisor with -Og, we encounter the following error:
>>>
>>> Is this with GCC 12 as well?
>>
>> Yes. If my memory serves me correctly this particular one occurs with both GCC 11 and 12.

Thanks. I will update the commit message to mention it.

>>
>>>> arch/arm/domain_build.c: In function ‘make_cpus_node’:
>>>> arch/arm/domain_build.c:2040:12: error: ‘clock_valid’ may be used uninitialized [-Werror=maybe-uninitialized]
>>>>    2040 |         if ( clock_valid )
>>>>         |            ^
>>>> arch/arm/domain_build.c:1947:10: note: ‘clock_valid’ was declared here
>>>>    1947 |     bool clock_valid;
>>>>         |          ^~~~~~~~~~~
>>>> cc1: all warnings being treated as errors
>>>>
>>>> Fix it by initializing the variable.
>>>>
>>>> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
>>>> ---
>>>> See previous discussion here
>>>> https://lists.xenproject.org/archives/html/xen-devel/2022-10/msg00741.html
>>>> ---
>>>>    xen/arch/arm/domain_build.c | 2 +-
>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
>>>> index 4f9d4f9d8867..18b350734a8e 100644
>>>> --- a/xen/arch/arm/domain_build.c
>>>> +++ b/xen/arch/arm/domain_build.c
>>>> @@ -1944,7 +1944,7 @@ static int __init make_cpus_node(const struct domain *d, void *fdt)
>>>>        /* Placeholder for cpu@ + a 32-bit hexadecimal number + \0 */
>>>>        char buf[13];
>>>>        u32 clock_frequency;
>>>> -    bool clock_valid;
>>>> +    bool clock_valid = false;
>>>
>>> NIT: I would add "Keep the compiler happy with -Og"
>>>
>>> I am happy to add it while committing if you agree.
>>
>> Yes, please do. Thanks.
> 
> One more thing, there is a typo in the subject, if you are willing to correct it while committing. s/unitialized/uninitialized/

Sure. I will do that.

Cheers,
diff mbox series

Patch

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 4f9d4f9d8867..18b350734a8e 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1944,7 +1944,7 @@  static int __init make_cpus_node(const struct domain *d, void *fdt)
     /* Placeholder for cpu@ + a 32-bit hexadecimal number + \0 */
     char buf[13];
     u32 clock_frequency;
-    bool clock_valid;
+    bool clock_valid = false;
     uint64_t mpidr_aff;
 
     dt_dprintk("Create cpus node\n");