usb: gadget: use usb_string_ids_tab instead multiple usb_string_id()
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Thu, 6 Sep 2012 18:11:16 +0000 (20:11 +0200)
committerFelipe Balbi <balbi@ti.com>
Mon, 10 Sep 2012 13:06:48 +0000 (16:06 +0300)
Using usb_string_ids_tab() instead multiple calls of usb_string_id()
seems to be handy. It also allows to add string without many checks.

Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/acm_ms.c
drivers/usb/gadget/audio.c
drivers/usb/gadget/cdc2.c
drivers/usb/gadget/ether.c
drivers/usb/gadget/gmidi.c
drivers/usb/gadget/hid.c
drivers/usb/gadget/ncm.c
drivers/usb/gadget/nokia.c
drivers/usb/gadget/serial.c
drivers/usb/gadget/webcam.c
drivers/usb/gadget/zero.c

index 5db661d8590b00e435f689a3b2e4e597d4fe2eb8..ea349bab7f15b45d49c0def74bebcdcb8d39ccc4 100644 (file)
@@ -192,17 +192,11 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
        snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
                init_utsname()->sysname, init_utsname()->release,
                gadget->name);
-       status = usb_string_id(cdev);
+       status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail1;
-       strings_dev[STRING_MANUFACTURER_IDX].id = status;
-       device_desc.iManufacturer = status;
-
-       status = usb_string_id(cdev);
-       if (status < 0)
-               goto fail1;
-       strings_dev[STRING_PRODUCT_IDX].id = status;
-       device_desc.iProduct = status;
+       device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
+       device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
 
        /* register our configuration */
        status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config);
index 689d1422a1c00b6b53310a2825d6800a246c9f50..5702ce3777fbadfc4d7d363301e8b2d588b53fe4 100644 (file)
@@ -165,17 +165,11 @@ static int __init audio_bind(struct usb_composite_dev *cdev)
        snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
                init_utsname()->sysname, init_utsname()->release,
                cdev->gadget->name);
-       status = usb_string_id(cdev);
+       status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail;
-       strings_dev[STRING_MANUFACTURER_IDX].id = status;
-       device_desc.iManufacturer = status;
-
-       status = usb_string_id(cdev);
-       if (status < 0)
-               goto fail;
-       strings_dev[STRING_PRODUCT_IDX].id = status;
-       device_desc.iProduct = status;
+       device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
+       device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
 
        status = usb_add_config(cdev, &audio_config_driver, audio_do_config);
        if (status < 0)
index 8e386cf377a5139c1dc350b5eb6d3ab8aed1e066..3b89fe2bd0b834cb56ced8250b9a70eb056bf1ff 100644 (file)
@@ -193,17 +193,11 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
        snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
                init_utsname()->sysname, init_utsname()->release,
                gadget->name);
-       status = usb_string_id(cdev);
+       status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail1;
-       strings_dev[STRING_MANUFACTURER_IDX].id = status;
-       device_desc.iManufacturer = status;
-
-       status = usb_string_id(cdev);
-       if (status < 0)
-               goto fail1;
-       strings_dev[STRING_PRODUCT_IDX].id = status;
-       device_desc.iProduct = status;
+       device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
+       device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
 
        /* register our configuration */
        status = usb_add_config(cdev, &cdc_config_driver, cdc_do_config);
index 39eb718f796ad9e3d12729a46ba7d222710b5fc5..004c6ed79e3b8c47b592b8f75476e559b1e3557f 100644 (file)
@@ -345,17 +345,11 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
        snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
                init_utsname()->sysname, init_utsname()->release,
                gadget->name);
-       status = usb_string_id(cdev);
+       status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail;
-       strings_dev[STRING_MANUFACTURER_IDX].id = status;
-       device_desc.iManufacturer = status;
-
-       status = usb_string_id(cdev);
-       if (status < 0)
-               goto fail;
-       strings_dev[STRING_PRODUCT_IDX].id = status;
-       device_desc.iProduct = status;
+       device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
+       device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
 
        /* register our configuration(s); RNDIS first, if it's used */
        if (has_rndis()) {
index 0c70708ef80f807d21581b4fa346cfec323a0873..68f8c032ba6b253fd5a569ab7271c4c48e4800b7 100644 (file)
@@ -140,25 +140,12 @@ static int __init midi_bind(struct usb_composite_dev *cdev)
        struct usb_gadget *gadget = cdev->gadget;
        int gcnum, status;
 
-       status = usb_string_id(cdev);
+       status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                return status;
-       strings_dev[STRING_MANUFACTURER_IDX].id = status;
-       device_desc.iManufacturer = status;
-
-       status = usb_string_id(cdev);
-       if (status < 0)
-               return status;
-       strings_dev[STRING_PRODUCT_IDX].id = status;
-       device_desc.iProduct = status;
-
-       /* config description */
-       status = usb_string_id(cdev);
-       if (status < 0)
-               return status;
-       strings_dev[STRING_DESCRIPTION_IDX].id = status;
-
-       midi_config.iConfiguration = status;
+       device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
+       device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
+       midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id;
 
        gcnum = usb_gadget_controller_number(gadget);
        if (gcnum < 0) {
index 4880cdd9de43c3030150e174292171c0651192d6..1e3f03be94dfa06e4206a4fe9271e39c4a51a063 100644 (file)
@@ -176,17 +176,12 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
        snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
                init_utsname()->sysname, init_utsname()->release,
                gadget->name);
-       status = usb_string_id(cdev);
-       if (status < 0)
-               return status;
-       strings_dev[STRING_MANUFACTURER_IDX].id = status;
-       device_desc.iManufacturer = status;
 
-       status = usb_string_id(cdev);
+       status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                return status;
-       strings_dev[STRING_PRODUCT_IDX].id = status;
-       device_desc.iProduct = status;
+       device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
+       device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
 
        /* register our configuration */
        status = usb_add_config(cdev, &config_driver, do_config);
index 69b660b79c091c0b7b25b77d37f4f8b51d3af3d2..6c7e159845353565b5a90e141943abb5cf942481 100644 (file)
@@ -180,17 +180,11 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
        snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
                init_utsname()->sysname, init_utsname()->release,
                gadget->name);
-       status = usb_string_id(cdev);
+       status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail;
-       strings_dev[STRING_MANUFACTURER_IDX].id = status;
-       device_desc.iManufacturer = status;
-
-       status = usb_string_id(cdev);
-       if (status < 0)
-               goto fail;
-       strings_dev[STRING_PRODUCT_IDX].id = status;
-       device_desc.iProduct = status;
+       device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
+       device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
 
        status = usb_add_config(cdev, &ncm_config_driver,
                                ncm_do_config);
index 6834c6204df3e03715336089be3303c60fd49663..b0893136a05db011c71108ab954a7f7b100756bf 100644 (file)
@@ -164,26 +164,12 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
        if (status < 0)
                goto err_ether;
 
-       status = usb_string_id(cdev);
+       status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto err_usb;
-       strings_dev[STRING_MANUFACTURER_IDX].id = status;
-
-       device_desc.iManufacturer = status;
-
-       status = usb_string_id(cdev);
-       if (status < 0)
-               goto err_usb;
-       strings_dev[STRING_PRODUCT_IDX].id = status;
-
-       device_desc.iProduct = status;
-
-       /* config description */
-       status = usb_string_id(cdev);
-       if (status < 0)
-               goto err_usb;
-       strings_dev[STRING_DESCRIPTION_IDX].id = status;
-
+       device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
+       device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
+       status = strings_dev[STRING_DESCRIPTION_IDX].id;
        nokia_config_500ma_driver.iConfiguration = status;
        nokia_config_100ma_driver.iConfiguration = status;
 
index 098c3d03deddac44945ff7d47044c27b84b12dd0..9962504e14f1148e095093448bcd43f649bcd08f 100644 (file)
@@ -175,26 +175,12 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
        snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
                init_utsname()->sysname, init_utsname()->release,
                gadget->name);
-       status = usb_string_id(cdev);
+       status = usb_string_ids_tab(cdev, strings_dev);
        if (status < 0)
                goto fail;
-       strings_dev[STRING_MANUFACTURER_IDX].id = status;
-
-       device_desc.iManufacturer = status;
-
-       status = usb_string_id(cdev);
-       if (status < 0)
-               goto fail;
-       strings_dev[STRING_PRODUCT_IDX].id = status;
-
-       device_desc.iProduct = status;
-
-       /* config description */
-       status = usb_string_id(cdev);
-       if (status < 0)
-               goto fail;
-       strings_dev[STRING_DESCRIPTION_IDX].id = status;
-
+       device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
+       device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
+       status = strings_dev[STRING_DESCRIPTION_IDX].id;
        serial_config_driver.iConfiguration = status;
 
        /* set up other descriptors */
index 66dfca86b21593059c2570eda95d9ffa5516b6fa..d44a4510a65ada2529816beb6a297645a1799fdf 100644 (file)
@@ -355,20 +355,15 @@ webcam_bind(struct usb_composite_dev *cdev)
        /* Allocate string descriptor numbers ... note that string contents
         * can be overridden by the composite_dev glue.
         */
-       if ((ret = usb_string_id(cdev)) < 0)
+       ret = usb_string_ids_tab(cdev, webcam_strings);
+       if (ret < 0)
                goto error;
-       webcam_strings[STRING_MANUFACTURER_IDX].id = ret;
-       webcam_device_descriptor.iManufacturer = ret;
-
-       if ((ret = usb_string_id(cdev)) < 0)
-               goto error;
-       webcam_strings[STRING_PRODUCT_IDX].id = ret;
-       webcam_device_descriptor.iProduct = ret;
-
-       if ((ret = usb_string_id(cdev)) < 0)
-               goto error;
-       webcam_strings[STRING_DESCRIPTION_IDX].id = ret;
-       webcam_config_driver.iConfiguration = ret;
+       webcam_device_descriptor.iManufacturer =
+               webcam_strings[STRING_MANUFACTURER_IDX].id;
+       webcam_device_descriptor.iProduct =
+               webcam_strings[STRING_PRODUCT_IDX].id;
+       webcam_config_driver.iConfiguration =
+               webcam_strings[STRING_DESCRIPTION_IDX].id;
 
        /* Register our configuration. */
        if ((ret = usb_add_config(cdev, &webcam_config_driver,
index 9a9adee2911a8a33ffda23983d8e0861e5a8ca29..dbc336e3ba981fc20ff69041e237e2187d6fb2d2 100644 (file)
@@ -264,28 +264,18 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
 {
        int                     gcnum;
        struct usb_gadget       *gadget = cdev->gadget;
-       int                     id;
+       int                     status;
 
        /* Allocate string descriptor numbers ... note that string
         * contents can be overridden by the composite_dev glue.
         */
-       id = usb_string_id(cdev);
-       if (id < 0)
-               return id;
-       strings_dev[STRING_MANUFACTURER_IDX].id = id;
-       device_desc.iManufacturer = id;
-
-       id = usb_string_id(cdev);
-       if (id < 0)
-               return id;
-       strings_dev[STRING_PRODUCT_IDX].id = id;
-       device_desc.iProduct = id;
-
-       id = usb_string_id(cdev);
-       if (id < 0)
-               return id;
-       strings_dev[STRING_SERIAL_IDX].id = id;
-       device_desc.iSerialNumber = id;
+       status = usb_string_ids_tab(cdev, strings_dev);
+       if (status < 0)
+               return status;
+
+       device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
+       device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
+       device_desc.iSerialNumber = strings_dev[STRING_SERIAL_IDX].id;
 
        setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);