Module Name:    src
Committed By:   mrg
Date:           Tue Sep 18 01:36:44 UTC 2018

Modified Files:
        src/sys/dev/usb: uhub.c usb_subr.c

Log Message:
add config_pending usage to uhub and general USB device attachment.

- call config_pending_incr() and config_pending_decr() around attaching
  devices against "usbdevif" attribute.

uhub:
- convert sc_explorepending and sc_running to bool.  add new sc_first_explore.
- call config_pending_incr() at the start of uhub_attach().  dropped in
  uhub_explore(), if this is the first explore.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/sys/dev/usb/uhub.c
cvs rdiff -u -r1.226 -r1.227 src/sys/dev/usb/usb_subr.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.138 src/sys/dev/usb/uhub.c:1.139
--- src/sys/dev/usb/uhub.c:1.138	Thu Feb  1 09:50:48 2018
+++ src/sys/dev/usb/uhub.c	Tue Sep 18 01:36:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhub.c,v 1.138 2018/02/01 09:50:48 msaitoh Exp $	*/
+/*	$NetBSD: uhub.c,v 1.139 2018/09/18 01:36:44 mrg 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.138 2018/02/01 09:50:48 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.139 2018/09/18 01:36:44 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -113,9 +113,9 @@ struct uhub_softc {
 	uint8_t			*sc_statuspend;
 	uint8_t			*sc_status;
 	size_t			 sc_statuslen;
-	int			 sc_explorepending;
-
-	u_char			 sc_running;
+	bool			 sc_explorepending;
+	bool			 sc_first_explore;
+	bool			 sc_running;
 };
 
 #define UHUB_IS_HIGH_SPEED(sc) \
@@ -263,6 +263,8 @@ uhub_attach(device_t parent, device_t se
 	usb_endpoint_descriptor_t *ed;
 	struct usbd_tt *tts = NULL;
 
+	config_pending_incr(self);
+
 	UHUBHIST_FUNC(); UHUBHIST_CALLED();
 
 	sc->sc_dev = self;
@@ -284,14 +286,14 @@ uhub_attach(device_t parent, device_t se
 	if (err) {
 		DPRINTF("configuration failed, sc %#jx error %jd",
 		    (uintptr_t)sc, err, 0, 0);
-		return;
+		goto bad2;
 	}
 
 	if (dev->ud_depth > USB_HUB_MAX_DEPTH) {
 		aprint_error_dev(self,
 		    "hub depth (%d) exceeded, hub ignored\n",
 		    USB_HUB_MAX_DEPTH);
-		return;
+		goto bad2;
 	}
 
 	/* Get hub descriptor. */
@@ -301,7 +303,7 @@ uhub_attach(device_t parent, device_t se
 	if (err) {
 		DPRINTF("getting hub descriptor failed, uhub%jd error %jd",
 		    device_unit(self), err, 0, 0);
-		return;
+		goto bad2;
 	}
 
 	for (nremov = 0, port = 1; port <= nports; port++)
@@ -365,7 +367,7 @@ uhub_attach(device_t parent, device_t se
 
 	/* force initial scan */
 	memset(sc->sc_status, 0xff, sc->sc_statuslen);
-	sc->sc_explorepending = 1;
+	sc->sc_explorepending = true;
 
 	err = usbd_open_pipe_intr(iface, ed->bEndpointAddress,
 		  USBD_SHORT_XFER_OK|USBD_MPSAFE, &sc->sc_ipipe, sc,
@@ -450,8 +452,8 @@ uhub_attach(device_t parent, device_t se
 		usbd_delay_ms(dev, pwrdly);
 
 	/* The usual exploration will finish the setup. */
-
-	sc->sc_running = 1;
+	sc->sc_running = true;
+	sc->sc_first_explore = true;
 
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
@@ -469,7 +471,8 @@ uhub_attach(device_t parent, device_t se
 		kmem_free(hub,
 		    sizeof(*hub) + (nports-1) * sizeof(struct usbd_port));
 	dev->ud_hub = NULL;
-	return;
+ bad2:
+	config_pending_decr(self);
 }
 
 usbd_status
@@ -778,7 +781,7 @@ uhub_explore(struct usbd_device *dev)
 		}
 	}
 	mutex_enter(&sc->sc_lock);
-	sc->sc_explorepending = 0;
+	sc->sc_explorepending = false;
 	for (int i = 0; i < sc->sc_statuslen; i++) {
 		if (sc->sc_statuspend[i] != 0) {
 			memcpy(sc->sc_status, sc->sc_statuspend,
@@ -789,6 +792,10 @@ uhub_explore(struct usbd_device *dev)
 		}
 	}
 	mutex_exit(&sc->sc_lock);
+	if (sc->sc_first_explore) {
+		config_pending_decr(sc->sc_dev);
+		sc->sc_first_explore = false;
+	}
 
 	return USBD_NORMAL_COMPLETION;
 }
@@ -943,7 +950,7 @@ uhub_intr(struct usbd_xfer *xfer, void *
 		}
 
 		if (!sc->sc_explorepending) {
-			sc->sc_explorepending = 1;
+			sc->sc_explorepending = true;
 
 			memcpy(sc->sc_status, sc->sc_statuspend,
 			    sc->sc_statuslen);

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.226 src/sys/dev/usb/usb_subr.c:1.227
--- src/sys/dev/usb/usb_subr.c:1.226	Thu Aug  2 06:09:04 2018
+++ src/sys/dev/usb/usb_subr.c	Tue Sep 18 01:36:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.226 2018/08/02 06:09:04 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.227 2018/09/18 01:36:44 mrg 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.226 2018/08/02 06:09:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.227 2018/09/18 01:36:44 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -907,6 +907,7 @@ usbd_attachwholedevice(device_t parent, 
 	dlocs[USBDEVIFCF_INTERFACE] = -1;
 
 	KERNEL_LOCK(1, curlwp);
+	config_pending_incr(parent);
 	dv = config_found_sm_loc(parent, "usbdevif", dlocs, &uaa, usbd_print,
 				 config_stdsubmatch);
 	KERNEL_UNLOCK_ONE(curlwp);
@@ -917,6 +918,7 @@ usbd_attachwholedevice(device_t parent, 
 		dev->ud_nifaces_claimed = 1; /* XXX */
 		usbd_serialnumber(dv, dev);
 	}
+	config_pending_decr(parent);
 	return USBD_NORMAL_COMPLETION;
 }
 

Reply via email to