Module Name: src
Committed By: riastradh
Date: Sat Jun 12 12:13:11 UTC 2021
Modified Files:
src/sys/dev/usb: uhub.c usb.c usb_subr.c xhci.c
Log Message:
usb(4): Sprinkle kernel lock assertions.
To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 src/sys/dev/usb/uhub.c
cvs rdiff -u -r1.194 -r1.195 src/sys/dev/usb/usb.c
cvs rdiff -u -r1.252 -r1.253 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.144 -r1.145 src/sys/dev/usb/xhci.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/dev/usb/uhub.c
diff -u src/sys/dev/usb/uhub.c:1.148 src/sys/dev/usb/uhub.c:1.149
--- src/sys/dev/usb/uhub.c:1.148 Sat Jun 12 12:11:01 2021
+++ src/sys/dev/usb/uhub.c Sat Jun 12 12:13:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: uhub.c,v 1.148 2021/06/12 12:11:01 riastradh Exp $ */
+/* $NetBSD: uhub.c,v 1.149 2021/06/12 12:13:10 riastradh Exp $ */
/* $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $ */
/* $OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.148 2021/06/12 12:11:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.149 2021/06/12 12:13:10 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -533,6 +533,8 @@ uhub_explore(struct usbd_device *dev)
device_unit(sc->sc_dev), (uintptr_t)dev, dev->ud_addr,
dev->ud_speed);
+ KASSERT(KERNEL_LOCKED_P());
+
if (!sc->sc_running)
return USBD_NOT_STARTED;
@@ -930,6 +932,8 @@ uhub_rescan(device_t self, const char *i
struct usbd_device *dev;
int port;
+ KASSERT(KERNEL_LOCKED_P());
+
if (uhub_explore_enter(sc) != 0)
return EBUSY;
for (port = 1; port <= hub->uh_hubdesc.bNbrPorts; port++) {
@@ -953,6 +957,8 @@ uhub_childdet(device_t self, device_t ch
int port;
int i;
+ KASSERT(KERNEL_LOCKED_P());
+
if (!devhub->ud_hub)
/* should never happen; children are only created after init */
panic("hub not fully initialised, but child deleted?");
Index: src/sys/dev/usb/usb.c
diff -u src/sys/dev/usb/usb.c:1.194 src/sys/dev/usb/usb.c:1.195
--- src/sys/dev/usb/usb.c:1.194 Sat Jun 12 12:11:38 2021
+++ src/sys/dev/usb/usb.c Sat Jun 12 12:13:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: usb.c,v 1.194 2021/06/12 12:11:38 riastradh Exp $ */
+/* $NetBSD: usb.c,v 1.195 2021/06/12 12:13:10 riastradh Exp $ */
/*
* Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.194 2021/06/12 12:11:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.195 2021/06/12 12:13:10 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -453,6 +453,8 @@ usb_doattach(device_t self)
USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+ KASSERT(KERNEL_LOCKED_P());
+
/* Protected by KERNEL_LOCK */
nusbbusses++;
@@ -690,6 +692,8 @@ usb_event_thread(void *arg)
USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+ KASSERT(KERNEL_LOCKED_P());
+
/*
* In case this controller is a companion controller to an
* EHCI controller we need to wait until the EHCI controller
@@ -1146,6 +1150,7 @@ usb_discover(struct usb_softc *sc)
USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+ KASSERT(KERNEL_LOCKED_P());
KASSERT(mutex_owned(bus->ub_lock));
if (usb_noexplore > 1)
Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.252 src/sys/dev/usb/usb_subr.c:1.253
--- src/sys/dev/usb/usb_subr.c:1.252 Sat Jun 12 12:11:27 2021
+++ src/sys/dev/usb/usb_subr.c Sat Jun 12 12:13:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: usb_subr.c,v 1.252 2021/06/12 12:11:27 riastradh Exp $ */
+/* $NetBSD: usb_subr.c,v 1.253 2021/06/12 12:13:10 riastradh Exp $ */
/* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */
/*
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.252 2021/06/12 12:11:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.253 2021/06/12 12:13:10 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -957,6 +957,9 @@ usbd_attachinterfaces(device_t parent, s
int i, j, loc;
device_t dv;
+ /* Needed for access to dev->ud_subdevs. */
+ KASSERT(KERNEL_LOCKED_P());
+
nifaces = dev->ud_cdesc->bNumInterface;
ifaces = kmem_zalloc(nifaces * sizeof(*ifaces), KM_SLEEP);
for (i = 0; i < nifaces; i++) {
@@ -1047,6 +1050,8 @@ usbd_probe_and_attach(device_t parent, s
int confi, nifaces;
usbd_status err;
+ KASSERT(KERNEL_LOCKED_P());
+
/* First try with device specific drivers. */
err = usbd_attachwholedevice(parent, dev, port, 0);
if (dev->ud_nifaces_claimed || err)
@@ -1111,6 +1116,8 @@ usbd_reattach_device(device_t parent, st
{
int i, loc;
+ KASSERT(KERNEL_LOCKED_P());
+
if (locators != NULL) {
loc = locators[USBIFIFCF_PORT];
if (loc != USBIFIFCF_PORT_DEFAULT && loc != port)
@@ -1169,6 +1176,8 @@ usbd_new_device(device_t parent, struct
int i;
int p;
+ KASSERT(KERNEL_LOCKED_P());
+
if (bus->ub_methods->ubm_newdev != NULL)
return (bus->ub_methods->ubm_newdev)(parent, bus, depth, speed,
port, up);
Index: src/sys/dev/usb/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.144 src/sys/dev/usb/xhci.c:1.145
--- src/sys/dev/usb/xhci.c:1.144 Sun Jun 6 18:37:20 2021
+++ src/sys/dev/usb/xhci.c Sat Jun 12 12:13:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: xhci.c,v 1.144 2021/06/06 18:37:20 jdolecek Exp $ */
+/* $NetBSD: xhci.c,v 1.145 2021/06/12 12:13:10 riastradh Exp $ */
/*
* Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.144 2021/06/06 18:37:20 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.145 2021/06/12 12:13:10 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -2778,6 +2778,8 @@ xhci_new_device(device_t parent, struct
XHCIHIST_CALLARGS("port %ju depth %ju speed %ju up %#jx",
port, depth, speed, (uintptr_t)up);
+ KASSERT(KERNEL_LOCKED_P());
+
dev = kmem_zalloc(sizeof(*dev), KM_SLEEP);
dev->ud_bus = bus;
dev->ud_quirks = &usbd_no_quirk;