autoconf(9): Provide diagnostics for config_detach_* misuse.

This commit is contained in:
riastradh 2022-08-12 16:16:12 +00:00
parent 7ce51081c7
commit 1536c4bfa3
1 changed files with 17 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_autoconf.c,v 1.301 2022/03/28 12:38:59 riastradh Exp $ */
/* $NetBSD: subr_autoconf.c,v 1.302 2022/08/12 16:16:12 riastradh Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.301 2022/03/28 12:38:59 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.302 2022/08/12 16:16:12 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@ -1919,6 +1919,7 @@ config_dump_garbage(struct devicelist *garbage)
static int
config_detach_enter(device_t dev)
{
struct lwp *l __diagused;
int error = 0;
mutex_enter(&config_misc_lock);
@ -1947,8 +1948,12 @@ config_detach_enter(device_t dev)
* running. Claim the device for detaching. This will cause
* all new attempts to acquire references to block.
*/
KASSERT(dev->dv_attaching == NULL);
KASSERT(dev->dv_detaching == NULL);
KASSERTMSG((l = dev->dv_attaching) == NULL,
"lwp %ld [%s] @ %p attaching",
(long)l->l_lid, (l->l_name ? l->l_name : l->l_proc->p_comm), l);
KASSERTMSG((l = dev->dv_detaching) == NULL,
"lwp %ld [%s] @ %p detaching",
(long)l->l_lid, (l->l_name ? l->l_name : l->l_proc->p_comm), l);
dev->dv_detaching = curlwp;
out: mutex_exit(&config_misc_lock);
@ -1958,9 +1963,12 @@ out: mutex_exit(&config_misc_lock);
static void
config_detach_exit(device_t dev)
{
struct lwp *l __diagused;
mutex_enter(&config_misc_lock);
KASSERT(dev->dv_detaching == curlwp);
KASSERTMSG((l = dev->dv_detaching) == curlwp,
"lwp %ld [%s] @ %p detaching",
(long)l->l_lid, (l->l_name ? l->l_name : l->l_proc->p_comm), l);
dev->dv_detaching = NULL;
cv_broadcast(&config_misc_cv);
mutex_exit(&config_misc_lock);
@ -2171,9 +2179,12 @@ out:
void
config_detach_commit(device_t dev)
{
struct lwp *l __diagused;
mutex_enter(&config_misc_lock);
KASSERT(dev->dv_detaching == curlwp);
KASSERTMSG((l = dev->dv_detaching) == curlwp,
"lwp %ld [%s] @ %p detaching",
(long)l->l_lid, (l->l_name ? l->l_name : l->l_proc->p_comm), l);
dev->dv_detached = true;
cv_broadcast(&config_misc_cv);
mutex_exit(&config_misc_lock);