Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: usb-audio: Fix EP matching for continuous rates

The function to evaluate the match of the parameters with an EP
assumes only the discrete rate tables and doesn't handle the
continuous rates properly.

This patch fixes match_endpoint_audioformats() to handle the
continuous rates. Also the almost useless debug prints there are
dropped.

Tested-by: Keith Milner <kamilner@superlative.org>
Tested-by: Dylan Robinson <dylan_robinson@motu.com>
Link: https://lore.kernel.org/r/20201123085347.19667-25-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+13 -24
+13 -24
sound/usb/pcm.c
··· 695 695 struct audioformat *match, int rate, 696 696 snd_pcm_format_t pcm_format) 697 697 { 698 - int i; 699 - int score = 0; 698 + int i, score; 700 699 701 - if (fp->channels < 1) { 702 - dev_dbg(&subs->dev->dev, 703 - "%s: (fmt @%p) no channels\n", __func__, fp); 700 + if (fp->channels < 1) 704 701 return 0; 705 - } 706 702 707 - if (!(fp->formats & pcm_format_to_bits(pcm_format))) { 708 - dev_dbg(&subs->dev->dev, 709 - "%s: (fmt @%p) no match for format %d\n", __func__, 710 - fp, pcm_format); 703 + if (!(fp->formats & pcm_format_to_bits(pcm_format))) 711 704 return 0; 712 - } 713 705 714 - for (i = 0; i < fp->nr_rates; i++) { 715 - if (fp->rate_table[i] == rate) { 716 - score++; 717 - break; 706 + if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) { 707 + if (rate < fp->rate_min || rate > fp->rate_max) 708 + return 0; 709 + } else { 710 + for (i = 0; i < fp->nr_rates; i++) { 711 + if (fp->rate_table[i] == rate) 712 + break; 718 713 } 719 - } 720 - if (!score) { 721 - dev_dbg(&subs->dev->dev, 722 - "%s: (fmt @%p) no match for rate %d\n", __func__, 723 - fp, rate); 724 - return 0; 714 + if (i >= fp->nr_rates) 715 + return 0; 725 716 } 726 717 718 + score = 1; 727 719 if (fp->channels == match->channels) 728 720 score++; 729 - 730 - dev_dbg(&subs->dev->dev, 731 - "%s: (fmt @%p) score %d\n", __func__, fp, score); 732 721 733 722 return score; 734 723 }