Skip to content

Commit 57e6dae

Browse files
cladischtiwai
authored andcommitted
ALSA: usb-audio: do not trust too-big wMaxPacketSize values
The driver used to assume that the streaming endpoint's wMaxPacketSize value would be an indication of how much data the endpoint expects or sends, and compute the number of packets per URB using this value. However, the Focusrite Scarlett 2i4 declares a value of 1024 bytes, while only about 88 or 44 bytes are be actually used. This discrepancy would result in URBs with far too few packets, which would not work correctly on the EHCI driver. To get correct URBs, use wMaxPacketSize only as an upper limit on the packet size. Reported-by: James Stone <[email protected]> Tested-by: James Stone <[email protected]> Cc: <[email protected]> # 2.6.35+ Signed-off-by: Clemens Ladisch <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent ddb6b5a commit 57e6dae

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

sound/usb/endpoint.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,16 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
591591
ep->stride = frame_bits >> 3;
592592
ep->silence_value = pcm_format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0;
593593

594-
/* calculate max. frequency */
595-
if (ep->maxpacksize) {
594+
/* assume max. frequency is 25% higher than nominal */
595+
ep->freqmax = ep->freqn + (ep->freqn >> 2);
596+
maxsize = ((ep->freqmax + 0xffff) * (frame_bits >> 3))
597+
>> (16 - ep->datainterval);
598+
/* but wMaxPacketSize might reduce this */
599+
if (ep->maxpacksize && ep->maxpacksize < maxsize) {
596600
/* whatever fits into a max. size packet */
597601
maxsize = ep->maxpacksize;
598602
ep->freqmax = (maxsize / (frame_bits >> 3))
599603
<< (16 - ep->datainterval);
600-
} else {
601-
/* no max. packet size: just take 25% higher than nominal */
602-
ep->freqmax = ep->freqn + (ep->freqn >> 2);
603-
maxsize = ((ep->freqmax + 0xffff) * (frame_bits >> 3))
604-
>> (16 - ep->datainterval);
605604
}
606605

607606
if (ep->fill_max)

0 commit comments

Comments
 (0)