Commit 0412558c authored by Takashi Iwai's avatar Takashi Iwai

ALSA: usb-audio - Fix non-continuous rate detection

The detection of non-continuous rates (given via rate tables) isn't
processed properly (e.g. for type II).

This patch fixes and simplifies the detection code.
Tested-by: default avatarJoris van Rantwijk <jorispubl@xs4all.nl>
Cc: <stable@kernel.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent e156ac4c
...@@ -2524,7 +2524,6 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform ...@@ -2524,7 +2524,6 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform
* build the rate table and bitmap flags * build the rate table and bitmap flags
*/ */
int r, idx; int r, idx;
unsigned int nonzero_rates = 0;
fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL); fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
if (fp->rate_table == NULL) { if (fp->rate_table == NULL) {
...@@ -2532,24 +2531,26 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform ...@@ -2532,24 +2531,26 @@ static int parse_audio_format_rates(struct snd_usb_audio *chip, struct audioform
return -1; return -1;
} }
fp->nr_rates = nr_rates; fp->nr_rates = 0;
fp->rate_min = fp->rate_max = combine_triple(&fmt[8]); fp->rate_min = fp->rate_max = 0;
for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) { for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) {
unsigned int rate = combine_triple(&fmt[idx]); unsigned int rate = combine_triple(&fmt[idx]);
if (!rate)
continue;
/* C-Media CM6501 mislabels its 96 kHz altsetting */ /* C-Media CM6501 mislabels its 96 kHz altsetting */
if (rate == 48000 && nr_rates == 1 && if (rate == 48000 && nr_rates == 1 &&
chip->usb_id == USB_ID(0x0d8c, 0x0201) && chip->usb_id == USB_ID(0x0d8c, 0x0201) &&
fp->altsetting == 5 && fp->maxpacksize == 392) fp->altsetting == 5 && fp->maxpacksize == 392)
rate = 96000; rate = 96000;
fp->rate_table[r] = rate; fp->rate_table[fp->nr_rates] = rate;
nonzero_rates |= rate; if (!fp->rate_min || rate < fp->rate_min)
if (rate < fp->rate_min)
fp->rate_min = rate; fp->rate_min = rate;
else if (rate > fp->rate_max) if (!fp->rate_max || rate > fp->rate_max)
fp->rate_max = rate; fp->rate_max = rate;
fp->rates |= snd_pcm_rate_to_rate_bit(rate); fp->rates |= snd_pcm_rate_to_rate_bit(rate);
fp->nr_rates++;
} }
if (!nonzero_rates) { if (!fp->nr_rates) {
hwc_debug("All rates were zero. Skipping format!\n"); hwc_debug("All rates were zero. Skipping format!\n");
return -1; return -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment