svn commit: r348164 - head/sys/dev/iicbus

Ian Lepore ian at FreeBSD.org
Thu May 23 14:02:40 UTC 2019


Author: ian
Date: Thu May 23 14:02:39 2019
New Revision: 348164
URL: https://svnweb.freebsd.org/changeset/base/348164

Log:
  Mark i2c slave devices busy while they own the bus.
  
  Many i2c slave drivers are in modules that can be unloaded.  If they detach
  while IO is in progress the bus would be hung forever.  Conversely,
  lower-layer drivers (iicbus and the hardware driver) also live in modules
  and other kinds of bad things happen if they get detached while IO is in
  progress.  Because device_busy() propagates up to parents, marking the slave
  device busy while it owns the bus solves both kinds of problems that come
  with detaching i2c devices while IO is in progress.

Modified:
  head/sys/dev/iicbus/iiconf.c

Modified: head/sys/dev/iicbus/iiconf.c
==============================================================================
--- head/sys/dev/iicbus/iiconf.c	Thu May 23 13:05:47 2019	(r348163)
+++ head/sys/dev/iicbus/iiconf.c	Thu May 23 14:02:39 2019	(r348164)
@@ -128,6 +128,12 @@ iicbus_request_bus(device_t bus, device_t dev, int how
 		++sc->owncount;
 		if (sc->owner == NULL) {
 			sc->owner = dev;
+			/*
+			 * Mark the device busy while it owns the bus, to
+			 * prevent detaching the device, bus, or hardware
+			 * controller, until ownership is relinquished.
+			 */
+			device_busy(dev);
 			/* 
 			 * Drop the lock around the call to the bus driver, it
 			 * should be allowed to sleep in the IIC_WAIT case.
@@ -177,6 +183,7 @@ iicbus_release_bus(device_t bus, device_t dev)
 		IICBUS_LOCK(sc);
 		sc->owner = NULL;
 		wakeup_one(sc);
+		device_unbusy(dev);
 	}
 	IICBUS_UNLOCK(sc);
 	return (0);


More information about the svn-src-head mailing list