Commit 0878263b authored by Felipe Balbi's avatar Felipe Balbi

usb: gadget: composite: avoid kernel oops with bad gadgets

If a gadget driver loaded to a Superspeed-capable
peripheral controller, using a Superspeed cable,
doesn't provide Superspeed descriptors, we will get
a NULL pointer dereference.

In order to avoid that situation, we will try to
find any valid descriptors we can. If no set of
descriptors is passed in, then we'll let that gadget
oops anyhow.
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent ce046d32
...@@ -66,20 +66,36 @@ function_descriptors(struct usb_function *f, ...@@ -66,20 +66,36 @@ function_descriptors(struct usb_function *f,
{ {
struct usb_descriptor_header **descriptors; struct usb_descriptor_header **descriptors;
/*
* NOTE: we try to help gadget drivers which might not be setting
* max_speed appropriately.
*/
switch (speed) { switch (speed) {
case USB_SPEED_SUPER_PLUS: case USB_SPEED_SUPER_PLUS:
descriptors = f->ssp_descriptors; descriptors = f->ssp_descriptors;
if (descriptors)
break; break;
/* FALLTHROUGH */
case USB_SPEED_SUPER: case USB_SPEED_SUPER:
descriptors = f->ss_descriptors; descriptors = f->ss_descriptors;
if (descriptors)
break; break;
/* FALLTHROUGH */
case USB_SPEED_HIGH: case USB_SPEED_HIGH:
descriptors = f->hs_descriptors; descriptors = f->hs_descriptors;
if (descriptors)
break; break;
/* FALLTHROUGH */
default: default:
descriptors = f->fs_descriptors; descriptors = f->fs_descriptors;
} }
/*
* if we can't find any descriptors at all, then this gadget deserves to
* Oops with a NULL pointer dereference
*/
return descriptors; return descriptors;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment