usb:g_dnl: Replace static usb_configuration structure with dynamically allocated one

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>
master
Lukasz Majewski 12 years ago committed by Marek Vasut
parent d42782631d
commit 7b412ab31f
  1. 24
      drivers/usb/gadget/g_dnl.c

@ -79,6 +79,8 @@ static int g_dnl_unbind(struct usb_composite_dev *cdev)
{ {
struct usb_gadget *gadget = cdev->gadget; struct usb_gadget *gadget = cdev->gadget;
free(cdev->config);
cdev->config = NULL;
debug("%s: calling usb_gadget_disconnect for " debug("%s: calling usb_gadget_disconnect for "
"controller '%s'\n", shortname, gadget->name); "controller '%s'\n", shortname, gadget->name);
usb_gadget_disconnect(gadget); usb_gadget_disconnect(gadget);
@ -105,16 +107,22 @@ static int g_dnl_do_config(struct usb_configuration *c)
static int g_dnl_config_register(struct usb_composite_dev *cdev) static int g_dnl_config_register(struct usb_composite_dev *cdev)
{ {
static struct usb_configuration config = { struct usb_configuration *config;
.label = "usb_dnload", const char *name = "usb_dnload";
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
.bConfigurationValue = CONFIGURATION_NUMBER,
.iConfiguration = STRING_USBDOWN,
.bind = g_dnl_do_config, config = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*config));
}; if (!config)
return -ENOMEM;
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); return usb_add_config(cdev, config);
} }
__weak __weak

Loading…
Cancel
Save