Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F175275983
D60507.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D60507.diff
View Options
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
@@ -740,7 +740,6 @@
* and MIDI). Handle those special cases here.
*/
if (IOCGROUP(cmd) == 'X') {
- PCM_ACQUIRE(d);
switch(cmd) {
case SNDCTL_SYSINFO:
sound_oss_sysinfo((oss_sysinfo *)arg);
@@ -765,7 +764,6 @@
default:
ret = EINVAL;
}
- PCM_RELEASE(d);
PCM_GIANT_EXIT(d);
return (ret);
}
@@ -2164,27 +2162,24 @@
}
}
- PCM_UNLOCKASSERT(d);
- PCM_LOCK(d);
if ((ai->dev == -1 && d->dsp_dev == i_dev) ||
- (ai->dev == unit)) {
- PCM_UNLOCK(d);
+ (ai->dev == unit))
break;
- } else {
- PCM_UNLOCK(d);
- d = NULL;
- }
+ d = NULL;
}
- bus_topo_unlock();
- /* Exhausted the search -- nothing is locked, so return. */
- if (d == NULL)
+ /* Exhausted the search. */
+ if (d == NULL) {
+ bus_topo_unlock();
return (EINVAL);
+ }
- /* XXX Need Giant magic entry ??? */
-
- PCM_UNLOCKASSERT(d);
- PCM_LOCK(d);
+ /*
+ * Do not give up the topology lock until the device is busied, or it
+ * might detach between unlocking and busying.
+ */
+ PCM_ACQUIRE(d);
+ bus_topo_unlock();
bzero((void *)ai, sizeof(oss_audioinfo));
ai->dev = unit;
@@ -2270,7 +2265,7 @@
if (ai->min_channels == INT_MAX)
ai->min_channels = 0;
- PCM_UNLOCK(d);
+ PCM_RELEASE(d);
return (0);
}
@@ -2332,18 +2327,24 @@
* 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++) {
+ for (unit = 0; ; unit++) {
+ bus_topo_lock();
+ if (pcm_devclass == NULL ||
+ unit >= devclass_get_maxunit(pcm_devclass)) {
+ bus_topo_unlock();
+ break;
+ }
d = devclass_get_softc(pcm_devclass, unit);
- if (!PCM_REGISTERED(d))
+ if (!PCM_REGISTERED(d)) {
+ bus_topo_unlock();
continue;
-
- /* XXX Need Giant magic entry ??? */
-
- /* See the note in function docblock */
- PCM_UNLOCKASSERT(d);
- PCM_LOCK(d);
+ }
+ /*
+ * Do not give up the topology lock until the device is busied,
+ * or it might detach between unlocking and busying.
+ */
+ PCM_ACQUIRE(d);
+ bus_topo_unlock();
CHN_FOREACH(ch, d, channels.pcm) {
CHN_UNLOCKASSERT(ch);
@@ -2357,7 +2358,7 @@
}
if (ch == NULL) {
- PCM_UNLOCK(d);
+ PCM_RELEASE(d);
continue;
}
@@ -2481,14 +2482,12 @@
ai->next_rec_engine = 0;
CHN_UNLOCK(ch);
- PCM_UNLOCK(d);
- bus_topo_unlock();
+ PCM_RELEASE(d);
return (0);
}
- bus_topo_unlock();
- /* Exhausted the search -- nothing is locked, so return. */
+ /* Exhausted the search. */
return (EINVAL);
}
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
@@ -887,6 +887,18 @@
return (EBADF);
PCM_GIANT_ENTER(d);
+
+ /*
+ * This group of ioctls can report info about any device in the system,
+ * and they busy each one as they inspect it, so they must not run with
+ * this device already busied, otherwise we will recurse on the sx.
+ */
+ if (IOCGROUP(cmd) == 'X') {
+ ret = mixer_ioctl_cmd(i_dev, cmd, arg, mode, td);
+ PCM_GIANT_EXIT(d);
+ return (ret);
+ }
+
PCM_ACQUIRE(d);
ret = mixer_ioctl_cmd(i_dev, cmd, arg, mode, td);
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
@@ -509,18 +509,24 @@
j = 0;
- bus_topo_lock();
- for (i = 0; pcm_devclass != NULL &&
- i < devclass_get_maxunit(pcm_devclass); i++) {
+ for (i = 0; ; i++) {
+ bus_topo_lock();
+ if (pcm_devclass == NULL ||
+ i >= devclass_get_maxunit(pcm_devclass)) {
+ bus_topo_unlock();
+ break;
+ }
d = devclass_get_softc(pcm_devclass, i);
- if (!PCM_REGISTERED(d))
+ if (!PCM_REGISTERED(d)) {
+ bus_topo_unlock();
continue;
-
- /* XXX Need Giant magic entry ??? */
-
- /* See note in function's docblock */
- PCM_UNLOCKASSERT(d);
- PCM_LOCK(d);
+ }
+ /*
+ * Do not give up the topology lock until the device is busied,
+ * or it might detach between unlocking and busying.
+ */
+ PCM_ACQUIRE(d);
+ bus_topo_unlock();
si->numaudioengines += PCM_CHANCOUNT(d);
@@ -534,9 +540,8 @@
j++;
}
- PCM_UNLOCK(d);
+ PCM_RELEASE(d);
}
- bus_topo_unlock();
si->numsynths = 0; /* OSSv4 docs: this field is obsolete */
/**
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
@@ -258,9 +258,12 @@
bus_topo_unlock();
return (EINVAL);
}
- bus_topo_unlock();
-
+ /*
+ * Do not give up the topology lock until the device is busied, or it
+ * might detach between unlocking and busying.
+ */
PCM_ACQUIRE(d);
+ bus_topo_unlock();
switch (VCHAN_SYSCTL_DIR(oidp->oid_arg1)) {
case VCHAN_PLAY:
@@ -316,9 +319,8 @@
bus_topo_unlock();
return (EINVAL);
}
- bus_topo_unlock();
-
PCM_ACQUIRE(d);
+ bus_topo_unlock();
switch (VCHAN_SYSCTL_DIR(oidp->oid_arg1)) {
case VCHAN_PLAY:
@@ -406,9 +408,8 @@
bus_topo_unlock();
return (EINVAL);
}
- bus_topo_unlock();
-
PCM_ACQUIRE(d);
+ bus_topo_unlock();
switch (VCHAN_SYSCTL_DIR(oidp->oid_arg1)) {
case VCHAN_PLAY:
@@ -498,9 +499,8 @@
bus_topo_unlock();
return (EINVAL);
}
- bus_topo_unlock();
-
PCM_ACQUIRE(d);
+ bus_topo_unlock();
switch (VCHAN_SYSCTL_DIR(oidp->oid_arg1)) {
case VCHAN_PLAY:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 10, 3:54 PM (9 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40537973
Default Alt Text
D60507.diff (5 KB)
Attached To
Mode
D60507: sound: Busy devices before giving up the topology lock
Attached
Detach File
Event Timeline
Log In to Comment