usb: gadget: Provide a default implementation of default manufacturer string
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Mon, 10 Sep 2012 13:01:58 +0000 (15:01 +0200)
committerFelipe Balbi <balbi@ti.com>
Mon, 10 Sep 2012 13:13:02 +0000 (16:13 +0300)
Some gadgets provide custom entry here. Some may override it with an
etntry that is also created by composite if there was no value sumbitted
at all.
This patch removes all "custom manufacturer" strings which are the same
as these which are created by composite. Then it moves the creation of
the default manufacturer string to usb_composite_overwrite_options() in
case no command line argument has been used and the entry is still an
empty string.
By doing this we get rid of the global variable "composite_manufacturer"
in composite.

Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
19 files changed:
drivers/usb/gadget/acm_ms.c
drivers/usb/gadget/audio.c
drivers/usb/gadget/cdc2.c
drivers/usb/gadget/composite.c
drivers/usb/gadget/ether.c
drivers/usb/gadget/f_hid.c
drivers/usb/gadget/f_mass_storage.c
drivers/usb/gadget/f_midi.c
drivers/usb/gadget/g_ffs.c
drivers/usb/gadget/gmidi.c
drivers/usb/gadget/hid.c
drivers/usb/gadget/mass_storage.c
drivers/usb/gadget/multi.c
drivers/usb/gadget/ncm.c
drivers/usb/gadget/nokia.c
drivers/usb/gadget/printer.c
drivers/usb/gadget/serial.c
drivers/usb/gadget/zero.c
include/linux/usb/composite.h

index 35db6aa572811fd6baa422796b53d26665cb128a..d280f164887c531e9fdc3dff24ac64e9a715e134 100644 (file)
@@ -15,7 +15,6 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/utsname.h>
 
 #include "u_serial.h"
 
@@ -87,13 +86,9 @@ static const struct usb_descriptor_header *otg_desc[] = {
        NULL,
 };
 
-
 /* string IDs are assigned dynamically */
-
-static char manufacturer[50];
-
 static struct usb_string strings_dev[] = {
-       [USB_GADGET_MANUFACTURER_IDX].s = manufacturer,
+       [USB_GADGET_MANUFACTURER_IDX].s = "",
        [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
        [USB_GADGET_SERIAL_IDX].s = "",
        {  } /* end of list */
@@ -186,11 +181,6 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
         * Allocate string descriptor numbers ... note that string
         * contents can be overridden by the composite_dev glue.
         */
-
-       /* device descriptor strings: manufacturer, product */
-       snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
-               init_utsname()->sysname, init_utsname()->release,
-               gadget->name);
        status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail1;
index 8857b6eeb6a2ed3f69cb38cd1f0915db91b809b6..1f81e0f4fab928bb20308b6e3cb94f1d0d0a1654 100644 (file)
@@ -12,7 +12,6 @@
 /* #define VERBOSE_DEBUG */
 
 #include <linux/kernel.h>
-#include <linux/utsname.h>
 #include <linux/usb/composite.h>
 
 #include "gadget_chips.h"
@@ -33,10 +32,8 @@ USB_GADGET_COMPOSITE_OPTIONS();
 
 /* string IDs are assigned dynamically */
 
-static char manufacturer[50];
-
 static struct usb_string strings_dev[] = {
-       [USB_GADGET_MANUFACTURER_IDX].s = manufacturer,
+       [USB_GADGET_MANUFACTURER_IDX].s = "",
        [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
        [USB_GADGET_SERIAL_IDX].s = "",
        {  } /* end of list */
@@ -161,10 +158,6 @@ static int __init audio_bind(struct usb_composite_dev *cdev)
                        __constant_cpu_to_le16(0x0300 | 0x0099);
        }
 
-       /* device descriptor strings: manufacturer, product */
-       snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
-               init_utsname()->sysname, init_utsname()->release,
-               cdev->gadget->name);
        status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail;
index 8966bdec15349469a11a70aaaa080ab3f820934d..4e2060bf35e3515a31ef8b137265e2c6b72240a5 100644 (file)
@@ -11,7 +11,6 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/utsname.h>
 #include <linux/module.h>
 
 #include "u_ether.h"
@@ -90,10 +89,8 @@ static const struct usb_descriptor_header *otg_desc[] = {
 
 
 /* string IDs are assigned dynamically */
-static char manufacturer[50];
-
 static struct usb_string strings_dev[] = {
-       [USB_GADGET_MANUFACTURER_IDX].s = manufacturer,
+       [USB_GADGET_MANUFACTURER_IDX].s = "",
        [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
        [USB_GADGET_SERIAL_IDX].s = "",
        {  } /* end of list */
@@ -182,15 +179,10 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
                        cpu_to_le16(0x0300 | 0x0099);
        }
 
-
        /* Allocate string descriptor numbers ... note that string
         * contents can be overridden by the composite_dev glue.
         */
 
-       /* device descriptor strings: manufacturer, product */
-       snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
-               init_utsname()->sysname, init_utsname()->release,
-               gadget->name);
        status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail1;
index f3689e1bf4b2e11dad1b349916fe7a3bf1c6fda9..c7066cd4c95a0e08f71cc6b6f7f17ac626fedd8c 100644 (file)
@@ -28,9 +28,6 @@
  * with the relevant device-wide data.
  */
 
-static char composite_manufacturer[50];
-
-/*-------------------------------------------------------------------------*/
 /**
  * next_ep_desc() - advance to the next EP descriptor
  * @t: currect pointer within descriptor array
@@ -860,7 +857,6 @@ static int get_string(struct usb_composite_dev *cdev,
        struct usb_configuration        *c;
        struct usb_function             *f;
        int                             len;
-       const char                      *str;
 
        /* Yes, not only is USB's I18N support probably more than most
         * folk will ever care about ... also, it's all supported here.
@@ -900,21 +896,6 @@ static int get_string(struct usb_composite_dev *cdev,
                return s->bLength;
        }
 
-       /* Otherwise, look up and return a specified string.  First
-        * check if the string has not been overridden.
-        */
-       if (cdev->manufacturer_override == id)
-               str = composite_manufacturer;
-       else
-               str = NULL;
-       if (str) {
-               struct usb_gadget_strings strings = {
-                       .language = language,
-                       .strings  = &(struct usb_string) { 0xff, str }
-               };
-               return usb_gadget_get_string(&strings, 0xff, buf);
-       }
-
        /* String IDs are device-scoped, so we look up each string
         * table we're told about.  These lookups are infrequent;
         * simpler-is-better here.
@@ -1367,23 +1348,11 @@ composite_unbind(struct usb_gadget *gadget)
                usb_ep_free_request(gadget->ep0, cdev->req);
        }
        device_remove_file(&gadget->dev, &dev_attr_suspended);
+       kfree(cdev->def_manufacturer);
        kfree(cdev);
        set_gadget_data(gadget, NULL);
 }
 
-static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
-{
-       if (!*desc) {
-               int ret = usb_string_id(cdev);
-               if (unlikely(ret < 0))
-                       WARNING(cdev, "failed to override string ID\n");
-               else
-                       *desc = ret;
-       }
-
-       return *desc;
-}
-
 static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
                const struct usb_device_descriptor *old)
 {
@@ -1477,19 +1446,6 @@ static int composite_bind(struct usb_gadget *gadget,
 
        update_unchanged_dev_desc(&cdev->desc, composite->dev);
 
-       /* string overrides */
-       if (!cdev->desc.iManufacturer) {
-               snprintf(composite_manufacturer,
-                               sizeof composite_manufacturer,
-                               "%s %s with %s",
-                               init_utsname()->sysname,
-                               init_utsname()->release,
-                               gadget->name);
-
-               cdev->manufacturer_override =
-                       override_id(cdev, &cdev->desc.iManufacturer);
-       }
-
        /* has userspace failed to provide a serial number? */
        if (composite->needs_serial && !cdev->desc.iSerialNumber)
                WARNING(cdev, "userspace failed to provide iSerialNumber\n");
@@ -1665,6 +1621,22 @@ void usb_composite_setup_continue(struct usb_composite_dev *cdev)
        spin_unlock_irqrestore(&cdev->lock, flags);
 }
 
+static char *composite_default_mfr(struct usb_gadget *gadget)
+{
+       char *mfr;
+       int len;
+
+       len = snprintf(NULL, 0, "%s %s with %s", init_utsname()->sysname,
+                       init_utsname()->release, gadget->name);
+       len++;
+       mfr = kmalloc(len, GFP_KERNEL);
+       if (!mfr)
+               return NULL;
+       snprintf(mfr, len, "%s %s with %s", init_utsname()->sysname,
+                       init_utsname()->release, gadget->name);
+       return mfr;
+}
+
 void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
                struct usb_composite_overwrite *covr)
 {
@@ -1688,6 +1660,11 @@ void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
        if (covr->manufacturer) {
                desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id;
                dev_str[USB_GADGET_MANUFACTURER_IDX].s = covr->manufacturer;
+
+       } else if (!strlen(dev_str[USB_GADGET_MANUFACTURER_IDX].s)) {
+               desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id;
+               cdev->def_manufacturer = composite_default_mfr(cdev->gadget);
+               dev_str[USB_GADGET_MANUFACTURER_IDX].s = cdev->def_manufacturer;
        }
 
        if (covr->product) {
index dd5e00d207fec91c595adb78105e3ce82a198e26..a5c2720676255d41f23fe75bf997811d1ae94b98 100644 (file)
@@ -14,8 +14,6 @@
 /* #define VERBOSE_DEBUG */
 
 #include <linux/kernel.h>
-#include <linux/utsname.h>
-
 
 #if defined USB_ETH_RNDIS
 #  undef USB_ETH_RNDIS
@@ -193,11 +191,8 @@ static const struct usb_descriptor_header *otg_desc[] = {
        NULL,
 };
 
-/* string IDs are assigned dynamically */
-static char manufacturer[50];
-
 static struct usb_string strings_dev[] = {
-       [USB_GADGET_MANUFACTURER_IDX].s = manufacturer,
+       [USB_GADGET_MANUFACTURER_IDX].s = "",
        [USB_GADGET_PRODUCT_IDX].s = PREFIX DRIVER_DESC,
        [USB_GADGET_SERIAL_IDX].s = "",
        {  } /* end of list */
@@ -333,15 +328,10 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
                        cpu_to_le16(0x0300 | 0x0099);
        }
 
-
        /* Allocate string descriptor numbers ... note that string
         * contents can be overridden by the composite_dev glue.
         */
 
-       /* device descriptor strings: manufacturer, product */
-       snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
-               init_utsname()->sysname, init_utsname()->release,
-               gadget->name);
        status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail;
index 16a8b1c15c626bf43dbfa5b2e7f294bf5ecf2385..77dbca099bcbd9e80c43ee58ae6fcfe7a57a234a 100644 (file)
@@ -10,7 +10,6 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/utsname.h>
 #include <linux/module.h>
 #include <linux/hid.h>
 #include <linux/cdev.h>
index 4f1142efa6d13888fc0bc3298ccc1d37775047c8..11150960d88b6a2e2a9622b7dd199f09c8e34dd1 100644 (file)
 #include <linux/spinlock.h>
 #include <linux/string.h>
 #include <linux/freezer.h>
-#include <linux/utsname.h>
 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
index 2f7e8f2930cc3367847ab68dc06ead22a2a6ab60..8ed1259fe80d0f91bff200abf9d7b6c11966af5a 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <linux/kernel.h>
 #include <linux/slab.h>
-#include <linux/utsname.h>
 #include <linux/device.h>
 
 #include <sound/core.h>
index eaaed199e453f191daf25362211e2f5333864038..9e62c20fb5bceb758eec14ec0d59243255826fdf 100644 (file)
@@ -13,7 +13,6 @@
 #define pr_fmt(fmt) "g_ffs: " fmt
 
 #include <linux/module.h>
-#include <linux/utsname.h>
 
 /*
  * kbuild is not very cooperative with respect to linking separately
index 2ee3a74056c98652e23f33a5667d95249d4ef17c..59621ef7657df9e4040acf9c59989cb57fd5d763 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <linux/kernel.h>
 #include <linux/slab.h>
-#include <linux/utsname.h>
 #include <linux/module.h>
 #include <linux/device.h>
 
index 16caf50e916dddbfc961347265fc865dd7d3cac8..0e2e357cc59e4db57db1fb51b99d0952423acd56 100644 (file)
@@ -91,10 +91,8 @@ static const struct usb_descriptor_header *otg_desc[] = {
 
 
 /* string IDs are assigned dynamically */
-static char manufacturer[50];
-
 static struct usb_string strings_dev[] = {
-       [USB_GADGET_MANUFACTURER_IDX].s = manufacturer,
+       [USB_GADGET_MANUFACTURER_IDX].s = "",
        [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
        [USB_GADGET_SERIAL_IDX].s = "",
        {  } /* end of list */
@@ -165,16 +163,10 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
        else
                device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);
 
-
        /* Allocate string descriptor numbers ... note that string
         * contents can be overridden by the composite_dev glue.
         */
 
-       /* device descriptor strings: manufacturer, product */
-       snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
-               init_utsname()->sysname, init_utsname()->release,
-               gadget->name);
-
        status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                return status;
index 50da3c88cb065850b6b58ea7b4eb6a85d908d1c9..9eb2be6858032ada47d4db6d399f25c62021e8ab 100644 (file)
 
 
 #include <linux/kernel.h>
-#include <linux/utsname.h>
 #include <linux/usb/ch9.h>
 
-
 /*-------------------------------------------------------------------------*/
 
 #define DRIVER_DESC            "Mass Storage Gadget"
index c158706b5ab09895e5a1ca53e2f148ff3b92c082..5bc5d96beaac5277dcf1b135c76c4190af5683b9 100644 (file)
 
 
 #include <linux/kernel.h>
-#include <linux/utsname.h>
 #include <linux/module.h>
 
-
 #if defined USB_ETH_RNDIS
 #  undef USB_ETH_RNDIS
 #endif
index 1a26452ce4ca96bad080e172bff1c69780768181..343f3d364ef8543c4f660ca4b3876cb0bbcb8d01 100644 (file)
@@ -20,8 +20,6 @@
 /* #define VERBOSE_DEBUG */
 
 #include <linux/kernel.h>
-#include <linux/utsname.h>
-
 
 #include "u_ether.h"
 
@@ -95,12 +93,9 @@ static const struct usb_descriptor_header *otg_desc[] = {
        NULL,
 };
 
-
 /* string IDs are assigned dynamically */
-static char manufacturer[50];
-
 static struct usb_string strings_dev[] = {
-       [USB_GADGET_MANUFACTURER_IDX].s = manufacturer,
+       [USB_GADGET_MANUFACTURER_IDX].s = "",
        [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
        [USB_GADGET_SERIAL_IDX].s = "",
        {  } /* end of list */
@@ -169,15 +164,10 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
                        cpu_to_le16(0x0300 | 0x0099);
        }
 
-
        /* Allocate string descriptor numbers ... note that string
         * contents can be overridden by the composite_dev glue.
         */
 
-       /* device descriptor strings: manufacturer, product */
-       snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
-               init_utsname()->sysname, init_utsname()->release,
-               gadget->name);
        status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail;
index 34b97f12b7da652af4bb09c30fbdd716b531f3d5..465766e41442507a7b476a580c66c433f5f2c94c 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/utsname.h>
 #include <linux/device.h>
 
 #include "u_serial.h"
index 3321a9df4862e18f229d4c408055ef680dc1b5e9..9bd994203d3d1f4b9f6cb9483f4f5db7d7d8ea65 100644 (file)
@@ -22,7 +22,6 @@
 #include <linux/timer.h>
 #include <linux/list.h>
 #include <linux/interrupt.h>
-#include <linux/utsname.h>
 #include <linux/device.h>
 #include <linux/moduleparam.h>
 #include <linux/fs.h>
@@ -237,7 +236,6 @@ static const struct usb_descriptor_header *otg_desc[] = {
 
 /* descriptors that are built on-demand */
 
-static char                            manufacturer [50];
 static char                            product_desc [40] = DRIVER_DESC;
 static char                            serial_num [40] = "1";
 static char                            pnp_string [1024] =
@@ -245,7 +243,7 @@ static char                         pnp_string [1024] =
 
 /* static strings, in UTF-8 */
 static struct usb_string               strings [] = {
-       [USB_GADGET_MANUFACTURER_IDX].s = manufacturer,
+       [USB_GADGET_MANUFACTURER_IDX].s = "",
        [USB_GADGET_PRODUCT_IDX].s = product_desc,
        [USB_GADGET_SERIAL_IDX].s =     serial_num,
        {  }            /* end of list */
@@ -1165,10 +1163,6 @@ static int __init printer_bind_config(struct usb_configuration *c)
                device_desc.bcdDevice =
                        cpu_to_le16(0xFFFF);
        }
-       snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s",
-               init_utsname()->sysname, init_utsname()->release,
-               gadget->name);
-
        if (iPNPstring)
                strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2);
 
index 768a38e896f7678885e5ed18ffffec94338a203f..bf12d55cd07b4492ee0c299093c73d15301f6ff7 100644 (file)
@@ -11,7 +11,6 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/utsname.h>
 #include <linux/device.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
@@ -61,10 +60,8 @@ USB_GADGET_COMPOSITE_OPTIONS();
 
 #define STRING_DESCRIPTION_IDX         USB_GADGET_FIRST_AVAIL_IDX
 
-static char manufacturer[50];
-
 static struct usb_string strings_dev[] = {
-       [USB_GADGET_MANUFACTURER_IDX].s = manufacturer,
+       [USB_GADGET_MANUFACTURER_IDX].s = "",
        [USB_GADGET_PRODUCT_IDX].s = GS_VERSION_NAME,
        [USB_GADGET_SERIAL_IDX].s = "",
        [STRING_DESCRIPTION_IDX].s = NULL /* updated; f(use_acm) */,
@@ -171,10 +168,6 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
         * contents can be overridden by the composite_dev glue.
         */
 
-       /* device description: manufacturer, product */
-       snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
-               init_utsname()->sysname, init_utsname()->release,
-               gadget->name);
        status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail;
index ee769c45498bc8bb34fa00b36f669409d5e0ea03..a837f3af2047b53bfee128d0ca074d544946133c 100644 (file)
@@ -42,7 +42,6 @@
 
 #include <linux/kernel.h>
 #include <linux/slab.h>
-#include <linux/utsname.h>
 #include <linux/device.h>
 
 #include "g_zero.h"
@@ -139,13 +138,11 @@ const struct usb_descriptor_header *otg_desc[] = {
 #endif
 
 /* string IDs are assigned dynamically */
-static char manufacturer[50];
-
 /* default serial number takes at least two packets */
 static char serial[] = "0123456789.0123456789.0123456789";
 
 static struct usb_string strings_dev[] = {
-       [USB_GADGET_MANUFACTURER_IDX].s = manufacturer,
+       [USB_GADGET_MANUFACTURER_IDX].s = "",
        [USB_GADGET_PRODUCT_IDX].s = longname,
        [USB_GADGET_SERIAL_IDX].s = serial,
        {  }                    /* end of list */
@@ -305,10 +302,6 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
 
        INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname);
 
-       snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
-               init_utsname()->sysname, init_utsname()->release,
-               gadget->name);
-
        return 0;
 }
 
index 60f8815998bd6377a58385a6c3d8418a6a5f3629..65ae0a3feb5be1e378b719c2ff52b83d1a9515cf 100644 (file)
@@ -358,7 +358,7 @@ struct usb_composite_dev {
        struct list_head                configs;
        struct usb_composite_driver     *driver;
        u8                              next_string_id;
-       u8                              manufacturer_override;
+       char                            *def_manufacturer;
 
        /* the gadget driver won't enable the data pullup
         * while the deactivation count is nonzero.