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~11709 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f355c97f4caa2f12b6561ccf2497c4860e47a572;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 d05397ec8a18..9c333f1cc62a 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)