Skip to content

Commit

Permalink
usb: gadget: u_audio: Fix high-speed max packet size
Browse files Browse the repository at this point in the history
Prior to commit eb9fecb ("usb: gadget: f_uac2: split out audio
core") the maximum packet size was calculated only from the high-speed
descriptor but now we use the largest of the full-speed and high-speed
descriptors.

This is correct, but the full-speed value is likely to be higher than
that for high-speed and this leads to submitting requests for OUT
transfers (received by the gadget) which are larger than the endpoint's
maximum packet size.  These are rightly rejected by the gadget core.

config_ep_by_speed() already sets up the correct maximum packet size for
the enumerated speed in the usb_ep structure, so we can simply use this
instead of the overall value that has been used to allocate buffers for
requests.

Note that the minimum period for ALSA is still set from the largest
value, and this is unavoidable because it's possible to open the audio
device before the gadget has been enumerated.

Tested-by: Pavel Hofman  <pavel.hofman@ivitera.com>
Signed-off-by: John Keeping <john@metanate.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
  • Loading branch information
John Keeping authored and Felipe Balbi committed Feb 11, 2020
1 parent 5ee8589 commit 904967c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/usb/gadget/function/u_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ int u_audio_start_capture(struct g_audio *audio_dev)
ep = audio_dev->out_ep;
prm = &uac->c_prm;
config_ep_by_speed(gadget, &audio_dev->func, ep);
req_len = prm->max_psize;
req_len = ep->maxpacket;

prm->ep_enabled = true;
usb_ep_enable(ep);
Expand All @@ -379,7 +379,7 @@ int u_audio_start_capture(struct g_audio *audio_dev)
req->context = &prm->ureq[i];
req->length = req_len;
req->complete = u_audio_iso_complete;
req->buf = prm->rbuf + i * prm->max_psize;
req->buf = prm->rbuf + i * ep->maxpacket;
}

if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC))
Expand Down Expand Up @@ -430,9 +430,9 @@ int u_audio_start_playback(struct g_audio *audio_dev)
uac->p_pktsize = min_t(unsigned int,
uac->p_framesize *
(params->p_srate / uac->p_interval),
prm->max_psize);
ep->maxpacket);

if (uac->p_pktsize < prm->max_psize)
if (uac->p_pktsize < ep->maxpacket)
uac->p_pktsize_residue = uac->p_framesize *
(params->p_srate % uac->p_interval);
else
Expand All @@ -457,7 +457,7 @@ int u_audio_start_playback(struct g_audio *audio_dev)
req->context = &prm->ureq[i];
req->length = req_len;
req->complete = u_audio_iso_complete;
req->buf = prm->rbuf + i * prm->max_psize;
req->buf = prm->rbuf + i * ep->maxpacket;
}

if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC))
Expand Down

0 comments on commit 904967c

Please sign in to comment.