Sun Apr 16 11:18:25 2023 UTC ()
autoconf(9): Assert alldevs_lock held in config_unit_nextfree.

The one caller, config_unit_alloc, guarantees it through
config_alldevs_enter/exit.


(riastradh)
diff -r1.308 -r1.309 src/sys/kern/subr_autoconf.c

cvs diff -r1.308 -r1.309 src/sys/kern/subr_autoconf.c (expand / switch to unified diff)

--- src/sys/kern/subr_autoconf.c 2023/04/16 11:14:58 1.308
+++ src/sys/kern/subr_autoconf.c 2023/04/16 11:18:25 1.309
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: subr_autoconf.c,v 1.308 2023/04/16 11:14:58 riastradh Exp $ */ 1/* $NetBSD: subr_autoconf.c,v 1.309 2023/04/16 11:18:25 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 2000 Christopher G. Demetriou 4 * Copyright (c) 1996, 2000 Christopher G. Demetriou
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -67,27 +67,27 @@ @@ -67,27 +67,27 @@
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * SUCH DAMAGE. 72 * SUCH DAMAGE.
73 * 73 *
74 * from: Header: subr_autoconf.c,v 1.12 93/02/01 19:31:48 torek Exp (LBL) 74 * from: Header: subr_autoconf.c,v 1.12 93/02/01 19:31:48 torek Exp (LBL)
75 * 75 *
76 * @(#)subr_autoconf.c 8.3 (Berkeley) 5/17/94 76 * @(#)subr_autoconf.c 8.3 (Berkeley) 5/17/94
77 */ 77 */
78 78
79#include <sys/cdefs.h> 79#include <sys/cdefs.h>
80__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.308 2023/04/16 11:14:58 riastradh Exp $"); 80__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.309 2023/04/16 11:18:25 riastradh Exp $");
81 81
82#ifdef _KERNEL_OPT 82#ifdef _KERNEL_OPT
83#include "opt_ddb.h" 83#include "opt_ddb.h"
84#include "drvctl.h" 84#include "drvctl.h"
85#endif 85#endif
86 86
87#include <sys/param.h> 87#include <sys/param.h>
88#include <sys/device.h> 88#include <sys/device.h>
89#include <sys/device_impl.h> 89#include <sys/device_impl.h>
90#include <sys/disklabel.h> 90#include <sys/disklabel.h>
91#include <sys/conf.h> 91#include <sys/conf.h>
92#include <sys/kauth.h> 92#include <sys/kauth.h>
93#include <sys/kmem.h> 93#include <sys/kmem.h>
@@ -1473,26 +1473,28 @@ config_devdelete(device_t dev) @@ -1473,26 +1473,28 @@ config_devdelete(device_t dev)
1473 if (dev->dv_locators) { 1473 if (dev->dv_locators) {
1474 size_t amount = *--dev->dv_locators; 1474 size_t amount = *--dev->dv_locators;
1475 kmem_free(dev->dv_locators, amount); 1475 kmem_free(dev->dv_locators, amount);
1476 } 1476 }
1477 1477
1478 config_devfree(dev); 1478 config_devfree(dev);
1479} 1479}
1480 1480
1481static int 1481static int
1482config_unit_nextfree(cfdriver_t cd, cfdata_t cf) 1482config_unit_nextfree(cfdriver_t cd, cfdata_t cf)
1483{ 1483{
1484 int unit = cf->cf_unit; 1484 int unit = cf->cf_unit;
1485 1485
 1486 KASSERT(mutex_owned(&alldevs_lock));
 1487
1486 if (unit < 0) 1488 if (unit < 0)
1487 return -1; 1489 return -1;
1488 if (cf->cf_fstate == FSTATE_STAR) { 1490 if (cf->cf_fstate == FSTATE_STAR) {
1489 for (; unit < cd->cd_ndevs; unit++) 1491 for (; unit < cd->cd_ndevs; unit++)
1490 if (cd->cd_devs[unit] == NULL) 1492 if (cd->cd_devs[unit] == NULL)
1491 break; 1493 break;
1492 /* 1494 /*
1493 * unit is now the unit of the first NULL device pointer, 1495 * unit is now the unit of the first NULL device pointer,
1494 * or max(cd->cd_ndevs,cf->cf_unit). 1496 * or max(cd->cd_ndevs,cf->cf_unit).
1495 */ 1497 */
1496 } else { 1498 } else {
1497 if (unit < cd->cd_ndevs && cd->cd_devs[unit] != NULL) 1499 if (unit < cd->cd_ndevs && cd->cd_devs[unit] != NULL)
1498 unit = -1; 1500 unit = -1;