Skip to content

Commit 973a578

Browse files
crwulffgregkh
authored andcommitted
usb: gadget: core: Check for unset descriptor
Make sure the descriptor has been set before looking at maxpacket. This fixes a null pointer panic in this case. This may happen if the gadget doesn't properly set up the endpoint for the current speed, or the gadget descriptors are malformed and the descriptor for the speed/endpoint are not found. No current gadget driver is known to have this problem, but this may cause a hard-to-find bug during development of new gadgets. Fixes: 54f83b8 ("USB: gadget: Reject endpoints with 0 maxpacket value") 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]>
1 parent afdcfd3 commit 973a578

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/usb/gadget/udc/core.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,10 @@ int usb_ep_enable(struct usb_ep *ep)
118118
goto out;
119119

120120
/* UDC drivers can't handle endpoints with maxpacket size 0 */
121-
if (usb_endpoint_maxp(ep->desc) == 0) {
122-
/*
123-
* We should log an error message here, but we can't call
124-
* dev_err() because there's no way to find the gadget
125-
* given only ep.
126-
*/
121+
if (!ep->desc || usb_endpoint_maxp(ep->desc) == 0) {
122+
WARN_ONCE(1, "%s: ep%d (%s) has %s\n", __func__, ep->address, ep->name,
123+
(!ep->desc) ? "NULL descriptor" : "maxpacket 0");
124+
127125
ret = -EINVAL;
128126
goto out;
129127
}

0 commit comments

Comments
 (0)