]> xenbits.xensource.com Git - people/tklengyel/xen.git/commitdiff
sched: fix build when NR_CPUS == 1
authorJan Beulich <jbeulich@suse.com>
Tue, 2 Mar 2021 11:29:16 +0000 (12:29 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 2 Mar 2021 11:29:16 +0000 (12:29 +0100)
In this case the compiler is recognizing that no valid array indexes
remain, and hence e.g. reports:

core.c: In function 'cpu_schedule_up':
core.c:2769:19: error: array subscript 1 is above array bounds
of 'struct vcpu *[1]' [-Werror=array-bounds]
 2769 |     if ( idle_vcpu[cpu] == NULL )
      |          ~~~~~~~~~^~~~~

Reported-by: Connor Davis <connojdavis@gmail.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Dario Faggioli <dfaggioli@suse.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
xen/common/sched/core.c

index 2b974fd6f8bacf293e8669b8842724932665617f..6d34764d384561dcd76e7cd3ca418c1b7d03caf4 100644 (file)
@@ -2768,6 +2768,12 @@ static int cpu_schedule_up(unsigned int cpu)
     if ( cpu == 0 )
         return 0;
 
+    /*
+     * Guard in particular against the compiler suspecting out-of-bounds
+     * array accesses below when NR_CPUS=1.
+     */
+    BUG_ON(cpu >= NR_CPUS);
+
     if ( idle_vcpu[cpu] == NULL )
         vcpu_create(idle_vcpu[0]->domain, cpu);
     else