diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -132,6 +132,7 @@ struct pcm_channel *c; int i; + bus_topo_lock(); for (i = 0; pcm_devclass != NULL && i < devclass_get_maxunit(pcm_devclass); i++) { d = devclass_get_softc(pcm_devclass, i); @@ -150,6 +151,7 @@ PCM_RELEASE(d); PCM_UNLOCK(d); } + bus_topo_unlock(); } static int @@ -170,7 +172,7 @@ return (0); } SYSCTL_PROC(_hw_snd, OID_AUTO, vpc_0db, - CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int), + CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int), sysctl_hw_snd_vpc_0db, "I", "0db relative level"); @@ -190,7 +192,7 @@ return (0); } SYSCTL_PROC(_hw_snd, OID_AUTO, vpc_reset, - CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 0, sizeof(int), + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 0, sizeof(int), sysctl_hw_snd_vpc_reset, "I", "reset volume on all channels"); diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -2016,6 +2016,7 @@ if (ai->dev == -1 && i_dev->si_devsw != &dsp_cdevsw) return (EINVAL); + bus_topo_lock(); for (unit = 0; pcm_devclass != NULL && unit < devclass_get_maxunit(pcm_devclass); unit++) { d = devclass_get_softc(pcm_devclass, unit); @@ -2023,6 +2024,7 @@ if ((ai->dev == -1 && unit == snd_unit) || ai->dev == unit) { dsp_oss_audioinfo_unavail(ai, unit); + bus_topo_unlock(); return (0); } else { d = NULL; @@ -2041,6 +2043,7 @@ d = NULL; } } + bus_topo_unlock(); /* Exhausted the search -- nothing is locked, so return. */ if (d == NULL) @@ -2197,6 +2200,7 @@ * Search for the requested audio device (channel). Start by * iterating over pcm devices. */ + bus_topo_lock(); for (unit = 0; pcm_devclass != NULL && unit < devclass_get_maxunit(pcm_devclass); unit++) { d = devclass_get_softc(pcm_devclass, unit); @@ -2346,9 +2350,11 @@ CHN_UNLOCK(ch); PCM_UNLOCK(d); + bus_topo_unlock(); return (0); } + bus_topo_unlock(); /* Exhausted the search -- nothing is locked, so return. */ return (EINVAL); diff --git a/sys/dev/sound/pcm/feeder_rate.c b/sys/dev/sound/pcm/feeder_rate.c --- a/sys/dev/sound/pcm/feeder_rate.c +++ b/sys/dev/sound/pcm/feeder_rate.c @@ -258,6 +258,7 @@ * set resampler quality if and only if it is exist as * part of feeder chains and the channel is idle. */ + bus_topo_lock(); for (i = 0; pcm_devclass != NULL && i < devclass_get_maxunit(pcm_devclass); i++) { d = devclass_get_softc(pcm_devclass, i); @@ -279,11 +280,12 @@ PCM_RELEASE(d); PCM_UNLOCK(d); } + bus_topo_unlock(); return (0); } SYSCTL_PROC(_hw_snd, OID_AUTO, feeder_rate_quality, - CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int), + CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int), sysctl_hw_snd_feeder_rate_quality, "I", "sample rate converter quality ("__XSTRING(Z_QUALITY_MIN)"=low .. " __XSTRING(Z_QUALITY_MAX)"=high)"); diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c --- a/sys/dev/sound/pcm/mixer.c +++ b/sys/dev/sound/pcm/mixer.c @@ -1444,12 +1444,14 @@ * There's a 1:1 relationship between mixers and PCM devices, so * begin by iterating over PCM devices and search for our mixer. */ + bus_topo_lock(); for (i = 0; pcm_devclass != NULL && i < devclass_get_maxunit(pcm_devclass); i++) { d = devclass_get_softc(pcm_devclass, i); if (!PCM_REGISTERED(d)) { if ((mi->dev == -1 && i == snd_unit) || mi->dev == i) { mixer_oss_mixerinfo_unavail(mi, i); + bus_topo_unlock(); return (0); } else continue; @@ -1470,6 +1472,7 @@ if (d->mixer_dev->si_drv1 == NULL) { mixer_oss_mixerinfo_unavail(mi, i); PCM_UNLOCK(d); + bus_topo_unlock(); return (0); } @@ -1550,8 +1553,10 @@ PCM_UNLOCK(d); + bus_topo_unlock(); return (0); } + bus_topo_unlock(); return (EINVAL); } diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c --- a/sys/dev/sound/pcm/sound.c +++ b/sys/dev/sound/pcm/sound.c @@ -116,17 +116,21 @@ unit = snd_unit; error = sysctl_handle_int(oidp, &unit, 0, req); if (error == 0 && req->newptr != NULL) { + bus_topo_lock(); d = devclass_get_softc(pcm_devclass, unit); - if (!PCM_REGISTERED(d) || CHN_EMPTY(d, channels.pcm)) + if (!PCM_REGISTERED(d) || CHN_EMPTY(d, channels.pcm)) { + bus_topo_unlock(); return EINVAL; + } snd_unit = unit; snd_unit_auto = 0; + bus_topo_unlock(); } return (error); } /* XXX: do we need a way to let the user change the default unit? */ SYSCTL_PROC(_hw_snd, OID_AUTO, default_unit, - CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_ANYBODY | CTLFLAG_NEEDGIANT, 0, + CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, 0, sizeof(int), sysctl_hw_snd_default_unit, "I", "default sound device"); @@ -213,6 +217,7 @@ best = -1; bestprio = -100; + bus_topo_lock(); for (i = 0; pcm_devclass != NULL && i < devclass_get_maxunit(pcm_devclass); i++) { d = devclass_get_softc(pcm_devclass, i); @@ -228,6 +233,8 @@ bestprio = prio; } } + bus_topo_unlock(); + return (best); } @@ -557,6 +564,7 @@ j = 0; + bus_topo_lock(); for (i = 0; pcm_devclass != NULL && i < devclass_get_maxunit(pcm_devclass); i++) { d = devclass_get_softc(pcm_devclass, i); @@ -583,6 +591,7 @@ PCM_UNLOCK(d); } + bus_topo_unlock(); si->numsynths = 0; /* OSSv4 docs: this field is obsolete */ /** @@ -603,9 +612,11 @@ * break if they try to loop through all mixers and some of them are * not available. */ + bus_topo_lock(); si->nummixers = devclass_get_maxunit(pcm_devclass); si->numcards = devclass_get_maxunit(pcm_devclass); si->numaudios = devclass_get_maxunit(pcm_devclass); + bus_topo_unlock(); /* OSSv4 docs: Intended only for test apps; API doesn't really have much of a concept of cards. Shouldn't be used by applications. */ @@ -631,6 +642,7 @@ struct snddev_info *d; int i; + bus_topo_lock(); for (i = 0; pcm_devclass != NULL && i < devclass_get_maxunit(pcm_devclass); i++) { d = devclass_get_softc(pcm_devclass, i); @@ -658,8 +670,11 @@ PCM_UNLOCK(d); } + bus_topo_unlock(); return (0); } + bus_topo_unlock(); + return (ENXIO); } diff --git a/sys/dev/sound/pcm/vchan.c b/sys/dev/sound/pcm/vchan.c --- a/sys/dev/sound/pcm/vchan.c +++ b/sys/dev/sound/pcm/vchan.c @@ -259,9 +259,13 @@ struct snddev_info *d; int err, enabled, flag; + bus_topo_lock(); d = devclass_get_softc(pcm_devclass, VCHAN_SYSCTL_UNIT(oidp->oid_arg1)); - if (!PCM_REGISTERED(d)) + if (!PCM_REGISTERED(d)) { + bus_topo_unlock(); return (EINVAL); + } + bus_topo_unlock(); PCM_LOCK(d); PCM_WAIT(d); @@ -317,9 +321,13 @@ int *vchanmode, direction, ret; char dtype[16]; + bus_topo_lock(); d = devclass_get_softc(pcm_devclass, VCHAN_SYSCTL_UNIT(oidp->oid_arg1)); - if (!PCM_REGISTERED(d)) + if (!PCM_REGISTERED(d)) { + bus_topo_unlock(); return (EINVAL); + } + bus_topo_unlock(); PCM_LOCK(d); PCM_WAIT(d); @@ -407,9 +415,13 @@ struct pcm_channel *c, *ch; int *vchanrate, direction, ret, newspd, restart; + bus_topo_lock(); d = devclass_get_softc(pcm_devclass, VCHAN_SYSCTL_UNIT(oidp->oid_arg1)); - if (!PCM_REGISTERED(d)) + if (!PCM_REGISTERED(d)) { + bus_topo_unlock(); return (EINVAL); + } + bus_topo_unlock(); PCM_LOCK(d); PCM_WAIT(d); @@ -499,9 +511,13 @@ int *vchanformat, direction, ret, restart; char fmtstr[AFMTSTR_LEN]; + bus_topo_lock(); d = devclass_get_softc(pcm_devclass, VCHAN_SYSCTL_UNIT(oidp->oid_arg1)); - if (!PCM_REGISTERED(d)) + if (!PCM_REGISTERED(d)) { + bus_topo_unlock(); return (EINVAL); + } + bus_topo_unlock(); PCM_LOCK(d); PCM_WAIT(d); @@ -749,6 +765,7 @@ if (error != 0 || req->newptr == NULL) return (error); + bus_topo_lock(); snd_vchans_enable = v >= 1; for (i = 0; pcm_devclass != NULL && @@ -766,11 +783,12 @@ d->flags &= ~(SD_F_PVCHANS | SD_F_RVCHANS); PCM_RELEASE_QUICK(d); } + bus_topo_unlock(); return (0); } SYSCTL_PROC(_hw_snd, OID_AUTO, vchans_enable, - CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int), + CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int), sysctl_hw_snd_vchans_enable, "I", "global virtual channel switch"); void