Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177490359
D46548.1794551830.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D46548.1794551830.diff
View Options
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
@@ -109,13 +109,12 @@
return bus_setup_intr(dev, res, flags, NULL, hand, param, cookiep);
}
-/* return error status and a locked channel */
int
pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction,
pid_t pid, char *comm)
{
struct pcm_channel *c;
- int err, vchancount, vchan_num;
+ int vchancount;
bool retry;
KASSERT(d != NULL && ch != NULL &&
@@ -125,53 +124,44 @@
PCM_BUSYASSERT(d);
*ch = NULL;
- vchan_num = 0;
vchancount = (direction == PCMDIR_PLAY) ? d->pvchancount :
d->rvchancount;
-
retry = false;
+
retry_chnalloc:
- err = ENOTSUP;
- /* scan for a free channel */
+ /* Scan for a free channel. */
CHN_FOREACH(c, d, channels.pcm) {
CHN_LOCK(c);
- if (c->direction == direction && (c->flags & CHN_F_VIRTUAL)) {
- if (vchancount < snd_maxautovchans &&
- vchan_num < c->unit) {
- CHN_UNLOCK(c);
- goto vchan_alloc;
- }
- vchan_num++;
+ if (c->direction != direction) {
+ CHN_UNLOCK(c);
+ continue;
}
- if (c->direction == direction && !(c->flags & CHN_F_BUSY)) {
+ if (!(c->flags & CHN_F_BUSY)) {
c->flags |= CHN_F_BUSY;
c->pid = pid;
strlcpy(c->comm, (comm != NULL) ? comm :
CHN_COMM_UNKNOWN, sizeof(c->comm));
*ch = c;
+
return (0);
- } else if (c->direction == direction && (c->flags & CHN_F_BUSY))
- err = EBUSY;
+ }
CHN_UNLOCK(c);
}
-
- /*
- * We came from retry_chnalloc and still didn't find a free channel.
- */
+ /* Maybe next time... */
if (retry)
- return (err);
+ return (EBUSY);
-vchan_alloc:
- /* no channel available */
+ /* No channel available. We also cannot create more VCHANs. */
if (!(vchancount > 0 && vchancount < snd_maxautovchans))
- return (err);
- err = vchan_setnew(d, direction, vchancount + 1);
- if (err == 0) {
+ return (ENOTSUP);
+
+ /* Increase the VCHAN count and try to get the new channel. */
+ if (vchan_setnew(d, direction, vchancount + 1) == 0) {
retry = true;
goto retry_chnalloc;
}
- return (err);
+ __assert_unreachable();
}
static int
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 13, 6:37 AM (12 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41694541
Default Alt Text
D46548.1794551830.diff (2 KB)
Attached To
Mode
D46548: sound: Simplify pcm_chnalloc() and fix infinite loop bug
Attached
Detach File
Event Timeline