git: 28f5e880e8b2 - main - Use device_delete_children instead of explicit calls to device_delete_child

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 02 Jan 2025 18:28:17 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=28f5e880e8b28d77cf1a4eb6ce2a766d3c5a3926

commit 28f5e880e8b28d77cf1a4eb6ce2a766d3c5a3926
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-01-02 18:20:21 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-01-02 18:20:21 +0000

    Use device_delete_children instead of explicit calls to device_delete_child
    
    This is simpler and more robust in the face of potential double-frees
    (e.g. if called after bus_generic_detach which will delete devices in
    a future commit).
    
    Reviewed by:    manu, imp
    Differential Revision:  https://reviews.freebsd.org/D47958
---
 sys/arm/allwinner/aw_mmc.c          | 8 +-------
 sys/arm64/broadcom/genet/if_genet.c | 5 +----
 sys/dev/intpm/intpm.c               | 3 +--
 3 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/sys/arm/allwinner/aw_mmc.c b/sys/arm/allwinner/aw_mmc.c
index 634afdfdfd46..9f61e1560658 100644
--- a/sys/arm/allwinner/aw_mmc.c
+++ b/sys/arm/allwinner/aw_mmc.c
@@ -482,7 +482,6 @@ static int
 aw_mmc_detach(device_t dev)
 {
 	struct aw_mmc_softc *sc;
-	device_t d;
 
 	sc = device_get_softc(dev);
 
@@ -494,12 +493,7 @@ aw_mmc_detach(device_t dev)
 
 	callout_drain(&sc->aw_timeoutc);
 
-	AW_MMC_LOCK(sc);
-	d = sc->child;
-	sc->child = NULL;
-	AW_MMC_UNLOCK(sc);
-	if (d != NULL)
-		device_delete_child(sc->aw_dev, d);
+	device_delete_children(sc->aw_dev);
 
 	aw_mmc_teardown_dma(sc);
 
diff --git a/sys/arm64/broadcom/genet/if_genet.c b/sys/arm64/broadcom/genet/if_genet.c
index ccc35fe841df..0602f076b257 100644
--- a/sys/arm64/broadcom/genet/if_genet.c
+++ b/sys/arm64/broadcom/genet/if_genet.c
@@ -365,10 +365,7 @@ static void
 gen_destroy(struct gen_softc *sc)
 {
 
-	if (sc->miibus) {	/* can't happen */
-		device_delete_child(sc->dev, sc->miibus);
-		sc->miibus = NULL;
-	}
+	device_delete_children(sc->dev);
 	bus_teardown_intr(sc->dev, sc->res[_RES_IRQ1], sc->ih);
 	bus_teardown_intr(sc->dev, sc->res[_RES_IRQ2], sc->ih2);
 	gen_bus_dma_teardown(sc);
diff --git a/sys/dev/intpm/intpm.c b/sys/dev/intpm/intpm.c
index 6fc228ac0cd0..3aa76ff48263 100644
--- a/sys/dev/intpm/intpm.c
+++ b/sys/dev/intpm/intpm.c
@@ -202,8 +202,7 @@ intsmb_release_resources(device_t dev)
 {
 	struct intsmb_softc *sc = device_get_softc(dev);
 
-	if (sc->smbus)
-		device_delete_child(dev, sc->smbus);
+	device_delete_children(dev);
 	if (sc->irq_hand)
 		bus_teardown_intr(dev, sc->irq_res, sc->irq_hand);
 	if (sc->irq_res)