Skip to content

Commit 2ed2ebe

Browse files
johnkeepingrkhuangtao
authored andcommitted
UPSTREAM: usb: gadget: f_uac2: fix packet size calculation
The packet size for USB audio must always be a multiple of the frame size, otherwise we are transmitting a partial frame which omits some channels (and these end up at the wrong offset in the next packet). Furthermore, it breaks the residue handling such that we end up trying to send a packet exceeding the maximum packet size for the endpoint. Signed-off-by: Ren Jianing <jianing.ren@rock-chips.com> Signed-off-by: John Keeping <john@metanate.com> Signed-off-by: Felipe Balbi <balbi@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Change-Id: I8181ce167a4c80a0e80bb51003f3e4ec8fa4b92d (cherry picked from commit 6b02af3465ee11b63a938b13bddbf7ecd92860f3)
1 parent dca70ed commit 2ed2ebe

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

drivers/usb/gadget/function/u_audio.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ int u_audio_start_playback(struct g_audio *audio_dev)
546546
struct usb_ep *ep;
547547
struct uac_rtd_params *prm;
548548
struct uac_params *params = &audio_dev->params;
549-
unsigned int factor, rate;
549+
unsigned int factor;
550550
const struct usb_endpoint_descriptor *ep_desc;
551551
int req_len, i;
552552

@@ -570,13 +570,15 @@ int u_audio_start_playback(struct g_audio *audio_dev)
570570
/* pre-compute some values for iso_complete() */
571571
uac->p_framesize = params->p_ssize *
572572
num_channels(params->p_chmask);
573-
rate = params->p_srate_active * uac->p_framesize;
574573
uac->p_interval = factor / (1 << (ep_desc->bInterval - 1));
575-
uac->p_pktsize = min_t(unsigned int, rate / uac->p_interval,
574+
uac->p_pktsize = min_t(unsigned int,
575+
uac->p_framesize *
576+
(params->p_srate_active / uac->p_interval),
576577
prm->max_psize);
577578

578579
if (uac->p_pktsize < prm->max_psize)
579-
uac->p_pktsize_residue = rate % uac->p_interval;
580+
uac->p_pktsize_residue = uac->p_framesize *
581+
(params->p_srate_active % uac->p_interval);
580582
else
581583
uac->p_pktsize_residue = 0;
582584

0 commit comments

Comments
 (0)