svn commit: r225103 - stable/8/sys/dev/usb

Hans Petter Selasky hselasky at FreeBSD.org
Tue Aug 23 07:42:05 UTC 2011


Author: hselasky
Date: Tue Aug 23 07:42:04 2011
New Revision: 225103
URL: http://svn.freebsd.org/changeset/base/225103

Log:
  MFC r225038:
  Fix for recursive locking in usb_close() after r224777 (9-current) and r224960 (8-stable).

Modified:
  stable/8/sys/dev/usb/usb_dev.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)

Modified: stable/8/sys/dev/usb/usb_dev.c
==============================================================================
--- stable/8/sys/dev/usb/usb_dev.c	Tue Aug 23 07:35:21 2011	(r225102)
+++ stable/8/sys/dev/usb/usb_dev.c	Tue Aug 23 07:42:04 2011	(r225103)
@@ -911,10 +911,23 @@ usb_close(void *arg)
 
 	DPRINTFN(2, "cpd=%p\n", cpd);
 
-	err = usb_ref_device(cpd, &refs, 1);
-	if (err) {
-		free(cpd, M_USBDEV);
-		return;
+	err = usb_ref_device(cpd, &refs, 0);
+	if (err)
+		goto done;
+
+	/*
+	 * If this function is not called directly from the root HUB
+	 * thread, there is usually a need to lock the enumeration
+	 * lock. Check this.
+	 */
+	if (!usbd_enum_is_locked(cpd->udev)) {
+
+		DPRINTFN(2, "Locking enumeration\n");
+
+		/* reference device */
+		err = usb_usb_ref_device(cpd, &refs);
+		if (err)
+			goto done;
 	}
 	if (cpd->fflags & FREAD) {
 		usb_fifo_close(refs.rxfifo, cpd->fflags);
@@ -922,10 +935,9 @@ usb_close(void *arg)
 	if (cpd->fflags & FWRITE) {
 		usb_fifo_close(refs.txfifo, cpd->fflags);
 	}
-
 	usb_unref_device(cpd, &refs);
+done:
 	free(cpd, M_USBDEV);
-	return;
 }
 
 static void


More information about the svn-src-stable-8 mailing list