Module Name:    src
Committed By:   skrll
Date:           Tue Nov 13 11:06:19 UTC 2018

Modified Files:
        src/sys/kern: kern_cpu.c

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

Discussed with rmind


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/kern/kern_cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_cpu.c
diff -u src/sys/kern/kern_cpu.c:1.74 src/sys/kern/kern_cpu.c:1.75
--- src/sys/kern/kern_cpu.c:1.74	Wed Jul  4 07:25:47 2018
+++ src/sys/kern/kern_cpu.c	Tue Nov 13 11:06:19 2018
@@ -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 @@ cpu_lookup(u_int idx)
 {
 	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 @@ cpu_lookup(u_int idx)
 
 	ci = cpu_infos[idx];
 	KASSERT(ci == NULL || cpu_index(ci) == idx);
+	KASSERTMSG(idx < maxcpus || ci == NULL, "idx %d ci %p", idx, ci);
 
 	return ci;
 }

Reply via email to