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

ALSA: usb-audio: Simplify with usb_endpoint_max_periodic_payload()

Recently we received a new helper function,
usb_endpoint_max_periodic_payload(), for calculating the max packet
size for periodic transfer.

Simplify the former open code with the new helper function.

Fixes: a748e1dbb2df ("ALSA: usb-audio: Fix max bytes-per-interval calculation")
Suggested-by: Michal Pecio <michal.pecio@gmail.com>
Link: https://lore.kernel.org/20251124210518.90054-1-dylan_robinson@motu.com
Link: https://patch.msgid.link/20251202070828.145656-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+2 -32
+2 -32
sound/usb/stream.c
··· 684 684 return NULL; 685 685 } 686 686 687 - static unsigned int 688 - snd_usb_max_bytes_per_interval(struct snd_usb_audio *chip, 689 - struct usb_host_interface *alts) 690 - { 691 - struct usb_host_endpoint *ep = &alts->endpoint[0]; 692 - unsigned int max_bytes = usb_endpoint_maxp(&ep->desc); 693 - 694 - /* SuperSpeed isoc endpoints have up to 16 bursts of up to 3 packets each */ 695 - if (snd_usb_get_speed(chip->dev) >= USB_SPEED_SUPER) { 696 - int burst = 1 + ep->ss_ep_comp.bMaxBurst; 697 - int mult = USB_SS_MULT(ep->ss_ep_comp.bmAttributes); 698 - max_bytes *= burst; 699 - max_bytes *= mult; 700 - } 701 - 702 - if (snd_usb_get_speed(chip->dev) == USB_SPEED_SUPER_PLUS && 703 - USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) { 704 - max_bytes = le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval); 705 - } 706 - 707 - /* High speed, 1-3 packets/uframe, max 6 for eUSB2 double bw */ 708 - if (snd_usb_get_speed(chip->dev) == USB_SPEED_HIGH) { 709 - if (usb_endpoint_is_hs_isoc_double(chip->dev, ep)) 710 - max_bytes = le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval); 711 - else 712 - max_bytes *= usb_endpoint_maxp_mult(&ep->desc); 713 - } 714 - 715 - return max_bytes; 716 - } 717 - 718 687 static struct audioformat * 719 688 audio_format_alloc_init(struct snd_usb_audio *chip, 720 689 struct usb_host_interface *alts, 721 690 int protocol, int iface_no, int altset_idx, 722 691 int altno, int num_channels, int clock) 723 692 { 693 + struct usb_host_endpoint *ep = &alts->endpoint[0]; 724 694 struct audioformat *fp; 725 695 726 696 fp = kzalloc(sizeof(*fp), GFP_KERNEL); ··· 704 734 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; 705 735 fp->datainterval = snd_usb_parse_datainterval(chip, alts); 706 736 fp->protocol = protocol; 707 - fp->maxpacksize = snd_usb_max_bytes_per_interval(chip, alts); 737 + fp->maxpacksize = usb_endpoint_max_periodic_payload(chip->dev, ep); 708 738 fp->channels = num_channels; 709 739 fp->clock = clock; 710 740 INIT_LIST_HEAD(&fp->list);