1
0
mirror of https://git.FreeBSD.org/src.git synced 2026-06-02 11:24:32 +00:00

snd_uaudio: Do not use snd_mixer->lock as mixer_lock

In similar fashion to c234740c9d ("snd_uaudio: Do not use
pcm_channel->lock to protect uaudio_chan"), stop this layering
violation, and introduce a snd_uaudio(4)-internal mixer_lock.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Pull Request:	https://ron-dev.freebsd.org/FreeBSD/src/pulls/18
This commit is contained in:
Christos Margiolis
2026-04-16 14:15:21 +02:00
parent 22730c4b10
commit 9a00e0b8ca
+11 -20
View File
@@ -356,7 +356,7 @@ struct uaudio_hid {
struct uaudio_softc_child {
device_t pcm_device;
struct mtx *mixer_lock;
struct mtx mixer_lock;
struct snd_mixer *mixer_dev;
uint32_t mix_info;
@@ -2955,12 +2955,9 @@ uaudio_mixer_sysctl_handler(SYSCTL_HANDLER_ARGS)
sc = (struct uaudio_softc *)oidp->oid_arg1;
hint = oidp->oid_arg2;
if (sc->sc_child[0].mixer_lock == NULL)
return (ENXIO);
/* lookup mixer node */
mtx_lock(sc->sc_child[0].mixer_lock);
mtx_lock(&sc->sc_child[0].mixer_lock);
for (pmc = sc->sc_mixer_root; pmc != NULL; pmc = pmc->next) {
for (chan = 0; chan != (int)pmc->nchan; chan++) {
if (pmc->wValue[chan] != -1 &&
@@ -2971,7 +2968,7 @@ uaudio_mixer_sysctl_handler(SYSCTL_HANDLER_ARGS)
}
}
found:
mtx_unlock(sc->sc_child[0].mixer_lock);
mtx_unlock(&sc->sc_child[0].mixer_lock);
error = sysctl_handle_int(oidp, &temp, 0, req);
if (error != 0 || req->newptr == NULL)
@@ -2979,7 +2976,7 @@ found:
/* update mixer value */
mtx_lock(sc->sc_child[0].mixer_lock);
mtx_lock(&sc->sc_child[0].mixer_lock);
if (pmc != NULL &&
temp >= pmc->minval &&
temp <= pmc->maxval) {
@@ -2989,7 +2986,7 @@ found:
/* start the transfer, if not already started */
usbd_transfer_start(sc->sc_mixer_xfer[0]);
}
mtx_unlock(sc->sc_child[0].mixer_lock);
mtx_unlock(&sc->sc_child[0].mixer_lock);
return (0);
}
@@ -3220,10 +3217,7 @@ uaudio_mixer_reload_all(struct uaudio_softc *sc)
struct uaudio_mixer_node *pmc;
int chan;
if (sc->sc_child[0].mixer_lock == NULL)
return;
mtx_lock(sc->sc_child[0].mixer_lock);
mtx_lock(&sc->sc_child[0].mixer_lock);
for (pmc = sc->sc_mixer_root; pmc != NULL; pmc = pmc->next) {
/* use reset defaults for non-oss controlled settings */
if (pmc->ctl == SOUND_MIXER_NRDEVICES)
@@ -3235,7 +3229,7 @@ uaudio_mixer_reload_all(struct uaudio_softc *sc)
/* start HID volume keys, if any */
usbd_transfer_start(sc->sc_hid.xfer[0]);
mtx_unlock(sc->sc_child[0].mixer_lock);
mtx_unlock(&sc->sc_child[0].mixer_lock);
}
static void
@@ -5439,13 +5433,13 @@ uaudio_mixer_init_sub(struct uaudio_softc *sc, struct snd_mixer *m)
DPRINTF("child=%u\n", i);
sc->sc_child[i].mixer_lock = mixer_get_lock(m);
mtx_init(&sc->sc_child[i].mixer_lock, "uaudio mixer lock", NULL, MTX_DEF);
sc->sc_child[i].mixer_dev = m;
if (i == 0 &&
usbd_transfer_setup(sc->sc_udev, &sc->sc_mixer_iface_index,
sc->sc_mixer_xfer, uaudio_mixer_config, 1, sc,
sc->sc_child[i].mixer_lock)) {
&sc->sc_child[i].mixer_lock)) {
DPRINTFN(0, "could not allocate USB transfer for mixer!\n");
return (ENOMEM);
}
@@ -5470,7 +5464,7 @@ uaudio_mixer_uninit_sub(struct uaudio_softc *sc, struct snd_mixer *m)
if (index == 0)
usbd_transfer_unsetup(sc->sc_mixer_xfer, 1);
sc->sc_child[index].mixer_lock = NULL;
mtx_destroy(&sc->sc_child[index].mixer_lock);
return (0);
}
@@ -6186,9 +6180,6 @@ uaudio_hid_attach(struct uaudio_softc *sc,
if (!(sc->sc_hid.flags & UAUDIO_HID_VALID))
return (-1);
if (sc->sc_child[0].mixer_lock == NULL)
return (-1);
/* Get HID descriptor */
error = usbd_req_get_hid_desc(uaa->device, NULL, &d_ptr,
&d_len, M_TEMP, sc->sc_hid.iface_index);
@@ -6247,7 +6238,7 @@ uaudio_hid_attach(struct uaudio_softc *sc,
/* allocate USB transfers */
error = usbd_transfer_setup(uaa->device, &sc->sc_hid.iface_index,
sc->sc_hid.xfer, uaudio_hid_config, UAUDIO_HID_N_TRANSFER,
sc, sc->sc_child[0].mixer_lock);
sc, &sc->sc_child[0].mixer_lock);
if (error) {
DPRINTF("error=%s\n", usbd_errstr(error));
return (-1);