PERFORCE change 163754 for review

Scott Long scottl at FreeBSD.org
Mon Jun 8 03:27:17 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=163754

Change 163754 by scottl at scottl-deimos on 2009/06/08 03:26:36

	Add locking to the remainder of the devclass methods.

Affected files ...

.. //depot/projects/scottl-camlock/src/sys/kern/subr_bus.c#24 edit

Differences ...

==== //depot/projects/scottl-camlock/src/sys/kern/subr_bus.c#24 (text+ko) ====

@@ -1518,12 +1518,14 @@
 
 	/* If we were given a wired unit number, check for existing device */
 	/* XXX imp XXX */
+	mtx_lock(&devclasses_mtx);
 	if (unit != -1) {
 		if (unit >= 0 && unit < dc->maxunit &&
 		    dc->devices[unit] != NULL) {
 			if (bootverbose)
 				printf("%s: %s%d already exists; skipping it\n",
 				    dc->name, dc->name, *unitp);
+			mtx_unlock(&devclasses_mtx);
 			return (EEXIST);
 		}
 	} else {
@@ -1566,8 +1568,10 @@
 		if (oldlist != NULL)
 			free(oldlist, M_BUS);
 	}
+	dc->devices[unit] = dev;
+	mtx_unlock(&devclasses_mtx);
+
 	PDEBUG(("now: unit %d in devclass %s", unit, DEVCLANAME(dc)));
-
 	*unitp = unit;
 	return (0);
 }
@@ -1607,8 +1611,11 @@
 		dev->nameunit = NULL;
 		return (error);
 	}
-	dc->devices[dev->unit] = dev;
+	mtx_lock(&devclasses_mtx);
+	DC_REF(dc);
+	DT_REF(dev);
 	dev->devclass = dc;
+	mtx_unlock(&devclasses_mtx);
 	snprintf(dev->nameunit, buflen, "%s%d", dc->name, dev->unit);
 
 	return (0);
@@ -1634,14 +1641,18 @@
 
 	PDEBUG(("%s in devclass %s", DEVICENAME(dev), DEVCLANAME(dc)));
 
+	mtx_lock(&devclasses_mtx);
 	if (dev->devclass != dc || dc->devices[dev->unit] != dev)
 		panic("devclass_delete_device: inconsistent device class");
+	DT_UNREF(dev);
+	DC_UNREF(dc);
 	dc->devices[dev->unit] = NULL;
 	if (dev->flags & DF_WILDCARD)
 		dev->unit = -1;
 	dev->devclass = NULL;
 	free(dev->nameunit, M_BUS);
 	dev->nameunit = NULL;
+	mtx_unlock(&devclasses_mtx);
 
 	return (0);
 }
@@ -1707,8 +1718,10 @@
 
 	dev->state = DS_NOTPRESENT;
 
+	mtx_lock(&devclasses_mtx);
 	TAILQ_INSERT_TAIL(&bus_data_devices, dev, devlink);
 	bus_data_generation_update();
+	mtx_unlock(&devclasses_mtx);
 
 	return (dev);
 }


More information about the p4-projects mailing list