Skip to content

Commit

Permalink
sched: fix build when NR_CPUS == 1
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jbeulich committed Mar 2, 2021
1 parent 9bd9695 commit 2de43f8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions xen/common/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2de43f8

Please sign in to comment.