Skip to content

Commit

Permalink
usb: gadget: Provide a default implementation of default manufacturer…
Browse files Browse the repository at this point in the history
… string

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>
  • Loading branch information
Sebastian Andrzej Siewior authored and Felipe Balbi committed Sep 10, 2012
1 parent d33f74f commit cc2683c
Show file tree
Hide file tree
Showing 19 changed files with 32 additions and 138 deletions.
12 changes: 1 addition & 11 deletions drivers/usb/gadget/acm_ms.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include <linux/kernel.h>
#include <linux/utsname.h>

#include "u_serial.h"

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 1 addition & 8 deletions drivers/usb/gadget/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/* #define VERBOSE_DEBUG */

#include <linux/kernel.h>
#include <linux/utsname.h>
#include <linux/usb/composite.h>

#include "gadget_chips.h"
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 1 addition & 9 deletions drivers/usb/gadget/cdc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/

#include <linux/kernel.h>
#include <linux/utsname.h>
#include <linux/module.h>

#include "u_ether.h"
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
67 changes: 22 additions & 45 deletions drivers/usb/gadget/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
{
Expand All @@ -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) {
Expand Down
12 changes: 1 addition & 11 deletions drivers/usb/gadget/ether.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
/* #define VERBOSE_DEBUG */

#include <linux/kernel.h>
#include <linux/utsname.h>


#if defined USB_ETH_RNDIS
# undef USB_ETH_RNDIS
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion drivers/usb/gadget/f_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

#include <linux/kernel.h>
#include <linux/utsname.h>
#include <linux/module.h>
#include <linux/hid.h>
#include <linux/cdev.h>
Expand Down
1 change: 0 additions & 1 deletion drivers/usb/gadget/f_mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion drivers/usb/gadget/f_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/utsname.h>
#include <linux/device.h>

#include <sound/core.h>
Expand Down
1 change: 0 additions & 1 deletion drivers/usb/gadget/g_ffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion drivers/usb/gadget/gmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/utsname.h>
#include <linux/module.h>
#include <linux/device.h>

Expand Down
10 changes: 1 addition & 9 deletions drivers/usb/gadget/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions drivers/usb/gadget/mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@


#include <linux/kernel.h>
#include <linux/utsname.h>
#include <linux/usb/ch9.h>


/*-------------------------------------------------------------------------*/

#define DRIVER_DESC "Mass Storage Gadget"
Expand Down
2 changes: 0 additions & 2 deletions drivers/usb/gadget/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions drivers/usb/gadget/ncm.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
/* #define VERBOSE_DEBUG */

#include <linux/kernel.h>
#include <linux/utsname.h>


#include "u_ether.h"

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion drivers/usb/gadget/nokia.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

#include <linux/kernel.h>
#include <linux/utsname.h>
#include <linux/device.h>

#include "u_serial.h"
Expand Down
Loading

0 comments on commit cc2683c

Please sign in to comment.