diff mbox series

[1/2,4.15?] sched: fix build when NR_CPUS == 1

Message ID 171d1da4-e87a-b154-5c63-a5627d4f93bc@suse.com (mailing list archive)
State New, archived
Headers show
Series fix build when NR_CPUS == 1 | expand

Commit Message

Jan Beulich March 1, 2021, 8:30 a.m. UTC
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>

Comments

Ian Jackson March 1, 2021, 3:57 p.m. UTC | #1
Jan Beulich writes ("[PATCH 1/2][4.15?] sched: fix build when NR_CPUS == 1"):
> In this case the compiler is recognizing that no valid array indexes
> remain, and hence e.g. reports:

Release-Acked-by: Ian Jackson <iwj@xenproject.org>
Dario Faggioli March 1, 2021, 5:50 p.m. UTC | #2
On Mon, 2021-03-01 at 15:57 +0000, Ian Jackson wrote:
> Jan Beulich writes ("[PATCH 1/2][4.15?] sched: fix build when NR_CPUS
> == 1"):
> > In this case the compiler is recognizing that no valid array
> > indexes
> > remain, and hence e.g. reports:
> 
> Release-Acked-by: Ian Jackson <iwj@xenproject.org>
>
Reviewed-by: Dario Faggioli <dfaggioli@suse.com>

Regards
diff mbox series

Patch

--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -2768,6 +2768,12 @@  static int cpu_schedule_up(unsigned int
     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