From 7beb0e066c85400fe0a4c9d966d729f505c086b8 Mon Sep 17 00:00:00 2001 From: jym Date: Tue, 1 Nov 2011 15:39:37 +0000 Subject: [PATCH] Avoid crashing when we do not explictly pass down a CPU when creating a kthread(9) in the LSIDL (KTHREAD_IDLE) state. --- sys/kern/kern_kthread.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c index a6b63fc387e9..7c51fbce2a8a 100644 --- a/sys/kern/kern_kthread.c +++ b/sys/kern/kern_kthread.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_kthread.c,v 1.37 2011/10/29 20:11:08 jym Exp $ */ +/* $NetBSD: kern_kthread.c,v 1.38 2011/11/01 15:39:37 jym Exp $ */ /*- * Copyright (c) 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_kthread.c,v 1.37 2011/10/29 20:11:08 jym Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_kthread.c,v 1.38 2011/11/01 15:39:37 jym Exp $"); #include #include @@ -140,8 +140,12 @@ kthread_create(pri_t pri, int flag, struct cpu_info *ci, l->l_stat = LSRUN; sched_enqueue(l, false); lwp_unlock(l); - } else - lwp_unlock_to(l, ci->ci_schedstate.spc_lwplock); + } else { + if (ci != NULL) + lwp_unlock_to(l, ci->ci_schedstate.spc_lwplock); + else + lwp_unlock(l); + } mutex_exit(proc0.p_lock); /* All done! */