aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/composite.c
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2012-09-10 09:01:58 -0400
committerFelipe Balbi <balbi@ti.com>2012-09-10 09:13:02 -0400
commitcc2683c318a5bf192b75cd5c343b51009db0cf6c (patch)
tree0ecbcd53bf42ab588208354fcabf7125d0d0a829 /drivers/usb/gadget/composite.c
parentd33f74fce3756d51a0203cec3d0d278e3b48d827 (diff)
usb: gadget: Provide a default implementation of default manufacturer 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>
Diffstat (limited to 'drivers/usb/gadget/composite.c')
-rw-r--r--drivers/usb/gadget/composite.c67
1 files changed, 22 insertions, 45 deletions
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index f3689e1bf4b2..c7066cd4c95a 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -28,9 +28,6 @@
28 * with the relevant device-wide data. 28 * with the relevant device-wide data.
29 */ 29 */
30 30
31static char composite_manufacturer[50];
32
33/*-------------------------------------------------------------------------*/
34/** 31/**
35 * next_ep_desc() - advance to the next EP descriptor 32 * next_ep_desc() - advance to the next EP descriptor
36 * @t: currect pointer within descriptor array 33 * @t: currect pointer within descriptor array
@@ -860,7 +857,6 @@ static int get_string(struct usb_composite_dev *cdev,
860 struct usb_configuration *c; 857 struct usb_configuration *c;
861 struct usb_function *f; 858 struct usb_function *f;
862 int len; 859 int len;
863 const char *str;
864 860
865 /* Yes, not only is USB's I18N support probably more than most 861 /* Yes, not only is USB's I18N support probably more than most
866 * folk will ever care about ... also, it's all supported here. 862 * folk will ever care about ... also, it's all supported here.
@@ -900,21 +896,6 @@ static int get_string(struct usb_composite_dev *cdev,
900 return s->bLength; 896 return s->bLength;
901 } 897 }
902 898
903 /* Otherwise, look up and return a specified string. First
904 * check if the string has not been overridden.
905 */
906 if (cdev->manufacturer_override == id)
907 str = composite_manufacturer;
908 else
909 str = NULL;
910 if (str) {
911 struct usb_gadget_strings strings = {
912 .language = language,
913 .strings = &(struct usb_string) { 0xff, str }
914 };
915 return usb_gadget_get_string(&strings, 0xff, buf);
916 }
917
918 /* String IDs are device-scoped, so we look up each string 899 /* String IDs are device-scoped, so we look up each string
919 * table we're told about. These lookups are infrequent; 900 * table we're told about. These lookups are infrequent;
920 * simpler-is-better here. 901 * simpler-is-better here.
@@ -1367,23 +1348,11 @@ composite_unbind(struct usb_gadget *gadget)
1367 usb_ep_free_request(gadget->ep0, cdev->req); 1348 usb_ep_free_request(gadget->ep0, cdev->req);
1368 } 1349 }
1369 device_remove_file(&gadget->dev, &dev_attr_suspended); 1350 device_remove_file(&gadget->dev, &dev_attr_suspended);
1351 kfree(cdev->def_manufacturer);
1370 kfree(cdev); 1352 kfree(cdev);
1371 set_gadget_data(gadget, NULL); 1353 set_gadget_data(gadget, NULL);
1372} 1354}
1373 1355
1374static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
1375{
1376 if (!*desc) {
1377 int ret = usb_string_id(cdev);
1378 if (unlikely(ret < 0))
1379 WARNING(cdev, "failed to override string ID\n");
1380 else
1381 *desc = ret;
1382 }
1383
1384 return *desc;
1385}
1386
1387static void update_unchanged_dev_desc(struct usb_device_descriptor *new, 1356static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
1388 const struct usb_device_descriptor *old) 1357 const struct usb_device_descriptor *old)
1389{ 1358{
@@ -1477,19 +1446,6 @@ static int composite_bind(struct usb_gadget *gadget,
1477 1446
1478 update_unchanged_dev_desc(&cdev->desc, composite->dev); 1447 update_unchanged_dev_desc(&cdev->desc, composite->dev);
1479 1448
1480 /* string overrides */
1481 if (!cdev->desc.iManufacturer) {
1482 snprintf(composite_manufacturer,
1483 sizeof composite_manufacturer,
1484 "%s %s with %s",
1485 init_utsname()->sysname,
1486 init_utsname()->release,
1487 gadget->name);
1488
1489 cdev->manufacturer_override =
1490 override_id(cdev, &cdev->desc.iManufacturer);
1491 }
1492
1493 /* has userspace failed to provide a serial number? */ 1449 /* has userspace failed to provide a serial number? */
1494 if (composite->needs_serial && !cdev->desc.iSerialNumber) 1450 if (composite->needs_serial && !cdev->desc.iSerialNumber)
1495 WARNING(cdev, "userspace failed to provide iSerialNumber\n"); 1451 WARNING(cdev, "userspace failed to provide iSerialNumber\n");
@@ -1665,6 +1621,22 @@ void usb_composite_setup_continue(struct usb_composite_dev *cdev)
1665 spin_unlock_irqrestore(&cdev->lock, flags); 1621 spin_unlock_irqrestore(&cdev->lock, flags);
1666} 1622}
1667 1623
1624static char *composite_default_mfr(struct usb_gadget *gadget)
1625{
1626 char *mfr;
1627 int len;
1628
1629 len = snprintf(NULL, 0, "%s %s with %s", init_utsname()->sysname,
1630 init_utsname()->release, gadget->name);
1631 len++;
1632 mfr = kmalloc(len, GFP_KERNEL);
1633 if (!mfr)
1634 return NULL;
1635 snprintf(mfr, len, "%s %s with %s", init_utsname()->sysname,
1636 init_utsname()->release, gadget->name);
1637 return mfr;
1638}
1639
1668void usb_composite_overwrite_options(struct usb_composite_dev *cdev, 1640void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
1669 struct usb_composite_overwrite *covr) 1641 struct usb_composite_overwrite *covr)
1670{ 1642{
@@ -1688,6 +1660,11 @@ void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
1688 if (covr->manufacturer) { 1660 if (covr->manufacturer) {
1689 desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id; 1661 desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id;
1690 dev_str[USB_GADGET_MANUFACTURER_IDX].s = covr->manufacturer; 1662 dev_str[USB_GADGET_MANUFACTURER_IDX].s = covr->manufacturer;
1663
1664 } else if (!strlen(dev_str[USB_GADGET_MANUFACTURER_IDX].s)) {
1665 desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id;
1666 cdev->def_manufacturer = composite_default_mfr(cdev->gadget);
1667 dev_str[USB_GADGET_MANUFACTURER_IDX].s = cdev->def_manufacturer;
1691 } 1668 }
1692 1669
1693 if (covr->product) { 1670 if (covr->product) {