ALSA: usb-audio: Fix races at disconnection in mixer_quirks.c
[linux-2.6.git] / sound / usb / format.c
index 8d042dc..ddfef57 100644 (file)
@@ -226,7 +226,7 @@ static int parse_uac2_sample_rate_range(struct audioformat *fp, int nr_triplets,
                int min = combine_quad(&data[2 + 12 * i]);
                int max = combine_quad(&data[6 + 12 * i]);
                int res = combine_quad(&data[10 + 12 * i]);
-               int rate;
+               unsigned int rate;
 
                if ((max < 0) || (min < 0) || (res < 0) || (max < min))
                        continue;
@@ -253,6 +253,10 @@ static int parse_uac2_sample_rate_range(struct audioformat *fp, int nr_triplets,
                        fp->rates |= snd_pcm_rate_to_rate_bit(rate);
 
                        nr_rates++;
+                       if (nr_rates >= MAX_NR_RATES) {
+                               snd_printk(KERN_ERR "invalid uac2 rates\n");
+                               break;
+                       }
 
                        /* avoid endless loop */
                        if (res == 0)
@@ -286,7 +290,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
                              USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
                              UAC2_CS_CONTROL_SAM_FREQ << 8,
                              snd_usb_ctrl_intf(chip) | (clock << 8),
-                             tmp, sizeof(tmp), 1000);
+                             tmp, sizeof(tmp));
 
        if (ret < 0) {
                snd_printk(KERN_ERR "%s(): unable to retrieve number of sample rates (clock %d)\n",
@@ -307,7 +311,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
                              USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
                              UAC2_CS_CONTROL_SAM_FREQ << 8,
                              snd_usb_ctrl_intf(chip) | (clock << 8),
-                             data, data_size, 1000);
+                             data, data_size);
 
        if (ret < 0) {
                snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range (clock %d)\n",