usb: gadget: use usb_string_ids_tab instead multiple usb_string_id()

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>
This commit is contained in:
Sebastian Andrzej Siewior 2012-09-06 20:11:16 +02:00 committed by Felipe Balbi
parent 72258493ec
commit e1f15ccbae
11 changed files with 45 additions and 136 deletions

View 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);

View 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)

View 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);

View 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()) {

View 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) {

View 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);

View 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);

View 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;

View 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 */

View 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,

View 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;
status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0)
return status;
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;
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);