git: 6da28bb2a34a - main - csa/emu10kx: Simplify deleting child devices
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 02 Jan 2025 18:28:25 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=6da28bb2a34ac9e410ba8a49a7d8b8975462e929 commit 6da28bb2a34ac9e410ba8a49a7d8b8975462e929 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2025-01-02 18:23:28 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2025-01-02 18:23:28 +0000 csa/emu10kx: Simplify deleting child devices Use bus_generic_detach to detach and delete all child devices instead of several explicit calls to device_delete_child. Differential Revision: https://reviews.freebsd.org/D47965 --- sys/dev/sound/pci/csa.c | 18 ++++-------------- sys/dev/sound/pci/emu10kx.c | 31 ++++--------------------------- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/sys/dev/sound/pci/csa.c b/sys/dev/sound/pci/csa.c index 4c43c42b1cc3..4bd8ff029f43 100644 --- a/sys/dev/sound/pci/csa.c +++ b/sys/dev/sound/pci/csa.c @@ -317,26 +317,16 @@ csa_detach(device_t dev) scp = device_get_softc(dev); resp = &scp->res; - if (scp->midi != NULL) { - err = device_delete_child(dev, scp->midi); - if (err != 0) - return err; - scp->midi = NULL; - } - - if (scp->pcm != NULL) { - err = device_delete_child(dev, scp->pcm); - if (err != 0) - return err; - scp->pcm = NULL; - } + err = bus_generic_detach(dev); + if (err != 0) + return err; bus_teardown_intr(dev, resp->irq, scp->ih); bus_release_resource(dev, SYS_RES_IRQ, resp->irq_rid, resp->irq); bus_release_resource(dev, SYS_RES_MEMORY, resp->mem_rid, resp->mem); bus_release_resource(dev, SYS_RES_MEMORY, resp->io_rid, resp->io); - return bus_generic_detach(dev); + return (0); } static int diff --git a/sys/dev/sound/pci/emu10kx.c b/sys/dev/sound/pci/emu10kx.c index 0c445482a932..9cd7dbca1cb2 100644 --- a/sys/dev/sound/pci/emu10kx.c +++ b/sys/dev/sound/pci/emu10kx.c @@ -3354,36 +3354,13 @@ static int emu_pci_detach(device_t dev) { struct emu_sc_info *sc; - int devcount, i; - device_t *childlist; int r = 0; sc = device_get_softc(dev); - for (i = 0; i < RT_COUNT; i++) { - if (sc->pcm[i] != NULL) { - r = device_delete_child(dev, sc->pcm[i]); - if (r) return (r); - } - } - - if (sc->midi[0] != NULL) { - r = device_delete_child(dev, sc->midi[0]); - if (r) return (r); - } - - if (sc->midi[1] != NULL) { - r = device_delete_child(dev, sc->midi[1]); - if (r) return (r); - } - - if (device_get_children(dev, &childlist, &devcount) == 0) - for (i = 0; i < devcount - 1; i++) { - device_printf(dev, "removing stale child %d (unit %d)\n", i, device_get_unit(childlist[i])); - device_delete_child(dev, childlist[i]); - } - if (childlist != NULL) - free(childlist, M_TEMP); + r = bus_generic_detach(dev); + if (r != 0) + return (r); r = emu10kx_dev_uninit(sc); if (r) @@ -3403,7 +3380,7 @@ emu_pci_detach(device_t dev) mtx_destroy(&sc->rw); mtx_destroy(&sc->lock); - return (bus_generic_detach(dev)); + return (0); } /* add suspend, resume */ static device_method_t emu_methods[] = {