Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Jan 2006 17:36:01 -0500
From:      John Baldwin <jhb@freebsd.org>
To:        Peter Jeremy <PeterJeremy@optushome.com.au>
Cc:        freebsd-current@freebsd.org
Subject:   Re: Panic due to deleting devices twice
Message-ID:  <200601231736.03028.jhb@freebsd.org>
In-Reply-To: <20060123214151.GO25397@cirb503493.alcatel.com.au>
References:  <20060121070706.GA32444@cirb503493.alcatel.com.au> <200601231618.04949.jhb@freebsd.org> <20060123214151.GO25397@cirb503493.alcatel.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
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@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200601231736.03028.jhb>