Panic due to deleting devices twice

M. Warner Losh imp at
Sat Jan 21 22:48:49 PST 2006

In message: <20060121070706.GA32444 at>
            Peter Jeremy <PeterJeremy at> writes:
: When deleting a device (using device_delete_child()), all its child
: devices are recursively deleted and then device_detach() is called.

I think that order is backwards.  We should detach the device prior to
deleting the device...

: Looking at device_detach(), it appears that the solution is to create
: a bus_child_detached method to inform the parent that a child is being
: destroyed so it can invalidate cached pointers to that child.  In
: practice, there are only 5 bus_child_detached methods (isa, ed,
: pccard, cbb and usb), though there are far more device types attached
: as children.

We have this problem in a number of places in the tree (mostly network
drivers).  However, most of the real bus drivers don't cache pointers
to children, so we've not seen this much at the present time.

: Looking at the iicsmb code, it appears that iicbb and iicsmb both
: cache and explicitly delete child devices and therefore both need
: bus_child_detached methods.  Is this correct?  Is there a simpler
: alternative?

Yes.  This is how ed deals:

static void
ed_child_detached(device_t dev, device_t child)
	struct ed_softc *sc;

	sc = device_get_softc(dev);
	if (child == sc->miibus)
		sc->miibus = NULL;


More information about the freebsd-current mailing list