Skip to content

Commit cf5425e

Browse files
committed
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: a748e1d ("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>
1 parent a30fa81 commit cf5425e

1 file changed

Lines changed: 2 additions & 32 deletions

File tree

sound/usb/stream.c

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -684,43 +684,13 @@ snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface,
684684
return NULL;
685685
}
686686

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-
718687
static struct audioformat *
719688
audio_format_alloc_init(struct snd_usb_audio *chip,
720689
struct usb_host_interface *alts,
721690
int protocol, int iface_no, int altset_idx,
722691
int altno, int num_channels, int clock)
723692
{
693+
struct usb_host_endpoint *ep = &alts->endpoint[0];
724694
struct audioformat *fp;
725695

726696
fp = kzalloc(sizeof(*fp), GFP_KERNEL);
@@ -734,7 +704,7 @@ audio_format_alloc_init(struct snd_usb_audio *chip,
734704
fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
735705
fp->datainterval = snd_usb_parse_datainterval(chip, alts);
736706
fp->protocol = protocol;
737-
fp->maxpacksize = snd_usb_max_bytes_per_interval(chip, alts);
707+
fp->maxpacksize = usb_endpoint_max_periodic_payload(chip->dev, ep);
738708
fp->channels = num_channels;
739709
fp->clock = clock;
740710
INIT_LIST_HEAD(&fp->list);

0 commit comments

Comments
 (0)