usb:g_dnl: Replace static usb_configuration structure with dynamically allocated one
authorLukasz Majewski <l.majewski@samsung.com>
Tue, 8 Oct 2013 12:30:40 +0000 (14:30 +0200)
committerChanho Park <chanho61.park@samsung.com>
Fri, 24 Jul 2015 07:29:51 +0000 (16:29 +0900)
When the usb_configuration structure is declared as static, it is very
hard to assure, that relevant fields (as e.g. config->interfaces[]) are
cleared out before new call to g_dnl related functions.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
drivers/usb/gadget/g_dnl.c

index 9d4bca873ec34faba6872e9fcc59ce4b17b25dd2..74ba8623d356bcbcc9130b929447680a192d782e 100644 (file)
@@ -91,6 +91,8 @@ static int g_dnl_unbind(struct usb_composite_dev *cdev)
 {
        struct usb_gadget *gadget = cdev->gadget;
 
+       free(cdev->config);
+       cdev->config = NULL;
        debug("%s: calling usb_gadget_disconnect for "
                        "controller '%s'\n", shortname, gadget->name);
        usb_gadget_disconnect(gadget);
@@ -117,16 +119,22 @@ static int g_dnl_do_config(struct usb_configuration *c)
 
 static int g_dnl_config_register(struct usb_composite_dev *cdev)
 {
-       static struct usb_configuration config = {
-               .label = "usb_dnload",
-               .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
-               .bConfigurationValue =  CONFIGURATION_NUMBER,
-               .iConfiguration =       STRING_USBDOWN,
+       struct usb_configuration *config;
+       const char *name = "usb_dnload";
 
-               .bind = g_dnl_do_config,
-       };
+       config = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*config));
+       if (!config)
+               return -ENOMEM;
 
-       return usb_add_config(cdev, &config);
+       memset(config, 0, sizeof(*config));
+
+       config->label = name;
+       config->bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER;
+       config->bConfigurationValue = CONFIGURATION_NUMBER;
+       config->iConfiguration = STRING_USBDOWN;
+       config->bind = g_dnl_do_config;
+
+       return usb_add_config(cdev, config);
 }
 
 __weak