Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Fix/add KASSERTS to work with a system of MAXCPUS. ...



details:   https://anonhg.NetBSD.org/src/rev/a294e9f8f108
branches:  trunk
changeset: 836942:a294e9f8f108
user:      skrll <skrll%NetBSD.org@localhost>
date:      Tue Nov 13 11:06:19 2018 +0000

description:
Fix/add KASSERTS to work with a system of MAXCPUS.  Add some comments to
explain things.

Discussed with rmind

diffstat:

 sys/kern/kern_cpu.c |  11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diffs (39 lines):

diff -r 673a1ba4fa86 -r a294e9f8f108 sys/kern/kern_cpu.c
--- a/sys/kern/kern_cpu.c       Tue Nov 13 11:01:54 2018 +0000
+++ b/sys/kern/kern_cpu.c       Tue Nov 13 11:06:19 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_cpu.c,v 1.74 2018/07/04 07:25:47 msaitoh Exp $    */
+/*     $NetBSD: kern_cpu.c,v 1.75 2018/11/13 11:06:19 skrll Exp $      */
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2010, 2012 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.74 2018/07/04 07:25:47 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.75 2018/11/13 11:06:19 skrll Exp $");
 
 #include "opt_cpu_ucode.h"
 
@@ -309,7 +309,11 @@
 {
        struct cpu_info *ci;
 
-       KASSERT(idx < maxcpus);
+       /*
+        * cpu_infos is a NULL terminated array of MAXCPUS + 1 entries,
+        * so an index of MAXCPUS here is ok.  See mi_cpu_attach.
+        */
+       KASSERT(idx <= maxcpus);
 
        if (__predict_false(cpu_infos == NULL)) {
                KASSERT(idx == 0);
@@ -318,6 +322,7 @@
 
        ci = cpu_infos[idx];
        KASSERT(ci == NULL || cpu_index(ci) == idx);
+       KASSERTMSG(idx < maxcpus || ci == NULL, "idx %d ci %p", idx, ci);
 
        return ci;
 }



Home | Main Index | Thread Index | Old Index