From nobody Thu Feb 27 15:17:39 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Z3Zhg6gbfz5qJkm; Thu, 27 Feb 2025 15:17:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z3Zhg5pNfz41t8; Thu, 27 Feb 2025 15:17:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740669459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zFWZbPcpkKrWQBzwNBetpgCURWqNKMiOiv3e4uvBVtU=; b=u+7fSj91XuBXh041Ysm2K16TZjYnw/7E2CIZ5devkDzm3y28biU/5ZgVS17Wg4w4xIm9zO W7l07qbq7usrE9AGKIGUKDGrmmp55RrN8v42F6CHf8dJelSnBBzH886rSkcv3sYKA8B1+C TRlsMJzDbhm+7KvssjNOocWXwd3MwwzJUodSPiI1BAzGVnhHyut48Vh6PIsViPa7Lb7S2X n+Zw36acFK1/lEU/OfdnNSoZnRnktaKoUrT+NrYapB0DUz/0jrmKYRDx0+h4Eqv39CvWK5 ko7J3lOPuaujm+qysmDSiF4/R0DGG38zqy7RIr9ChyGXRAn/8vqjOaUgL/+Ovg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740669459; a=rsa-sha256; cv=none; b=Uc6ds1d3XgG1HszNdRtYF7w4f1OPsYscF+2xwSzcjgKPcpA2EdAZrPE+0Ka6bEaqp2W2oe Nbgn+CiE5HU/jVTQBrDOJ+QOXkrMDiaoNS/ZauzrRKwqB4Ew/xY3+qID5e8WlQDNrQk8Q5 1CskY/BrnBivTVwEi4Sm3ao1Mxua9oG58sV3/wXOWS5Ue49CtB8c3KtY22WlS4toinQz6R 3ZGajX+4sTfXbmG2W2OLJelUE2l2qwCK85fRD5d7mBGeDlDypT+nd59rN+4vb/oh7cvW6y fMhuINX3OfMJJaaDC7Ds55w5Eh3Z7MOVopy9gc/6Ts2yzsOL9APufFFCltqAnQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740669459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zFWZbPcpkKrWQBzwNBetpgCURWqNKMiOiv3e4uvBVtU=; b=kBerW5DLJlH6DKwUOakHt83CaFrpt3mTZmkEZzugzar1f/mfK3cpWm6DtYTKMTraMtiUKd PoJuiHbdmz9CSrybNXx+PdkaWwYWipqwIvjfa2bYo9Ozy4hovPZHWIwDhPk7KA1UawLHSf ROi9OfiuD7YzTJH3V87VUhfl42dHdMu/hF5TR0hAurTg5qizr6EwV1znZkvHd3f5Yo2bLs 10wY/9vUlfiBn/7g/29hbgM6yX4cm82ID8bm1LFbGPPx5wIk2BJsXqDIzGYEA2unQ31yuR sFYVKclYS56wCAbnXjbwjis5uxyhlhsDDwbtsMVkYXIy6+6Wkk47JRfYxTnqcw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Z3Zhg4rdMzp9K; Thu, 27 Feb 2025 15:17:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 51RFHdiN030133; Thu, 27 Feb 2025 15:17:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51RFHd1k030130; Thu, 27 Feb 2025 15:17:39 GMT (envelope-from git) Date: Thu, 27 Feb 2025 15:17:39 GMT Message-Id: <202502271517.51RFHd1k030130@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 38ed49b0f927 - stable/14 - sound: Use bus_child_deleted methods to free ivars for children List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 38ed49b0f9276a349323f5fddebf02ec47b356ac Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=38ed49b0f9276a349323f5fddebf02ec47b356ac commit 38ed49b0f9276a349323f5fddebf02ec47b356ac Author: John Baldwin AuthorDate: 2024-11-01 14:09:11 +0000 Commit: John Baldwin CommitDate: 2025-02-27 15:16:56 +0000 sound: Use bus_child_deleted methods to free ivars for children Note that hdsp and hdspe were just leaking the ivars on detach previously. While here, use M_WAITOK to allocate ivars since attach routines are sleepable. hdsp and hdspe were using M_NOWAIT without checking the return value. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47366 (cherry picked from commit a17a41ffde0d1c579dcd7cef7900c3b44be0ec81) hsdp(4) doesn't exist in stable/14 so is not patched --- sys/dev/sound/pci/csa.c | 26 +++------ sys/dev/sound/pci/emu10kx.c | 134 ++++++++++---------------------------------- sys/dev/sound/pci/hdspe.c | 9 ++- 3 files changed, 46 insertions(+), 123 deletions(-) diff --git a/sys/dev/sound/pci/csa.c b/sys/dev/sound/pci/csa.c index f293a8fc8af8..aa682bf43071 100644 --- a/sys/dev/sound/pci/csa.c +++ b/sys/dev/sound/pci/csa.c @@ -274,22 +274,14 @@ csa_attach(device_t dev) /* Attach the children. */ /* PCM Audio */ - func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO); - if (func == NULL) { - error = ENOMEM; - goto err_teardown; - } + func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_WAITOK | M_ZERO); func->varinfo = &scp->binfo; func->func = SCF_PCM; scp->pcm = device_add_child(dev, "pcm", -1); device_set_ivars(scp->pcm, func); /* Midi Interface */ - func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO); - if (func == NULL) { - error = ENOMEM; - goto err_teardown; - } + func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_WAITOK | M_ZERO); func->varinfo = &scp->binfo; func->func = SCF_MIDI; scp->midi = device_add_child(dev, "midi", -1); @@ -310,34 +302,33 @@ err_io: return (error); } +static void +csa_child_deleted(device_t dev, device_t child) +{ + free(device_get_ivars(child), M_DEVBUF); +} + static int csa_detach(device_t dev) { csa_res *resp; sc_p scp; - struct sndcard_func *func; int err; scp = device_get_softc(dev); resp = &scp->res; if (scp->midi != NULL) { - func = device_get_ivars(scp->midi); err = device_delete_child(dev, scp->midi); if (err != 0) return err; - if (func != NULL) - free(func, M_DEVBUF); scp->midi = NULL; } if (scp->pcm != NULL) { - func = device_get_ivars(scp->pcm); err = device_delete_child(dev, scp->pcm); if (err != 0) return err; - if (func != NULL) - free(func, M_DEVBUF); scp->pcm = NULL; } @@ -1062,6 +1053,7 @@ static device_method_t csa_methods[] = { DEVMETHOD(device_resume, csa_resume), /* Bus interface */ + DEVMETHOD(bus_child_deleted, csa_child_deleted), DEVMETHOD(bus_alloc_resource, csa_alloc_resource), DEVMETHOD(bus_release_resource, csa_release_resource), DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), diff --git a/sys/dev/sound/pci/emu10kx.c b/sys/dev/sound/pci/emu10kx.c index 0f938597e06c..2cd5a881c653 100644 --- a/sys/dev/sound/pci/emu10kx.c +++ b/sys/dev/sound/pci/emu10kx.c @@ -3211,16 +3211,8 @@ emu_pci_attach(device_t dev) sc->pcm[i] = NULL; /* FRONT */ - func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO); - if (func == NULL) { - error = ENOMEM; - goto bad; - } - pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_NOWAIT | M_ZERO); - if (pcminfo == NULL) { - error = ENOMEM; - goto bad; - } + func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_WAITOK | M_ZERO); + pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_WAITOK | M_ZERO); pcminfo->card = sc; pcminfo->route = RT_FRONT; @@ -3231,16 +3223,8 @@ emu_pci_attach(device_t dev) if (!(sc->mch_disabled)) { /* REAR */ - func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO); - if (func == NULL) { - error = ENOMEM; - goto bad; - } - pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_NOWAIT | M_ZERO); - if (pcminfo == NULL) { - error = ENOMEM; - goto bad; - } + func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_WAITOK | M_ZERO); + pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_WAITOK | M_ZERO); pcminfo->card = sc; pcminfo->route = RT_REAR; @@ -3250,16 +3234,8 @@ emu_pci_attach(device_t dev) device_set_ivars(sc->pcm[RT_REAR], func); if (sc->has_51) { /* CENTER */ - func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO); - if (func == NULL) { - error = ENOMEM; - goto bad; - } - pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_NOWAIT | M_ZERO); - if (pcminfo == NULL) { - error = ENOMEM; - goto bad; - } + func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_WAITOK | M_ZERO); + pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_WAITOK | M_ZERO); pcminfo->card = sc; pcminfo->route = RT_CENTER; @@ -3268,16 +3244,8 @@ emu_pci_attach(device_t dev) sc->pcm[RT_CENTER] = device_add_child(dev, "pcm", -1); device_set_ivars(sc->pcm[RT_CENTER], func); /* SUB */ - func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO); - if (func == NULL) { - error = ENOMEM; - goto bad; - } - pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_NOWAIT | M_ZERO); - if (pcminfo == NULL) { - error = ENOMEM; - goto bad; - } + func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_WAITOK | M_ZERO); + pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_WAITOK | M_ZERO); pcminfo->card = sc; pcminfo->route = RT_SUB; @@ -3288,16 +3256,8 @@ emu_pci_attach(device_t dev) } if (sc->has_71) { /* SIDE */ - func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO); - if (func == NULL) { - error = ENOMEM; - goto bad; - } - pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_NOWAIT | M_ZERO); - if (pcminfo == NULL) { - error = ENOMEM; - goto bad; - } + func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_WAITOK | M_ZERO); + pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_WAITOK | M_ZERO); pcminfo->card = sc; pcminfo->route = RT_SIDE; @@ -3309,16 +3269,8 @@ emu_pci_attach(device_t dev) } /* mch_disabled */ if (sc->mch_rec) { - func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO); - if (func == NULL) { - error = ENOMEM; - goto bad; - } - pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_NOWAIT | M_ZERO); - if (pcminfo == NULL) { - error = ENOMEM; - goto bad; - } + func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_WAITOK | M_ZERO); + pcminfo = malloc(sizeof(struct emu_pcminfo), M_DEVBUF, M_WAITOK | M_ZERO); pcminfo->card = sc; pcminfo->route = RT_MCHRECORD; @@ -3335,16 +3287,8 @@ emu_pci_attach(device_t dev) #if 0 /* Midi Interface 1: Live!, Audigy, Audigy 2 */ if ((sc->is_emu10k1) || (sc->is_emu10k2) || (sc->is_ca0102)) { - func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO); - if (func == NULL) { - error = ENOMEM; - goto bad; - } - midiinfo = malloc(sizeof(struct emu_midiinfo), M_DEVBUF, M_NOWAIT | M_ZERO); - if (midiinfo == NULL) { - error = ENOMEM; - goto bad; - } + func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_WAITOK | M_ZERO); + midiinfo = malloc(sizeof(struct emu_midiinfo), M_DEVBUF, M_WAITOK | M_ZERO); midiinfo->card = sc; if (sc->is_emu10k2 || (sc->is_ca0102)) { midiinfo->port = EMU_A_MUDATA1; @@ -3361,16 +3305,8 @@ emu_pci_attach(device_t dev) } /* Midi Interface 2: Audigy, Audigy 2 (on AudigyDrive) */ if (sc->is_emu10k2 || (sc->is_ca0102)) { - func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT | M_ZERO); - if (func == NULL) { - error = ENOMEM; - goto bad; - } - midiinfo = malloc(sizeof(struct emu_midiinfo), M_DEVBUF, M_NOWAIT | M_ZERO); - if (midiinfo == NULL) { - error = ENOMEM; - goto bad; - } + func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_WAITOK | M_ZERO); + midiinfo = malloc(sizeof(struct emu_midiinfo), M_DEVBUF, M_WAITOK | M_ZERO); midiinfo->card = sc; midiinfo->port = EMU_A_MUDATA2; @@ -3401,11 +3337,22 @@ bad: return (error); } +static void +emu_pci_child_deleted(device_t dev, device_t child) +{ + struct sndcard_func *func; + + func = device_get_ivars(child); + if (func != NULL) { + free(func->varinfo, M_DEVBUF); + free(func, M_DEVBUF); + } +} + static int emu_pci_detach(device_t dev) { struct emu_sc_info *sc; - struct sndcard_func *func; int devcount, i; device_t *childlist; int r = 0; @@ -3414,35 +3361,17 @@ emu_pci_detach(device_t dev) for (i = 0; i < RT_COUNT; i++) { if (sc->pcm[i] != NULL) { - func = device_get_ivars(sc->pcm[i]); - if (func != NULL && func->func == SCF_PCM) { - device_set_ivars(sc->pcm[i], NULL); - free(func->varinfo, M_DEVBUF); - free(func, M_DEVBUF); - } r = device_delete_child(dev, sc->pcm[i]); if (r) return (r); } } if (sc->midi[0] != NULL) { - func = device_get_ivars(sc->midi[0]); - if (func != NULL && func->func == SCF_MIDI) { - device_set_ivars(sc->midi[0], NULL); - free(func->varinfo, M_DEVBUF); - free(func, M_DEVBUF); - } r = device_delete_child(dev, sc->midi[0]); if (r) return (r); } if (sc->midi[1] != NULL) { - func = device_get_ivars(sc->midi[1]); - if (func != NULL && func->func == SCF_MIDI) { - device_set_ivars(sc->midi[1], NULL); - free(func->varinfo, M_DEVBUF); - free(func, M_DEVBUF); - } r = device_delete_child(dev, sc->midi[1]); if (r) return (r); } @@ -3450,12 +3379,6 @@ emu_pci_detach(device_t dev) 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])); - func = device_get_ivars(childlist[i]); - if (func != NULL && (func->func == SCF_MIDI || func->func == SCF_PCM)) { - device_set_ivars(childlist[i], NULL); - free(func->varinfo, M_DEVBUF); - free(func, M_DEVBUF); - } device_delete_child(dev, childlist[i]); } if (childlist != NULL) @@ -3488,6 +3411,7 @@ static device_method_t emu_methods[] = { DEVMETHOD(device_attach, emu_pci_attach), DEVMETHOD(device_detach, emu_pci_detach), /* Bus methods */ + DEVMETHOD(bus_child_deleted, emu_pci_child_deleted), DEVMETHOD(bus_read_ivar, emu_read_ivar), DEVMETHOD(bus_write_ivar, emu_write_ivar), diff --git a/sys/dev/sound/pci/hdspe.c b/sys/dev/sound/pci/hdspe.c index 0b378cc3d8f4..a9543cbfbebb 100644 --- a/sys/dev/sound/pci/hdspe.c +++ b/sys/dev/sound/pci/hdspe.c @@ -491,7 +491,7 @@ hdspe_attach(device_t dev) return (ENXIO); for (i = 0; i < HDSPE_MAX_CHANS && chan_map[i].descr != NULL; i++) { - scp = malloc(sizeof(struct sc_pcminfo), M_DEVBUF, M_NOWAIT | M_ZERO); + scp = malloc(sizeof(struct sc_pcminfo), M_DEVBUF, M_WAITOK | M_ZERO); scp->hc = &chan_map[i]; scp->sc = sc; scp->dev = device_add_child(dev, "pcm", -1); @@ -527,6 +527,12 @@ hdspe_attach(device_t dev) return (bus_generic_attach(dev)); } +static void +hdspe_child_deleted(device_t dev, device_t child) +{ + free(device_get_ivars(child), M_DEVBUF); +} + static void hdspe_dmafree(struct sc_info *sc) { @@ -574,6 +580,7 @@ static device_method_t hdspe_methods[] = { DEVMETHOD(device_probe, hdspe_probe), DEVMETHOD(device_attach, hdspe_attach), DEVMETHOD(device_detach, hdspe_detach), + DEVMETHOD(bus_child_deleted, hdspe_child_deleted), { 0, 0 } };