Skip to content

Commit

Permalink
usb: gadget: u_audio: Check return codes from usb_ep_enable and confi…
Browse files Browse the repository at this point in the history
…g_ep_by_speed.

[ Upstream commit 76a7bfc ]

These functions can fail if descriptors are malformed, or missing,
for the selected USB speed.

Fixes: eb9fecb ("usb: gadget: f_uac2: split out audio core")
Fixes: 24f779d ("usb: gadget: f_uac2/u_audio: add feedback endpoint support")
Cc: [email protected]
Signed-off-by: Chris Wulff <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
crwulff authored and gregkh committed Aug 19, 2024
1 parent a6117b3 commit 479e23a
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions drivers/usb/gadget/function/u_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,24 @@ int u_audio_start_capture(struct g_audio *audio_dev)
struct usb_ep *ep, *ep_fback;
struct uac_rtd_params *prm;
struct uac_params *params = &audio_dev->params;
int req_len, i;
int req_len, i, ret;

ep = audio_dev->out_ep;
prm = &uac->c_prm;
config_ep_by_speed(gadget, &audio_dev->func, ep);
ret = config_ep_by_speed(gadget, &audio_dev->func, ep);
if (ret < 0) {
dev_err(dev, "config_ep_by_speed for out_ep failed (%d)\n", ret);
return ret;
}

req_len = ep->maxpacket;

prm->ep_enabled = true;
usb_ep_enable(ep);
ret = usb_ep_enable(ep);
if (ret < 0) {
dev_err(dev, "usb_ep_enable failed for out_ep (%d)\n", ret);
return ret;
}

for (i = 0; i < params->req_number; i++) {
if (!prm->reqs[i]) {
Expand All @@ -508,9 +517,18 @@ int u_audio_start_capture(struct g_audio *audio_dev)
return 0;

/* Setup feedback endpoint */
config_ep_by_speed(gadget, &audio_dev->func, ep_fback);
ret = config_ep_by_speed(gadget, &audio_dev->func, ep_fback);
if (ret < 0) {
dev_err(dev, "config_ep_by_speed in_ep_fback failed (%d)\n", ret);
return ret; // TODO: Clean up out_ep
}

prm->fb_ep_enabled = true;
usb_ep_enable(ep_fback);
ret = usb_ep_enable(ep_fback);
if (ret < 0) {
dev_err(dev, "usb_ep_enable failed for in_ep_fback (%d)\n", ret);
return ret; // TODO: Clean up out_ep
}
req_len = ep_fback->maxpacket;

req_fback = usb_ep_alloc_request(ep_fback, GFP_ATOMIC);
Expand Down Expand Up @@ -565,11 +583,15 @@ int u_audio_start_playback(struct g_audio *audio_dev)
struct uac_params *params = &audio_dev->params;
unsigned int factor;
const struct usb_endpoint_descriptor *ep_desc;
int req_len, i;
int req_len, i, ret;

ep = audio_dev->in_ep;
prm = &uac->p_prm;
config_ep_by_speed(gadget, &audio_dev->func, ep);
ret = config_ep_by_speed(gadget, &audio_dev->func, ep);
if (ret < 0) {
dev_err(dev, "config_ep_by_speed for in_ep failed (%d)\n", ret);
return ret;
}

ep_desc = ep->desc;

Expand Down Expand Up @@ -598,7 +620,11 @@ int u_audio_start_playback(struct g_audio *audio_dev)
uac->p_residue = 0;

prm->ep_enabled = true;
usb_ep_enable(ep);
ret = usb_ep_enable(ep);
if (ret < 0) {
dev_err(dev, "usb_ep_enable failed for in_ep (%d)\n", ret);
return ret;
}

for (i = 0; i < params->req_number; i++) {
if (!prm->reqs[i]) {
Expand Down

0 comments on commit 479e23a

Please sign in to comment.