diff mbox series

[2/3] xen: silence maybe-unitialized warning

Message ID 20240729142421.137283-3-stewart.hildebrand@amd.com (mailing list archive)
State New
Headers show
Series Stack checking on Arm | expand

Commit Message

Stewart Hildebrand July 29, 2024, 2:24 p.m. UTC
When building with gcc with -finstrument-functions, optimization level
-O1, CONFIG_HYPFS=y and # CONFIG_HAS_SCHED_GRANULARITY is not set, the
the following build warning (error) is encountered:

common/sched/cpupool.c: In function ‘cpupool_gran_write’:
common/sched/cpupool.c:1220:26: error: ‘gran’ may be used uninitialized [-Werror=maybe-uninitialized]
 1220 |                      0 : cpupool_check_granularity(gran);
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
common/sched/cpupool.c:1207:21: note: ‘gran’ declared here
 1207 |     enum sched_gran gran;
      |                     ^~~~

This is a false positive. Silence the warning (error) by initializing
the variable.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
---
 xen/common/sched/cpupool.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Juergen Gross July 29, 2024, 3:03 p.m. UTC | #1
On 29.07.24 16:24, Stewart Hildebrand wrote:
> When building with gcc with -finstrument-functions, optimization level
> -O1, CONFIG_HYPFS=y and # CONFIG_HAS_SCHED_GRANULARITY is not set, the
> the following build warning (error) is encountered:
> 
> common/sched/cpupool.c: In function ‘cpupool_gran_write’:
> common/sched/cpupool.c:1220:26: error: ‘gran’ may be used uninitialized [-Werror=maybe-uninitialized]
>   1220 |                      0 : cpupool_check_granularity(gran);
>        |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> common/sched/cpupool.c:1207:21: note: ‘gran’ declared here
>   1207 |     enum sched_gran gran;
>        |                     ^~~~
> 
> This is a false positive. Silence the warning (error) by initializing
> the variable.
> 
> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen
Stewart Hildebrand July 29, 2024, 7:01 p.m. UTC | #2
On 7/29/24 11:03, Jürgen Groß wrote:
> On 29.07.24 16:24, Stewart Hildebrand wrote:
>> When building with gcc with -finstrument-functions, optimization level
>> -O1, CONFIG_HYPFS=y and # CONFIG_HAS_SCHED_GRANULARITY is not set, the
>> the following build warning (error) is encountered:
>>
>> common/sched/cpupool.c: In function ‘cpupool_gran_write’:
>> common/sched/cpupool.c:1220:26: error: ‘gran’ may be used uninitialized [-Werror=maybe-uninitialized]
>>   1220 |                      0 : cpupool_check_granularity(gran);
>>        |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> common/sched/cpupool.c:1207:21: note: ‘gran’ declared here
>>   1207 |     enum sched_gran gran;
>>        |                     ^~~~
>>
>> This is a false positive. Silence the warning (error) by initializing
>> the variable.
>>
>> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
> 
> Reviewed-by: Juergen Gross <jgross@suse.com>

Thanks!

It just occurred to me: should the subject prefix be xen/cpupool:
instead of plain xen: ?
Juergen Gross July 30, 2024, 8:19 a.m. UTC | #3
On 29.07.24 21:01, Stewart Hildebrand wrote:
> On 7/29/24 11:03, Jürgen Groß wrote:
>> On 29.07.24 16:24, Stewart Hildebrand wrote:
>>> When building with gcc with -finstrument-functions, optimization level
>>> -O1, CONFIG_HYPFS=y and # CONFIG_HAS_SCHED_GRANULARITY is not set, the
>>> the following build warning (error) is encountered:
>>>
>>> common/sched/cpupool.c: In function ‘cpupool_gran_write’:
>>> common/sched/cpupool.c:1220:26: error: ‘gran’ may be used uninitialized [-Werror=maybe-uninitialized]
>>>    1220 |                      0 : cpupool_check_granularity(gran);
>>>         |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> common/sched/cpupool.c:1207:21: note: ‘gran’ declared here
>>>    1207 |     enum sched_gran gran;
>>>         |                     ^~~~
>>>
>>> This is a false positive. Silence the warning (error) by initializing
>>> the variable.
>>>
>>> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
>>
>> Reviewed-by: Juergen Gross <jgross@suse.com>
> 
> Thanks!
> 
> It just occurred to me: should the subject prefix be xen/cpupool:
> instead of plain xen: ?

Probably, yes.


Juergen
diff mbox series

Patch

diff --git a/xen/common/sched/cpupool.c b/xen/common/sched/cpupool.c
index 57dfee26f21f..3d02c7b70690 100644
--- a/xen/common/sched/cpupool.c
+++ b/xen/common/sched/cpupool.c
@@ -103,6 +103,7 @@  custom_param("sched-gran", sched_select_granularity);
 #elif defined(CONFIG_HYPFS)
 static int sched_gran_get(const char *str, enum sched_gran *mode)
 {
+    *mode = SCHED_GRAN_cpu;
     return -EINVAL;
 }
 #endif