Re: Panic due to deleting devices twice

From: M. Warner Losh <imp_at_bsdimp.com>
Date: Sat, 21 Jan 2006 23:48:22 -0700 (MST)
In message: <20060121070706.GA32444_at_cirb503493.alcatel.com.au>
            Peter Jeremy <PeterJeremy_at_optushome.com.au> 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;
}

Warner
Received on Sun Jan 22 2006 - 05:48:49 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:51 UTC