From owner-svn-src-all@freebsd.org Tue Oct 20 19:53:01 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4788FA19A3E; Tue, 20 Oct 2015 19:53:01 +0000 (UTC) (envelope-from dumbbell@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 21FE51058; Tue, 20 Oct 2015 19:53:01 +0000 (UTC) (envelope-from dumbbell@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t9KJr0RW049649; Tue, 20 Oct 2015 19:53:00 GMT (envelope-from dumbbell@FreeBSD.org) Received: (from dumbbell@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9KJqxxk049641; Tue, 20 Oct 2015 19:52:59 GMT (envelope-from dumbbell@FreeBSD.org) Message-Id: <201510201952.t9KJqxxk049641@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dumbbell set sender to dumbbell@FreeBSD.org using -f From: =?UTF-8?Q?Jean-S=c3=a9bastien_P=c3=a9dron?= Date: Tue, 20 Oct 2015 19:52:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r289657 - head/sys/dev/iicbus X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Oct 2015 19:53:01 -0000 Author: dumbbell Date: Tue Oct 20 19:52:59 2015 New Revision: 289657 URL: https://svnweb.freebsd.org/changeset/base/289657 Log: iicbus: Use device_delete_children() instead of explicit child removal If the bus is detached and deleted by a call to device_delete_child() or device_delete_children() on a device higher in the tree, I²C children were already detached and deleted. So the device_t pointer stored in sc points to freed memory: we must not try to delete it again. By using device_delete_children(), we let subr_bus.c figure out if there are children to take care of. While here, make sure iicbus_detach() and iicoc_detach() call device_delete_children() too, to be safe. Reviewed by: jhb, imp Approved by: jhb, imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D3926 Modified: head/sys/dev/iicbus/iicbb.c head/sys/dev/iicbus/iicbus.c head/sys/dev/iicbus/iicoc.c head/sys/dev/iicbus/iicsmb.c Modified: head/sys/dev/iicbus/iicbb.c ============================================================================== --- head/sys/dev/iicbus/iicbb.c Tue Oct 20 19:47:08 2015 (r289656) +++ head/sys/dev/iicbus/iicbb.c Tue Oct 20 19:52:59 2015 (r289657) @@ -149,22 +149,9 @@ iicbb_attach(device_t dev) static int iicbb_detach(device_t dev) { - struct iicbb_softc *sc = (struct iicbb_softc *)device_get_softc(dev); - device_t child; - /* - * We need to save child because the detach indirectly causes - * sc->iicbus to be zeroed. Since we added the device - * unconditionally in iicbb_attach, we need to make sure we - * delete it here. See iicbb_child_detached. We need that - * callback in case newbus detached our children w/o detaching - * us (say iicbus is a module and unloaded w/o iicbb being - * unloaded). - */ - child = sc->iicbus; bus_generic_detach(dev); - if (child) - device_delete_child(dev, child); + device_delete_children(dev); return (0); } Modified: head/sys/dev/iicbus/iicbus.c ============================================================================== --- head/sys/dev/iicbus/iicbus.c Tue Oct 20 19:47:08 2015 (r289656) +++ head/sys/dev/iicbus/iicbus.c Tue Oct 20 19:52:59 2015 (r289657) @@ -135,6 +135,7 @@ iicbus_detach(device_t dev) iicbus_reset(dev, IIC_FASTEST, 0, NULL); bus_generic_detach(dev); + device_delete_children(dev); mtx_destroy(&sc->lock); return (0); } Modified: head/sys/dev/iicbus/iicoc.c ============================================================================== --- head/sys/dev/iicbus/iicoc.c Tue Oct 20 19:47:08 2015 (r289656) +++ head/sys/dev/iicbus/iicoc.c Tue Oct 20 19:52:59 2015 (r289657) @@ -229,6 +229,7 @@ static int iicoc_detach(device_t dev) { bus_generic_detach(dev); + device_delete_children(dev); return (0); } Modified: head/sys/dev/iicbus/iicsmb.c ============================================================================== --- head/sys/dev/iicbus/iicsmb.c Tue Oct 20 19:47:08 2015 (r289656) +++ head/sys/dev/iicbus/iicsmb.c Tue Oct 20 19:52:59 2015 (r289657) @@ -167,11 +167,9 @@ 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); - } + device_delete_children(dev); mtx_destroy(&sc->lock); return (0);