Panic due to deleting devices twice

John Baldwin jhb at
Mon Jan 23 14:57:53 PST 2006

On Monday 23 January 2006 16:41, Peter Jeremy wrote:
> On Mon, 2006-Jan-23 16:18:03 -0500, John Baldwin wrote:
> >On Saturday 21 January 2006 02:07, Peter Jeremy wrote:
> >> 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?
> >
> >Can they just call bus_generic_detach() instead and not call
> >device_delete_child()?
> The existing code does both:
> static int iicbb_detach(device_t dev)
> {
>         struct iicbb_softc *sc = (struct iicbb_softc
> *)device_get_softc(dev);
>         if (sc->iicbus) {
>                 bus_generic_detach(dev);
>                 device_delete_child(dev, sc->iicbus);
>         }
>         return (0);
> }
> static int
> iicsmb_detach(device_t dev)
> {
>         struct iicsmb_softc *sc = (struct iicsmb_softc
> *)device_get_softc(dev);
>         bus_generic_detach(dev);
>         if (sc->smbus) {
>                 device_delete_child(dev, sc->smbus);
>         }
>         return (0);
> }
> Maybe a better solution in both cases is to just map device_detach to
> bus_generic_detach() - in which case my patch in kern/92092 is overly
> baroque.  I was hoping that someone might shed some insight into why
> it was done that way in the first case.

Yeah, they should probably just use bus_generic_detach(), and they probably 
don't even need the smbus and iicbus pointers in their softc for that matter.  
Well, that might not be true.  I think some of the drivers that use 
device_delete_child() only use the pointer to call that function, but some 
drivers use child devices to handle requests (smb comes to mind IIRC).  If 
the drivers in question just use the device_t so they can call 
device_delete_child(), then I think you can axe the member from the softc and 
just use bus_generic_detach().  If they use the reference for other things, 
then the bus_device_detached route as in your patch in the PR is the way to 
go.  This is assuming that this is a device whose parent will delete it when 
it is detached (this is true for many 'psuedo-bus' devices like smb).  If a 
device isn't like that, then it may need to always use a bus_device_detached 
hook and call device_delete_child() conditionally in its detach routine.

John Baldwin <jhb at>  <><
"Power Users Use the Power to Serve"  =

More information about the freebsd-current mailing list