ALSA: usb-audio: Cap upper limits of buffer/period bytes for implicit fb
authorTakashi Iwai <tiwai@suse.de>
Thu, 7 Apr 2022 21:16:57 +0000 (23:16 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 8 Apr 2022 12:30:01 +0000 (14:30 +0200)
commit98c27add5d96485db731a92dac31567b0486cae8
treeade5f799bb87f3a8c7020191b24404b29b331c7f
parentd52eee988597ac2a2c5d17d842946616d7d41070
ALSA: usb-audio: Cap upper limits of buffer/period bytes for implicit fb

In the implicit feedback mode, some parameters are tied between both
playback and capture streams.  One of the tied parameters is the
period size, and this can be a problem if the device has different
number of channels to both streams.  Assume that an application opens
a playback stream that has an implicit feedback from a capture stream,
and it allocates up to the max period and buffer size as much as
possible.  When the capture device supports only more channels than
the playback, the minimum period and buffer sizes become larger than
the sizes the playback stream took.  That is, the minimum size will be
over the max size the driver limits, and PCM core sees as if no
available configuration is found, returning -EINVAL mercilessly.

For avoiding this problem, we have to look through the counter part of
audioformat list for each sync ep, and checks the channels.  If more
channels are found there, we reduce the max period and buffer sizes
accordingly.

You may wonder that the patch adds only the evaluation of channels
between streams, and what about other parameters?  Both the format and
the rate are tied in the implicit fb mode, hence they are always
identical.

BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=215792
Fixes: 5a6c3e11c9c9 ("ALSA: usb-audio: Add hw constraint for implicit fb sync")
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20220407211657.15087-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/pcm.c