usb: gadget: Fix usb string id allocation
authorBenoit Goby <benoit@android.com>
Fri, 20 Jan 2012 22:42:41 +0000 (14:42 -0800)
committerArve Hjønnevåg <arve@android.com>
Mon, 1 Jul 2013 20:40:51 +0000 (13:40 -0700)
Don't reset next_string_id every time the gadget is enabled, this makes
the next strings allocated overwrite strings allocated at probe time.
Instead, fix rndis not to allocate new string ids on every config bind.

Change-Id: Ied28ee416bb6f00c434c34176fe5b7f0dcb2b2d4
Signed-off-by: Benoit Goby <benoit@android.com>
drivers/usb/gadget/android.c
drivers/usb/gadget/f_rndis.c
drivers/usb/gadget/rndis.c

index ff60af76822804657336176fc280cd35704719bb..5a65149a185e48d537d16b5bed1b00a590c1da36 100644 (file)
@@ -1150,7 +1150,6 @@ static ssize_t enable_store(struct device *pdev, struct device_attribute *attr,
 
        sscanf(buff, "%d", &enabled);
        if (enabled && !dev->enabled) {
-               cdev->next_string_id = 0;
                /*
                 * Update values in composite driver's copy of
                 * device descriptor.
index 36e8c44d8e5e2fb04222b86b4e9fbc4d3a493083..21c5ee2482d6c3f3181fa14a75f8c375d4f971d5 100644 (file)
@@ -821,12 +821,12 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
        if (!can_support_rndis(c) || !ethaddr)
                return -EINVAL;
 
-       if (rndis_string_defs[0].id == 0) {
-               /* ... and setup RNDIS itself */
-               status = rndis_init();
-               if (status < 0)
-                       return status;
+       /* setup RNDIS itself */
+       status = rndis_init();
+       if (status < 0)
+               return status;
 
+       if (rndis_string_defs[0].id == 0) {
                status = usb_string_ids_tab(c->cdev, rndis_string_defs);
                if (status)
                        return status;
index 1e4cfb05f70b9a0bba6a2fa421ef696d7649e8e8..693f0c24d51608955055a558fcc9d2e440495da3 100644 (file)
@@ -1127,11 +1127,15 @@ static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
 
 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
 
+static bool rndis_initialized;
 
 int rndis_init(void)
 {
        u8 i;
 
+       if (rndis_initialized)
+               return 0;
+
        for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
                char name [20];
@@ -1158,6 +1162,7 @@ int rndis_init(void)
                INIT_LIST_HEAD(&(rndis_per_dev_params[i].resp_queue));
        }
 
+       rndis_initialized = true;
        return 0;
 }
 
@@ -1166,7 +1171,13 @@ void rndis_exit(void)
 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
        u8 i;
        char name[20];
+#endif
 
+       if (!rndis_initialized)
+               return;
+       rndis_initialized = false;
+
+#ifdef CONFIG_USB_GADGET_DEBUG_FILES
        for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
                sprintf(name, NAME_TEMPLATE, i);
                remove_proc_entry(name, NULL);