Module Name:    src
Committed By:   riastradh
Date:           Mon Mar 31 14:45:35 UTC 2025

Modified Files:
        src/sys/arch/mips/ralink: ralink_ehci.c
        src/sys/dev/cardbus: ehci_cardbus.c
        src/sys/dev/pci: ehci_pci.c usb_pci.c

Log Message:
ehci(4): Sprinkle KERNEL_LOCKED_P and KNF on usb_*_add/rem.

Mark with XXXSMP comments to be fixed later without the kernel lock.

No functional change intended: callers generally do this from
autoconf *_attach/detach routines, which run kernel-locked anyway
(for the moment).

Cleanup in preparation for:

PR port-amd64/59180: System reboots instead of shutting down


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/mips/ralink/ralink_ehci.c
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/cardbus/ehci_cardbus.c
cvs rdiff -u -r1.77 -r1.78 src/sys/dev/pci/ehci_pci.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/pci/usb_pci.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/arch/mips/ralink/ralink_ehci.c
diff -u src/sys/arch/mips/ralink/ralink_ehci.c:1.9 src/sys/arch/mips/ralink/ralink_ehci.c:1.10
--- src/sys/arch/mips/ralink/ralink_ehci.c:1.9	Sat Aug  7 16:18:59 2021
+++ src/sys/arch/mips/ralink/ralink_ehci.c	Mon Mar 31 14:45:35 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: ralink_ehci.c,v 1.9 2021/08/07 16:18:59 thorpej Exp $	*/
+/*	$NetBSD: ralink_ehci.c,v 1.10 2025/03/31 14:45:35 riastradh Exp $	*/
 /*-
  * Copyright (c) 2011 CradlePoint Technology, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
 /* ralink_ehci.c -- Ralink EHCI USB Driver */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ralink_ehci.c,v 1.9 2021/08/07 16:18:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ralink_ehci.c,v 1.10 2025/03/31 14:45:35 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -57,15 +57,11 @@ static void ralink_ehci_attach(device_t,
 static int  ralink_ehci_detach(device_t, int);
 
 CFATTACH_DECL2_NEW(ralink_ehci, sizeof(struct ralink_ehci_softc),
-	ralink_ehci_match, ralink_ehci_attach, ralink_ehci_detach,
-	ehci_activate, NULL, ehci_childdet);
+    ralink_ehci_match, ralink_ehci_attach, ralink_ehci_detach,
+    ehci_activate, NULL, ehci_childdet);
 
 static TAILQ_HEAD(, ralink_usb_hc) ralink_usb_alldevs =
-	TAILQ_HEAD_INITIALIZER(ralink_usb_alldevs);
-
-#if 0
-struct usb_hc_alldevs ralink_usb_alldevs = TAILQ_HEAD_INITIALIZER(ralink_usb_alldevs);
-#endif
+    TAILQ_HEAD_INITIALIZER(ralink_usb_alldevs);
 
 /*
  * ralink_ehci_match
@@ -144,6 +140,7 @@ ralink_ehci_attach(device_t parent, devi
 	 * have lower function numbers so they should be enumerated already.
 	 */
 	int ncomp = 0;
+	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ralink_usb_alldevs */
 	TAILQ_FOREACH(ruh, &ralink_usb_alldevs, next) {
 		aprint_normal_dev(self, "companion %s\n",
 			device_xname(ruh->usb));
@@ -207,6 +204,9 @@ ralink_ehci_detach(device_t self, int fl
 void
 ralink_usb_hc_add(struct ralink_usb_hc *ruh, device_t usbp)
 {
+
+	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ralink_usb_alldevs */
+
 	TAILQ_INSERT_TAIL(&ralink_usb_alldevs, ruh, next);
 	ruh->usb = usbp;
 }
@@ -214,5 +214,8 @@ ralink_usb_hc_add(struct ralink_usb_hc *
 void
 ralink_usb_hc_rem(struct ralink_usb_hc *ruh)
 {
+
+	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ralink_usb_alldevs */
+
 	TAILQ_REMOVE(&ralink_usb_alldevs, ruh, next);
 }

Index: src/sys/dev/cardbus/ehci_cardbus.c
diff -u src/sys/dev/cardbus/ehci_cardbus.c:1.37 src/sys/dev/cardbus/ehci_cardbus.c:1.38
--- src/sys/dev/cardbus/ehci_cardbus.c:1.37	Sat Aug  7 16:19:10 2021
+++ src/sys/dev/cardbus/ehci_cardbus.c	Mon Mar 31 14:45:35 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: ehci_cardbus.c,v 1.37 2021/08/07 16:19:10 thorpej Exp $	*/
+/*	$NetBSD: ehci_cardbus.c,v 1.38 2025/03/31 14:45:35 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci_cardbus.c,v 1.37 2021/08/07 16:19:10 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci_cardbus.c,v 1.38 2025/03/31 14:45:35 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -82,7 +82,7 @@ CFATTACH_DECL_NEW(ehci_cardbus, sizeof(s
     ehci_activate);
 
 static TAILQ_HEAD(, usb_cardbus) ehci_cardbus_alldevs =
-	TAILQ_HEAD_INITIALIZER(ehci_cardbus_alldevs);
+    TAILQ_HEAD_INITIALIZER(ehci_cardbus_alldevs);
 
 int
 ehci_cardbus_match(device_t parent, cfdata_t match, void *aux)
@@ -175,6 +175,7 @@ ehci_cardbus_attach(device_t parent, dev
 	 * have lower function numbers so they should be enumerated already.
 	 */
 	ncomp = 0;
+	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_cardbus_alldevs */
 	TAILQ_FOREACH(up, &ehci_cardbus_alldevs, next) {
 		if (up->bus == ca->ca_bus) {
 			DPRINTF(("ehci_cardbus_attach: companion %s\n",
@@ -232,6 +233,9 @@ void
 usb_cardbus_add(struct usb_cardbus *up, struct cardbus_attach_args *ca,
     device_t bu)
 {
+
+	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_cardbus_alldevs */
+
 	TAILQ_INSERT_TAIL(&ehci_cardbus_alldevs, up, next);
 	up->bus = ca->ca_bus;
 	up->function = ca->ca_function;
@@ -241,5 +245,8 @@ usb_cardbus_add(struct usb_cardbus *up, 
 void
 usb_cardbus_rem(struct usb_cardbus *up)
 {
+
+	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_cardbus_alldevs */
+
 	TAILQ_REMOVE(&ehci_cardbus_alldevs, up, next);
 }

Index: src/sys/dev/pci/ehci_pci.c
diff -u src/sys/dev/pci/ehci_pci.c:1.77 src/sys/dev/pci/ehci_pci.c:1.78
--- src/sys/dev/pci/ehci_pci.c:1.77	Sun Mar 24 03:29:02 2024
+++ src/sys/dev/pci/ehci_pci.c	Mon Mar 31 14:45:35 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: ehci_pci.c,v 1.77 2024/03/24 03:29:02 mrg Exp $	*/
+/*	$NetBSD: ehci_pci.c,v 1.78 2025/03/31 14:45:35 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci_pci.c,v 1.77 2024/03/24 03:29:02 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci_pci.c,v 1.78 2025/03/31 14:45:35 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -243,6 +243,7 @@ ehci_pci_attach(device_t parent, device_
 	const u_int maxncomp = EHCI_HCS_N_CC(EREAD4(&sc->sc, EHCI_HCSPARAMS));
 	KASSERT(maxncomp <= EHCI_COMPANION_MAX);
 	ncomp = 0;
+	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_pci_alldevs */
 	TAILQ_FOREACH(up, &ehci_pci_alldevs, next) {
 		if (up->bus == pa->pa_bus && up->device == pa->pa_device &&
 		    !up->claimed) {

Index: src/sys/dev/pci/usb_pci.c
diff -u src/sys/dev/pci/usb_pci.c:1.7 src/sys/dev/pci/usb_pci.c:1.8
--- src/sys/dev/pci/usb_pci.c:1.7	Mon Apr 28 20:23:55 2008
+++ src/sys/dev/pci/usb_pci.c	Mon Mar 31 14:45:35 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_pci.c,v 1.7 2008/04/28 20:23:55 martin Exp $	*/
+/*	$NetBSD: usb_pci.c,v 1.8 2025/03/31 14:45:35 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@@ -30,31 +30,34 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_pci.c,v 1.7 2008/04/28 20:23:55 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_pci.c,v 1.8 2025/03/31 14:45:35 riastradh Exp $");
 
 #include <sys/param.h>
-#include <sys/systm.h>
 #include <sys/kernel.h>
-#include <sys/queue.h>
 #include <sys/proc.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
 
 #include <dev/pci/pcivar.h>
 #include <dev/pci/usb_pci.h>
 
 #include <dev/usb/usb.h>
+#include <dev/usb/usb_mem.h>
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdivar.h>
-#include <dev/usb/usb_mem.h>
 
 #include <dev/usb/ehcireg.h>
 #include <dev/usb/ehcivar.h>
 
 struct usb_pci_alldevs ehci_pci_alldevs =
-	TAILQ_HEAD_INITIALIZER(ehci_pci_alldevs);
+    TAILQ_HEAD_INITIALIZER(ehci_pci_alldevs);
 
 void
 usb_pci_add(struct usb_pci *up, struct pci_attach_args *pa, device_t bu)
 {
+
+	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_pci_alldevs */
+
 	TAILQ_INSERT_TAIL(&ehci_pci_alldevs, up, next);
 	up->bus = pa->pa_bus;
 	up->device = pa->pa_device;
@@ -65,5 +68,8 @@ usb_pci_add(struct usb_pci *up, struct p
 void
 usb_pci_rem(struct usb_pci *up)
 {
+
+	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_pci_alldevs */
+
 	TAILQ_REMOVE(&ehci_pci_alldevs, up, next);
 }

Reply via email to