From: Jared Suttles Date: Thu, 30 Jul 2009 21:13:27 +0000 (-0500) Subject: drivers: usb: gadget: handle NULL descriptors in composite config_buf X-Git-Tag: firefly_0821_release~9833^2~5^2~289 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9fd9743c8866f2d4145654b302a6e59b71dc5203;p=firefly-linux-kernel-4.4.55.git drivers: usb: gadget: handle NULL descriptors in composite config_buf This fixes a problem in enumeration after a gadget function is removed. Submitted on behalf of RaviKumar Vembu Signed-off-by: Jared Suttles Signed-off-by: Mike Lockwood --- diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 1160c55de7f2..65012ff1c2ed 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -236,6 +236,7 @@ static int config_buf(struct usb_configuration *config, int len = USB_BUFSIZ - USB_DT_CONFIG_SIZE; struct usb_function *f; int status; + int interfaceCount = 0; /* write the config descriptor */ c = buf; @@ -266,8 +267,16 @@ static int config_buf(struct usb_configuration *config, descriptors = f->hs_descriptors; else descriptors = f->descriptors; - if (!descriptors) + if (!descriptors || descriptors[0] == NULL) { + for (; f != config->interface[interfaceCount];) { + interfaceCount++; + c->bNumInterfaces--; + } continue; + } + for (; f != config->interface[interfaceCount];) + interfaceCount++; + status = usb_descriptor_fillbuf(next, len, (const struct usb_descriptor_header **) descriptors); if (status < 0)