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. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> --- drivers/usb/gadget/acm_ms.c | 12 +------ drivers/usb/gadget/audio.c | 9 +---- drivers/usb/gadget/cdc2.c | 10 +----- drivers/usb/gadget/composite.c | 67 ++++++++++++----------------------- drivers/usb/gadget/ether.c | 12 +------ drivers/usb/gadget/f_hid.c | 1 - drivers/usb/gadget/f_mass_storage.c | 1 - drivers/usb/gadget/f_midi.c | 1 - drivers/usb/gadget/g_ffs.c | 1 - drivers/usb/gadget/gmidi.c | 1 - drivers/usb/gadget/hid.c | 10 +----- drivers/usb/gadget/mass_storage.c | 2 -- drivers/usb/gadget/multi.c | 2 -- drivers/usb/gadget/ncm.c | 12 +------ drivers/usb/gadget/nokia.c | 1 - drivers/usb/gadget/printer.c | 8 +---- drivers/usb/gadget/serial.c | 9 +---- drivers/usb/gadget/zero.c | 9 +---- include/linux/usb/composite.h | 2 +- 19 files changed, 32 insertions(+), 138 deletions(-) diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c index 35db6aa..d280f16 100644 --- a/drivers/usb/gadget/acm_ms.c +++ b/drivers/usb/gadget/acm_ms.c @@ -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; diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c index 8857b6e..1f81e0f 100644 --- a/drivers/usb/gadget/audio.c +++ b/drivers/usb/gadget/audio.c @@ -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; diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c index 8966bde..4e2060b 100644 --- a/drivers/usb/gadget/cdc2.c +++ b/drivers/usb/gadget/cdc2.c @@ -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; diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index b477d9e..1f0e59c 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -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, cdriver->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 (cdriver->needs_serial && !cdev->desc.iSerialNumber) WARNING(cdev, "userspace failed to provide iSerialNumber\n"); @@ -1672,6 +1628,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) { @@ -1695,6 +1667,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) { diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index dd5e00d..a5c2720 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -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; diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c index 16a8b1c..77dbca0 100644 --- a/drivers/usb/gadget/f_hid.c +++ b/drivers/usb/gadget/f_hid.c @@ -10,7 +10,6 @@ */ #include <linux/kernel.h> -#include <linux/utsname.h> #include <linux/module.h> #include <linux/hid.h> #include <linux/cdev.h> diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 4f1142e..1115096 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -213,7 +213,6 @@ #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> diff --git a/drivers/usb/gadget/f_midi.c b/drivers/usb/gadget/f_midi.c index 2f7e8f2..8ed1259 100644 --- a/drivers/usb/gadget/f_midi.c +++ b/drivers/usb/gadget/f_midi.c @@ -21,7 +21,6 @@ #include <linux/kernel.h> #include <linux/slab.h> -#include <linux/utsname.h> #include <linux/device.h> #include <sound/core.h> diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index 83a2f7d..f2ba786 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c @@ -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 diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index 2ee3a74..59621ef 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c @@ -22,7 +22,6 @@ #include <linux/kernel.h> #include <linux/slab.h> -#include <linux/utsname.h> #include <linux/module.h> #include <linux/device.h> diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c index 16caf50..0e2e357 100644 --- a/drivers/usb/gadget/hid.c +++ b/drivers/usb/gadget/hid.c @@ -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; diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c index c8a83fa..7d4d2cf 100644 --- a/drivers/usb/gadget/mass_storage.c +++ b/drivers/usb/gadget/mass_storage.c @@ -29,10 +29,8 @@ #include <linux/kernel.h> -#include <linux/utsname.h> #include <linux/usb/ch9.h> - /*-------------------------------------------------------------------------*/ #define DRIVER_DESC "Mass Storage Gadget" diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index 3f4c235..0e056cb 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c @@ -14,10 +14,8 @@ #include <linux/kernel.h> -#include <linux/utsname.h> #include <linux/module.h> - #if defined USB_ETH_RNDIS # undef USB_ETH_RNDIS #endif diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c index 1a26452..343f3d3 100644 --- a/drivers/usb/gadget/ncm.c +++ b/drivers/usb/gadget/ncm.c @@ -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; diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c index 34b97f1..465766e 100644 --- a/drivers/usb/gadget/nokia.c +++ b/drivers/usb/gadget/nokia.c @@ -16,7 +16,6 @@ */ #include <linux/kernel.h> -#include <linux/utsname.h> #include <linux/device.h> #include "u_serial.h" diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index 3321a9d..9bd9942 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c @@ -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); diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index 768a38e..bf12d55 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c @@ -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; diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index ee769c4..a837f3a 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c @@ -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; } diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index 60f8815..65ae0a3 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h @@ -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. -- 1.7.10.4 Sebastian -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html