From nobody Sat Aug 22 12:49:16 2026 X-Original-To: dev-commits-src-main@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 4hRxnm3y4Lz6pptb for ; Sat, 22 Aug 2026 12:49:16 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hRxnm39x2z3bg9 for ; Sat, 22 Aug 2026 12:49:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787402956; 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=WFLQb7MhV6cYnSWdmkP8qZQzbpQ43SWRJT+c6vM60GM=; b=o9rAmp7zBK2TA+yTD+5omOjARVykXrbl+fjtErDgBj77/EbFjb6/BsqYXrEDyhIB039plP oLV4BR7KRXfjILV93m7tpU35Ga1a3GekicNvmX77fMPXk061/R00tQ5pacaoGR75Ax/+oV 4IpPCYakjcWuOMraSR/AHvKiTvYjF4wGHB43FI57btXz7qIaO5aJdMkJim9/IGumaxcmSG jNmPksNQDLq8tbAQfW7repgKP1zBAvX7ff5RAbDM+9la4BkvRXlpJ3V2kjtGcKQG7BwTRT 4b21CqVI8mSbhXXqRL3bEqijXaEd8IqR06X7n9oi1JEIl00dt/U6aGIOTg0ycA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787402956; a=rsa-sha256; cv=none; b=fY+WXmJZ2zCGJQdRD6LXWVv2n9qKfdOvUGj5eIgCoZ8tNfFKxTD9Noi1Qb2rEp9plEku4C D5rppI3NDhexMuml06JKUNIos+n41HNJN9oFQR6lPz9JlTCwAiJL1pC0DdZzcz+2d9Sz6+ OL1LbprKyBDlnf25/iEHgggpihtQOAcFBSySm13LJnNR/ld5FvJQDRgxUtXlcIrAoujw5I sBrKkrlCo/UU7G0PUVLqj3hXFpmk1iBpJYEenAuU0xMyQEiLmNqPZT5OVQvbZWrxFsilFB RczrnCEWq8PvcCW9SOJfT6c++Ik5ck1bJuAD5Gk6W5mEgCRUyQQU/HeFIMI1Sg== 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=1787402956; 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=WFLQb7MhV6cYnSWdmkP8qZQzbpQ43SWRJT+c6vM60GM=; b=CbKSRAErpcpFDO3m/soC/D2BKSx1J8xMZdxxy47V7TCQ/9bIZXjHFH0D9ibeJOmsxjvcA1 INxpOlyApdnXBj3v8Po8+qVUfP7q3NyxPSWYqqbWrWy1C6Ogov4sfhCdvOJ6YeVVifIzOu WTIoJIGfZWxnl+37VL+ujTB+xaKDyJyyDe4EgD9MNjJzSx2aIAs3XZWVlNeumjPm9JtoLG LBZ1kNGYGurp1/ng2YvuURflEEVoj4oYQPpG5boOYgOq4SyvcjOVHVhFKRrgQcptGYmj92 1MyzomLKdIEMmaSktterVbccxseyK5f+LeJZkM790QVf+BQtHC3O5855sT2/Yw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hRxnm1F3szq28 for ; Sat, 22 Aug 2026 12:49:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 31fcc by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 22 Aug 2026 12:49:16 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: b5c1ab6c8f28 - main - snd_hdsp*: malloc(9) with M_WAITOK List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b5c1ab6c8f2811278b801084713a6618f3b783d3 Auto-Submitted: auto-generated Date: Sat, 22 Aug 2026 12:49:16 +0000 Message-Id: <6a899acc.31fcc.547b8295@gitrepo.freebsd.org> The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=b5c1ab6c8f2811278b801084713a6618f3b783d3 commit b5c1ab6c8f2811278b801084713a6618f3b783d3 Author: Christos Margiolis AuthorDate: 2026-08-22 12:48:50 +0000 Commit: Christos Margiolis CommitDate: 2026-08-22 12:48:50 +0000 snd_hdsp*: malloc(9) with M_WAITOK Perform the allocations outside the lock section so that we can use M_WAITOK. Holding the lock here is actually not really necessary and we could just as well remove it, but keep it for consistency. Sponsored by: The FreeBSD Foundation MFC after: 1 month Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D59079 --- sys/dev/sound/pci/hdsp-pcm.c | 17 +++++++++++++++-- sys/dev/sound/pci/hdspe-pcm.c | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/sys/dev/sound/pci/hdsp-pcm.c b/sys/dev/sound/pci/hdsp-pcm.c index b4df8ca90555..7f4f7dc76557 100644 --- a/sys/dev/sound/pci/hdsp-pcm.c +++ b/sys/dev/sound/pci/hdsp-pcm.c @@ -676,10 +676,13 @@ hdspchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct sc_pcminfo *scp; struct sc_chinfo *ch; struct sc_info *sc; + struct pcmchan_caps *caps; + uint32_t *data; int num; scp = devinfo; sc = scp->sc; + caps = malloc(sizeof(struct pcmchan_caps), M_HDSP, M_WAITOK); mtx_lock(&sc->lock); num = scp->chnum; @@ -704,7 +707,7 @@ hdspchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, SND_FORMAT(AFMT_S32_LE, hdsp_port_slot_count(ch->ports, 192000), 0); ch->cap_fmts[3] = 0; - ch->caps = malloc(sizeof(struct pcmchan_caps), M_HDSP, M_NOWAIT); + ch->caps = caps; *(ch->caps) = (struct pcmchan_caps) {32000, 192000, ch->cap_fmts, 0}; /* HDSP 9652 does not support quad speed sample rates. */ @@ -715,7 +718,6 @@ hdspchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, /* Allocate maximum buffer size. */ ch->size = HDSP_CHANBUF_SIZE * hdsp_port_slot_count_max(ch->ports); - ch->data = malloc(ch->size, M_HDSP, M_NOWAIT); ch->position = 0; ch->buffer = b; @@ -726,6 +728,17 @@ hdspchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, mtx_unlock(&sc->lock); + /* + * It is safe to access ch->size here without holding the lock, because + * 1) as of now, ch->size is written only once, here, and 2) ch's + * lifetime is equal to scp's lifetime so it cannot go away yet. + */ + data = malloc(ch->size, M_HDSP, M_WAITOK); + + mtx_lock(&sc->lock); + ch->data = data; + mtx_unlock(&sc->lock); + if (sndbuf_setup(ch->buffer, ch->data, ch->size) != 0) { device_printf(scp->dev, "Can't setup sndbuf.\n"); hdspchan_free(obj, ch); diff --git a/sys/dev/sound/pci/hdspe-pcm.c b/sys/dev/sound/pci/hdspe-pcm.c index e0b6168efcba..a814c80127b1 100644 --- a/sys/dev/sound/pci/hdspe-pcm.c +++ b/sys/dev/sound/pci/hdspe-pcm.c @@ -670,10 +670,13 @@ hdspechan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct sc_pcminfo *scp; struct sc_chinfo *ch; struct sc_info *sc; + struct pcmchan_caps *caps; + uint32_t *data; int num; scp = devinfo; sc = scp->sc; + caps = malloc(sizeof(struct pcmchan_caps), M_HDSPE, M_WAITOK); mtx_lock(&sc->lock); num = scp->chnum; @@ -697,12 +700,11 @@ hdspechan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, ch->cap_fmts[2] = SND_FORMAT(AFMT_S32_LE, hdspe_channel_count(ch->ports, 8), 0); ch->cap_fmts[3] = 0; - ch->caps = malloc(sizeof(struct pcmchan_caps), M_HDSPE, M_NOWAIT); + ch->caps = caps; *(ch->caps) = (struct pcmchan_caps) {32000, 192000, ch->cap_fmts, 0}; /* Allocate maximum buffer size. */ ch->size = HDSPE_CHANBUF_SIZE * hdspe_channel_count(ch->ports, 8); - ch->data = malloc(ch->size, M_HDSPE, M_NOWAIT); ch->position = 0; ch->buffer = b; @@ -713,6 +715,17 @@ hdspechan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, mtx_unlock(&sc->lock); + /* + * It is safe to access ch->size here without holding the lock, because + * 1) as of now, ch->size is written only once, here, and 2) ch's + * lifetime is equal to scp's lifetime so it cannot go away yet. + */ + data = malloc(ch->size, M_HDSPE, M_WAITOK); + + mtx_lock(&sc->lock); + ch->data = data; + mtx_unlock(&sc->lock); + if (sndbuf_setup(ch->buffer, ch->data, ch->size) != 0) { device_printf(scp->dev, "Can't setup sndbuf.\n"); hdspechan_free(obj, ch);