From owner-freebsd-current@FreeBSD.ORG Sun Jan 22 06:48:49 2006 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5A4CA16A41F for ; Sun, 22 Jan 2006 06:48:49 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id DE51043D53 for ; Sun, 22 Jan 2006 06:48:48 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (localhost.village.org [127.0.0.1] (may be forged)) by harmony.bsdimp.com (8.13.3/8.13.3) with ESMTP id k0M6m5Wp075894; Sat, 21 Jan 2006 23:48:05 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Sat, 21 Jan 2006 23:48:22 -0700 (MST) Message-Id: <20060121.234822.107142930.imp@bsdimp.com> To: PeterJeremy@optushome.com.au From: "M. Warner Losh" In-Reply-To: <20060121070706.GA32444@cirb503493.alcatel.com.au> References: <20060121070706.GA32444@cirb503493.alcatel.com.au> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (harmony.bsdimp.com [127.0.0.1]); Sat, 21 Jan 2006 23:48:05 -0700 (MST) Cc: freebsd-current@freebsd.org Subject: Re: Panic due to deleting devices twice X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Jan 2006 06:48:49 -0000 In message: <20060121070706.GA32444@cirb503493.alcatel.com.au> Peter Jeremy 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