A few gadgets provide a harcoded string in case the module parameter was not used. If nothing is provided then composite_bind() creates a string which is based on the kernel version and UDC's name. Some gadget create the exact same sting. This patch moves the creation of the string into composite_default_mfr(). Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> --- drivers/usb/gadget/acm_ms.c | 17 +++++++---------- drivers/usb/gadget/audio.c | 14 ++++++-------- drivers/usb/gadget/cdc2.c | 15 ++++++--------- drivers/usb/gadget/composite.c | 22 ++++++++++++++++++++++ drivers/usb/gadget/ether.c | 16 ++++++---------- 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 | 12 +++++++----- drivers/usb/gadget/gmidi.c | 1 - drivers/usb/gadget/hid.c | 15 ++++++--------- drivers/usb/gadget/mass_storage.c | 17 ++++++++++++----- drivers/usb/gadget/multi.c | 12 +++++++----- drivers/usb/gadget/ncm.c | 16 ++++++---------- drivers/usb/gadget/nokia.c | 1 - drivers/usb/gadget/printer.c | 14 ++++++-------- drivers/usb/gadget/serial.c | 21 ++++++++++++--------- drivers/usb/gadget/zero.c | 15 ++++++--------- 18 files changed, 109 insertions(+), 102 deletions(-) diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c index 51fc568..6986d4c 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" @@ -93,10 +92,8 @@ static const struct usb_descriptor_header *otg_desc[] = { #define STRING_PRODUCT_IDX 1 #define STRING_PRODUCT_SERIAL 2 -static char manufacturer[50]; - static struct usb_string strings_dev[] = { - [STRING_MANUFACTURER_IDX].s = manufacturer, + [STRING_MANUFACTURER_IDX].s = "", [STRING_PRODUCT_IDX].s = DRIVER_DESC, [STRING_PRODUCT_SERIAL].s = "", { } /* end of list */ @@ -190,10 +187,6 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev) * 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; @@ -212,7 +205,10 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev) strings_dev[STRING_PRODUCT_SERIAL].id; } if (iManufacturer) - strings_dev[STRING_MANUFACTURER_IDX].s = iManufacturer; + strings_dev[STRING_MANUFACTURER_IDX].s = iManufacturer; + else + strings_dev[STRING_MANUFACTURER_IDX].s = + composite_default_mfr(gadget); dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC); @@ -230,7 +226,8 @@ fail0: static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) { gserial_cleanup(); - + if (!iManufacturer) + kfree(strings_dev[STRING_MANUFACTURER_IDX].s); return 0; } diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c index d598e32..f9b6a82 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" @@ -37,10 +36,8 @@ USB_GADGET_COMPOSITE_OPTIONS(); #define STRING_PRODUCT_IDX 1 #define STRING_PRODUCT_SERIAL 2 -static char manufacturer[50]; - static struct usb_string strings_dev[] = { - [STRING_MANUFACTURER_IDX].s = manufacturer, + [STRING_MANUFACTURER_IDX].s = "", [STRING_PRODUCT_IDX].s = DRIVER_DESC, [STRING_PRODUCT_SERIAL].s = "", { } /* end of list */ @@ -164,10 +161,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; @@ -185,6 +178,9 @@ static int __init audio_bind(struct usb_composite_dev *cdev) } if (iManufacturer) strings_dev[STRING_MANUFACTURER_IDX].s = iManufacturer; + else + strings_dev[STRING_MANUFACTURER_IDX].s = + composite_default_mfr(cdev->gadget); INFO(cdev, "%s, version: %s\n", DRIVER_DESC, DRIVER_VERSION); return 0; @@ -198,6 +194,8 @@ static int __exit audio_unbind(struct usb_composite_dev *cdev) #ifdef CONFIG_GADGET_UAC1 gaudio_cleanup(); #endif + if (!iManufacturer) + kfree(strings_dev[STRING_MANUFACTURER_IDX].s); return 0; } diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c index 390a7e4..708f17c 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" @@ -94,10 +93,8 @@ static const struct usb_descriptor_header *otg_desc[] = { #define STRING_PRODUCT_IDX 1 #define STRING_PRODUCT_SERIAL 2 -static char manufacturer[50]; - static struct usb_string strings_dev[] = { - [STRING_MANUFACTURER_IDX].s = manufacturer, + [STRING_MANUFACTURER_IDX].s = "", [STRING_PRODUCT_IDX].s = DRIVER_DESC, [STRING_PRODUCT_SERIAL].s = "", { } /* end of list */ @@ -190,11 +187,6 @@ static int __init cdc_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; @@ -212,6 +204,9 @@ static int __init cdc_bind(struct usb_composite_dev *cdev) } if (iManufacturer) strings_dev[STRING_MANUFACTURER_IDX].s = iManufacturer; + else + strings_dev[STRING_MANUFACTURER_IDX].s = + composite_default_mfr(gadget); USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", @@ -230,6 +225,8 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev) { gserial_cleanup(); gether_cleanup(); + if (!iManufacturer) + kfree(strings_dev[STRING_MANUFACTURER_IDX].s); return 0; } diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index a89f95d..9c09cf6 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1494,6 +1494,28 @@ fail: return status; } +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); + if (len < 0) + return NULL; + len = min(32, len + 1); + mfr = kmalloc(len, GFP_KERNEL); + if (!mfr) + return NULL; + len = snprintf(mfr, len, "%s %s with %s", init_utsname()->sysname, + init_utsname()->release, gadget->name); + if (len < 0) { + kfree(mfr); + return NULL; + } + return mfr; +} + /*-------------------------------------------------------------------------*/ static void diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index fc7ad19..513c309 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 @@ -199,10 +197,8 @@ static const struct usb_descriptor_header *otg_desc[] = { #define STRING_PRODUCT_IDX 1 #define STRING_PRODUCT_SERIAL 2 -static char manufacturer[50]; - static struct usb_string strings_dev[] = { - [STRING_MANUFACTURER_IDX].s = manufacturer, + [STRING_MANUFACTURER_IDX].s = "", [STRING_PRODUCT_IDX].s = PREFIX DRIVER_DESC, [STRING_PRODUCT_SERIAL].s = "", { } /* end of list */ @@ -342,11 +338,6 @@ static int __init eth_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 fail; @@ -373,6 +364,9 @@ static int __init eth_bind(struct usb_composite_dev *cdev) } if (iManufacturer) strings_dev[STRING_MANUFACTURER_IDX].s = iManufacturer; + else + strings_dev[STRING_MANUFACTURER_IDX].s = + composite_default_mfr(gadget); dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC); @@ -387,6 +381,8 @@ fail: static int __exit eth_unbind(struct usb_composite_dev *cdev) { gether_cleanup(); + if (!iManufacturer) + kfree(strings_dev[STRING_MANUFACTURER_IDX].s); return 0; } 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 b8a23fb..0960987 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 @@ -402,11 +401,12 @@ static int gfs_bind(struct usb_composite_dev *cdev) gfs_strings[GFFS_SERIAL_IDX].s = iSerialNumber; gfs_dev_desc.iSerialNumber = gfs_strings[GFFS_SERIAL_IDX].id; } - if (iManufacturer) { + gfs_dev_desc.iManufacturer = gfs_strings[GFFS_MFR_IDX].id; + if (iManufacturer) gfs_strings[GFFS_MFR_IDX].s = iManufacturer; - gfs_dev_desc.iManufacturer = gfs_strings[GFFS_MFR_IDX].id; - } - + else + gfs_strings[GFFS_MFR_IDX].s = + composite_default_mfr(cdev->gadget); return 0; error_unbind: @@ -444,6 +444,8 @@ static int gfs_unbind(struct usb_composite_dev *cdev) if (ffs_tab[i].ffs_data) functionfs_unbind(ffs_tab[i].ffs_data); + if (!iManufacturer) + kfree(gfs_strings[GFFS_MFR_IDX].s); return 0; } diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index e5e9ea3..1417262 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 5c81c3f..2a6f278 100644 --- a/drivers/usb/gadget/hid.c +++ b/drivers/usb/gadget/hid.c @@ -95,10 +95,8 @@ static const struct usb_descriptor_header *otg_desc[] = { #define STRING_PRODUCT_IDX 1 #define STRING_PRODUCT_SERIAL 2 -static char manufacturer[50]; - static struct usb_string strings_dev[] = { - [STRING_MANUFACTURER_IDX].s = manufacturer, + [STRING_MANUFACTURER_IDX].s = "", [STRING_PRODUCT_IDX].s = DRIVER_DESC, [STRING_PRODUCT_SERIAL].s = "", { } /* end of list */ @@ -173,12 +171,6 @@ static int __init hid_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) return status; @@ -198,6 +190,9 @@ static int __init hid_bind(struct usb_composite_dev *cdev) } if (iManufacturer) strings_dev[STRING_MANUFACTURER_IDX].s = iManufacturer; + else + strings_dev[STRING_MANUFACTURER_IDX].s = + composite_default_mfr(gadget); dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); @@ -207,6 +202,8 @@ static int __init hid_bind(struct usb_composite_dev *cdev) static int __exit hid_unbind(struct usb_composite_dev *cdev) { ghid_cleanup(); + if (!iManufacturer) + kfree(strings_dev[STRING_MANUFACTURER_IDX].s); return 0; } diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c index 6d586fe..bc5bd95 100644 --- a/drivers/usb/gadget/mass_storage.c +++ b/drivers/usb/gadget/mass_storage.c @@ -29,7 +29,6 @@ #include <linux/kernel.h> -#include <linux/utsname.h> #include <linux/usb/ch9.h> @@ -171,11 +170,12 @@ static int __init msg_bind(struct usb_composite_dev *cdev) msg_device_desc.iSerialNumber = strings_dev[STRING_PRODUCT_SERIAL].id; } - if (iManufacturer) { + msg_device_desc.iManufacturer = strings_dev[STRING_PRODUCT_MFR].id; + if (iManufacturer) strings_dev[STRING_PRODUCT_MFR].s = iManufacturer; - msg_device_desc.iManufacturer = - strings_dev[STRING_PRODUCT_MFR].id; - } + else + strings_dev[STRING_PRODUCT_MFR].s = + composite_default_mfr(cdev->gadget); dev_info(&cdev->gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); @@ -183,6 +183,12 @@ static int __init msg_bind(struct usb_composite_dev *cdev) return 0; } +static int msg_unbind(struct usb_composite_dev *cdev) +{ + if (!iManufacturer) + kfree(strings_dev[STRING_PRODUCT_MFR].s); + return 0; +} /****************************** Some noise ******************************/ @@ -194,6 +200,7 @@ static __refdata struct usb_composite_driver msg_driver = { .needs_serial = 1, .strings = dev_strings, .bind = msg_bind, + .unbind = msg_unbind, }; MODULE_DESCRIPTION(DRIVER_DESC); diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index d77fdc5..952fc1b 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c @@ -14,7 +14,6 @@ #include <linux/kernel.h> -#include <linux/utsname.h> #include <linux/module.h> @@ -317,11 +316,12 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) device_desc.iSerialNumber = strings_dev[MULTI_STRING_SERIAL_IDX].id; } - if (iManufacturer) { + device_desc.iManufacturer = strings_dev[MULTI_STRING_MFR_IDX].id; + if (iManufacturer) strings_dev[MULTI_STRING_MFR_IDX].s = iManufacturer; - device_desc.iManufacturer = - strings_dev[MULTI_STRING_MFR_IDX].id; - } + else + strings_dev[MULTI_STRING_MFR_IDX].s = + composite_default_mfr(gadget); /* we're done */ dev_info(&gadget->dev, DRIVER_DESC "\n"); @@ -343,6 +343,8 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev) { gserial_cleanup(); gether_cleanup(); + if (!iManufacturer) + kfree(strings_dev[MULTI_STRING_MFR_IDX].s); return 0; } diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c index c1dca2c..6f8c270 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" @@ -102,10 +100,8 @@ static const struct usb_descriptor_header *otg_desc[] = { #define STRING_PRODUCT_IDX 1 #define STRING_SERIAL_IDX 2 -static char manufacturer[50]; - static struct usb_string strings_dev[] = { - [STRING_MANUFACTURER_IDX].s = manufacturer, + [STRING_MANUFACTURER_IDX].s = "", [STRING_PRODUCT_IDX].s = DRIVER_DESC, [STRING_SERIAL_IDX].s = "", { } /* end of list */ @@ -178,11 +174,6 @@ static int __init gncm_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 fail; @@ -202,6 +193,9 @@ static int __init gncm_bind(struct usb_composite_dev *cdev) } if (iManufacturer) strings_dev[STRING_MANUFACTURER_IDX].s = iManufacturer; + else + strings_dev[STRING_MANUFACTURER_IDX].s = + composite_default_mfr(gadget); dev_info(&gadget->dev, "%s\n", DRIVER_DESC); @@ -215,6 +209,8 @@ fail: static int __exit gncm_unbind(struct usb_composite_dev *cdev) { gether_cleanup(); + if (!iManufacturer) + kfree(strings_dev[STRING_MANUFACTURER_IDX].s); return 0; } diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c index 1c8d67b..e382b52 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 c620123..0f63c08 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> @@ -241,7 +240,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] = @@ -249,7 +247,7 @@ static char pnp_string [1024] = /* static strings, in UTF-8 */ static struct usb_string strings [] = { - [STRING_MANUFACTURER].s = manufacturer, + [STRING_MANUFACTURER].s = "", [STRING_PRODUCT].s = product_desc, [STRING_SERIALNUM].s = serial_num, { } /* end of list */ @@ -1169,10 +1167,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); @@ -1247,6 +1241,8 @@ fail: static int printer_unbind(struct usb_composite_dev *cdev) { + if (!iManufacturer) + kfree(strings[STRING_MANUFACTURER].s); return 0; } @@ -1269,7 +1265,9 @@ static int __init printer_bind(struct usb_composite_dev *cdev) strings[STRING_SERIALNUM].s = iSerialNumber; if (iManufacturer) strings[STRING_MANUFACTURER].s = iManufacturer; - + else + strings[STRING_MANUFACTURER].s = + composite_default_mfr(cdev->gadget); return 0; } diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index 31da904..8bffcd6 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> @@ -64,10 +63,8 @@ USB_GADGET_COMPOSITE_OPTIONS(); #define STRING_DESCRIPTION_IDX 2 #define STRING_SERIAL_IDX 3 -static char manufacturer[50]; - static struct usb_string strings_dev[] = { - [STRING_MANUFACTURER_IDX].s = manufacturer, + [STRING_MANUFACTURER_IDX].s = "", [STRING_PRODUCT_IDX].s = GS_VERSION_NAME, [STRING_DESCRIPTION_IDX].s = NULL /* updated; f(use_acm) */, [STRING_SERIAL_IDX].s = "", @@ -173,11 +170,6 @@ static int __init gs_bind(struct usb_composite_dev *cdev) /* Allocate string descriptor numbers ... note that string * 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; @@ -222,6 +214,9 @@ static int __init gs_bind(struct usb_composite_dev *cdev) } if (iManufacturer) strings_dev[STRING_MANUFACTURER_IDX].s = iManufacturer; + else + strings_dev[STRING_MANUFACTURER_IDX].s = + composite_default_mfr(gadget); INFO(cdev, "%s\n", GS_VERSION_NAME); @@ -232,12 +227,20 @@ fail: return status; } +static int gs_unbind(struct usb_composite_dev *cdev) +{ + if (!iManufacturer) + kfree(strings_dev[STRING_MANUFACTURER_IDX].s); + return 0; +} + static __refdata struct usb_composite_driver gserial_driver = { .name = "g_serial", .dev = &device_desc, .strings = dev_strings, .max_speed = USB_SPEED_SUPER, .bind = gs_bind, + .unbind = gs_unbind, }; static int __init init(void) diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index b38c141..9679d53 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" @@ -144,13 +143,11 @@ const struct usb_descriptor_header *otg_desc[] = { #define STRING_PRODUCT_IDX 1 #define STRING_SERIAL_IDX 2 -static char manufacturer[50]; - /* default serial number takes at least two packets */ static char serial[] = "0123456789.0123456789.0123456789"; static struct usb_string strings_dev[] = { - [STRING_MANUFACTURER_IDX].s = manufacturer, + [STRING_MANUFACTURER_IDX].s = "", [STRING_PRODUCT_IDX].s = longname, [STRING_SERIAL_IDX].s = serial, { } /* end of list */ @@ -311,18 +308,18 @@ static int __init zero_bind(struct usb_composite_dev *cdev) strings_dev[STRING_SERIAL_IDX].s = iSerialNumber; if (iManufacturer) strings_dev[STRING_MANUFACTURER_IDX].s = iManufacturer; + else + strings_dev[STRING_MANUFACTURER_IDX].s = + composite_default_mfr(gadget); 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; } static int zero_unbind(struct usb_composite_dev *cdev) { + if (!iManufacturer) + kfree(strings_dev[STRING_MANUFACTURER_IDX].s); del_timer_sync(&autoresume_timer); return 0; } -- 1.7.10.4 -- 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