From nobody Fri Sep 18 18:18:42 2026 X-Original-To: dev-commits-src-all@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 4hmgqQ4lQ4z6sp5q for ; Fri, 18 Sep 2026 18:18:42 +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 4hmgqQ2nglz4NTD for ; Fri, 18 Sep 2026 18:18:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789755522; 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=e9pzAYoxpydmlcOenVLe5eCYGY6IojUVzqWtpcmfFuQ=; b=nAcqAxOy03A+ATfVz1iLTd966YeVSkIGSA9sz/kBCn17hfwKuPcqNKuthEak+eKF1a/FZc ZxWdN0A9bDxGoWCCAEJ/DiUM/jJbz2vp3DqNaNvs7ZoaJncZW4C5/uFukd29e63L9SJvrc 43zdD9O0pEgTyxpASj/P4Q00HvwLNM8t0Tk8GvaVqMlLpIEeMX0G8vH2dtP+nBsEfUqcZb cxsC1iz4qEP6mLlkyBxtxgchD5eo32Opyrd5MC+US1/DoJM2JMOB2pbHLGuceC20twWxng ssHGO5IlUxYjQUhPaEcYUQSZKkHpK+pi97DCZeaU76SJ+jnyTkdT0awSu871vA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789755522; b=n96y+7WBukfZMEnPpeD4BCqGWMvRFQfluw02tW+z6+KwjnxuNUnoNBZH1WjsAfsLe7P4ht Qk29JbKvpv48FIdnrLO6pUJbCkvki46E/ecUPIBmDhEPeFddPeXvyYbZejywAL5l5kTU2f LoC8Hdc84mPF91KtHZEm3sJrjODCxnhgBQQvwL4Y/iml3CRWszatTGbXVn3KiC5XRqFOm8 uKRN8UstgWarOlZw5n/4igRqf8W59eCWfC1QKbULV3Ee5NS8WkLDDGM6kA+p7fDjoJIkh6 Dz8WLWmYiHUV6DWH04yGtIL2drlphHOUM3UkYrHq0RHIFCXeN46XbX7QEPnLeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789755522; 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=e9pzAYoxpydmlcOenVLe5eCYGY6IojUVzqWtpcmfFuQ=; b=qbuLFLtMqE6z6YPSjNjJRboCnr4QesKgczxQ+Rt7KM0IOg0MHciOUBPeKIlNer5u/4Hngw vleM7UW7NkgcipPUJF8HjUYvkAI9s1zdJ98J37hAdXLYp9KamL0bqgguuJmzGhRPxNxoLJ k0vcDo4xIZ1eZ1WhbQiemn0EmUsMd0wJkLMQ6cRuH4wk+BvjySVUYazwyeC5GrA/wmvE57 iXhLjnIWvrhMJTIQxAKarHPGISqvAM0GdVqp82zCxAsi7zsYcypZO8fAsIX6eM2dlT5efE VO9hH5CjnnQxEuPQoDLOEQ8ch3M78L3y63tr0Bdlidm1K+PS9w6o7OjZokVCwQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hmgqQ1ss8zVdN for ; Fri, 18 Sep 2026 18:18:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 367a8 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 18 Sep 2026 18:18:42 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 9548bfa342a7 - main - sound: Retire mixer_hwvol locked variants List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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: 9548bfa342a71f1ca0ad953bf323086e84a395c3 Auto-Submitted: auto-generated Date: Fri, 18 Sep 2026 18:18:42 +0000 Message-Id: <6aad8082.367a8.706558a3@gitrepo.freebsd.org> The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=9548bfa342a71f1ca0ad953bf323086e84a395c3 commit 9548bfa342a71f1ca0ad953bf323086e84a395c3 Author: Christos Margiolis AuthorDate: 2026-09-18 18:16:03 +0000 Commit: Christos Margiolis CommitDate: 2026-09-18 18:16:03 +0000 sound: Retire mixer_hwvol locked variants Prior to 9a00e0b8ca56 ("snd_uaudio: Do not use snd_mixer->lock as mixer_lock"), there was a need for mixer_hwvol_mute_locked() and mixer_hwvol_step_locked(), because the unlocked variants would acquire the lock, but uaudio_hid_rx_callback() would also hold the lock, so this was a measure to avoid recursion on snd_mixer->lock. Now that snd_uaudio(4) has a private mixer lock, the locked variants are not only unnecessary, but wrong, because we now lock the private lock and not the snd_mixer one, which is what mixer_hwvol_mute_locked() and mixer_hwvol_step_locked() expect. Retire the locked variants and call the regular functions instead. The unlocked variants take the mixer lock, which is now the PCM lock, and reach uaudio_mixer_ctl_set(), which takes mixer_lock. Calling them straight from uaudio_hid_rx_callback() would therefore take mixer_lock and the PCM lock in the opposite order to the mixer ioctl path, so record what the HID report asked for and perform the volume change at the end of the callback, with mixer_lock dropped. The USB stack allows a callback to drop its transfer mutex (see usbdi.9). Sponsored by: The FreeBSD Foundation MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D59075 --- sys/dev/sound/pcm/mixer.c | 24 +++++------------------- sys/dev/sound/pcm/mixer.h | 2 -- sys/dev/sound/usb/uaudio.c | 31 ++++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c index 1c76ace34042..bad464538609 100644 --- a/sys/dev/sound/pcm/mixer.c +++ b/sys/dev/sound/pcm/mixer.c @@ -743,12 +743,6 @@ mixer_hwvol_init(device_t dev) return 0; } -void -mixer_hwvol_mute_locked(struct snd_mixer *m) -{ - mix_setmutedevs(m, m->mutedevs ^ (1 << m->hwvol_mixer)); -} - void mixer_hwvol_mute(device_t dev) { @@ -756,17 +750,19 @@ mixer_hwvol_mute(device_t dev) m = mixer_get_devt(dev); mtx_lock(m->lock); - mixer_hwvol_mute_locked(m); + mix_setmutedevs(m, m->mutedevs ^ (1 << m->hwvol_mixer)); mtx_unlock(m->lock); } void -mixer_hwvol_step_locked(struct snd_mixer *m, int left_step, int right_step) +mixer_hwvol_step(device_t dev, int left_step, int right_step) { + struct snd_mixer *m; int level, left, right; + m = mixer_get_devt(dev); + mtx_lock(m->lock); level = mixer_get(m, m->hwvol_mixer); - if (level != -1) { left = level & 0xff; right = (level >> 8) & 0xff; @@ -783,16 +779,6 @@ mixer_hwvol_step_locked(struct snd_mixer *m, int left_step, int right_step) mixer_set(m, m->hwvol_mixer, m->mutedevs, left | right << 8); } -} - -void -mixer_hwvol_step(device_t dev, int left_step, int right_step) -{ - struct snd_mixer *m; - - m = mixer_get_devt(dev); - mtx_lock(m->lock); - mixer_hwvol_step_locked(m, left_step, right_step); mtx_unlock(m->lock); } diff --git a/sys/dev/sound/pcm/mixer.h b/sys/dev/sound/pcm/mixer.h index d26895a41ba0..7c9d120463ca 100644 --- a/sys/dev/sound/pcm/mixer.h +++ b/sys/dev/sound/pcm/mixer.h @@ -72,9 +72,7 @@ int mixer_ioctl_cmd(struct cdev *i_dev, unsigned long cmd, caddr_t arg, int mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi); int mixer_hwvol_init(device_t dev); -void mixer_hwvol_mute_locked(struct snd_mixer *m); void mixer_hwvol_mute(device_t dev); -void mixer_hwvol_step_locked(struct snd_mixer *m, int l_step, int r_step); void mixer_hwvol_step(device_t dev, int left_step, int right_step); int mix_set(struct snd_mixer *m, unsigned int dev, unsigned int left, unsigned int right); diff --git a/sys/dev/sound/usb/uaudio.c b/sys/dev/sound/usb/uaudio.c index 4e1d7c4c89d5..80c35aca89bc 100644 --- a/sys/dev/sound/usb/uaudio.c +++ b/sys/dev/sound/usb/uaudio.c @@ -6245,9 +6245,13 @@ uaudio_hid_rx_callback(struct usb_xfer *xfer, usb_error_t error) struct snd_mixer *m; uint8_t id; int actlen; + bool mute, volume_up, volume_down; usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); + m = NULL; + mute = volume_up = volume_down = false; + switch (USB_GET_STATE(xfer)) { case USB_ST_TRANSFERRED: DPRINTF("actlen=%d\n", actlen); @@ -6269,7 +6273,7 @@ uaudio_hid_rx_callback(struct usb_xfer *xfer, usb_error_t error) &sc->sc_hid.mute_loc)) { DPRINTF("Mute toggle\n"); - mixer_hwvol_mute_locked(m); + mute = true; } if ((sc->sc_hid.flags & UAUDIO_HID_HAS_VOLUME_UP) && @@ -6278,7 +6282,7 @@ uaudio_hid_rx_callback(struct usb_xfer *xfer, usb_error_t error) &sc->sc_hid.volume_up_loc)) { DPRINTF("Volume Up\n"); - mixer_hwvol_step_locked(m, 1, 1); + volume_up = true; } if ((sc->sc_hid.flags & UAUDIO_HID_HAS_VOLUME_DOWN) && @@ -6287,7 +6291,7 @@ uaudio_hid_rx_callback(struct usb_xfer *xfer, usb_error_t error) &sc->sc_hid.volume_down_loc)) { DPRINTF("Volume Down\n"); - mixer_hwvol_step_locked(m, -1, -1); + volume_down = true; } case USB_ST_SETUP: @@ -6308,6 +6312,27 @@ tr_setup: } break; } + + if (!mute && !volume_up && !volume_down) + return; + + /* + * The mixer_hwvol_*() functions take the mixer lock, which is the PCM + * lock, and end up in uaudio_mixer_ctl_set(), which takes the + * mixer_lock this callback is entered with. Acquiring the two in that + * order here would reverse the order taken by the mixer ioctl path + * (PCM lock first, then mixer_lock), so drop mixer_lock for the + * duration. The USB stack explicitly allows a callback to drop its + * transfer mutex, and usbd_transfer_drain() accounts for it. + */ + mtx_unlock(&sc->sc_child[0].mixer_lock); + if (mute) + mixer_hwvol_mute(m->dev); + if (volume_up) + mixer_hwvol_step(m->dev, 1, 1); + if (volume_down) + mixer_hwvol_step(m->dev, -1, -1); + mtx_lock(&sc->sc_child[0].mixer_lock); } static int