From f355c97f4caa2f12b6561ccf2497c4860e47a572 Mon Sep 17 00:00:00 2001 From: Jared Suttles Date: Thu, 30 Jul 2009 16:13:27 -0500 Subject: [PATCH] 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 --- drivers/usb/gadget/composite.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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) -- 2.34.1