HomeFreeBSD

sound: Simplify pcm_chnalloc() and fix infinite loop bug

Description

sound: Simplify pcm_chnalloc() and fix infinite loop bug

Simplify logic to execute the following algorithm:

  1. Search for a free (i.e not busy) channel and return successfully.
  2. If no channel was found, either return an ENOTSUP if no VCHAN can be created (disabled or we reached the limit), or create one more VCHAN and scan for it again.
  3. If the second scan failed again, return EBUSY.

This patch also solves a bug where we'd end up in an infinite loop,
calling vchan_setnew() with the same newcnt value indefinitely, after
the following scenario:

  1. Plug device.
  2. Spawn X channels.
  3. Kill all channels except _last_ opened.
  4. Clean up all unused VCHANs.
  5. Spawn X+1 channels.
  6. Infinite loop in pcm_chnalloc().

I am not exactly sure which part of pcm_chnalloc() caused this bug, but
the patch fixes it at least...

Sponsored by: The FreeBSD Foundation
MFC after: 2 days
Reviewed by: dev_submerge.ch
Differential Revision: https://reviews.freebsd.org/D46548

(cherry picked from commit b973a14d354f332a3428cbab8e9d4b72cb3e2d6e)

Details

Provenance
christosAuthored on Fri, Oct 18, 8:38 AM
Reviewer
dev_submerge.ch
Differential Revision
D46548: sound: Simplify pcm_chnalloc() and fix infinite loop bug
Parents
rG9834b6fc77ff: sound: Get rid of pnum and max variables in chn_init()
Branches
Unknown
Tags
Unknown