提交 e1f15ccb 编写于 作者: S Sebastian Andrzej Siewior 提交者: Felipe Balbi

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: NMichal Nazarewicz <mina86@mina86.com>
Signed-off-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: NFelipe Balbi <balbi@ti.com>
上级 72258493
...@@ -192,17 +192,11 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev) ...@@ -192,17 +192,11 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
init_utsname()->sysname, init_utsname()->release, init_utsname()->sysname, init_utsname()->release,
gadget->name); gadget->name);
status = usb_string_id(cdev); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
goto fail1; goto fail1;
strings_dev[STRING_MANUFACTURER_IDX].id = status; device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
device_desc.iManufacturer = status; device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
status = usb_string_id(cdev);
if (status < 0)
goto fail1;
strings_dev[STRING_PRODUCT_IDX].id = status;
device_desc.iProduct = status;
/* register our configuration */ /* register our configuration */
status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config); status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config);
......
...@@ -165,17 +165,11 @@ static int __init audio_bind(struct usb_composite_dev *cdev) ...@@ -165,17 +165,11 @@ static int __init audio_bind(struct usb_composite_dev *cdev)
snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
init_utsname()->sysname, init_utsname()->release, init_utsname()->sysname, init_utsname()->release,
cdev->gadget->name); cdev->gadget->name);
status = usb_string_id(cdev); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
goto fail; goto fail;
strings_dev[STRING_MANUFACTURER_IDX].id = status; device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
device_desc.iManufacturer = status; device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
status = usb_string_id(cdev);
if (status < 0)
goto fail;
strings_dev[STRING_PRODUCT_IDX].id = status;
device_desc.iProduct = status;
status = usb_add_config(cdev, &audio_config_driver, audio_do_config); status = usb_add_config(cdev, &audio_config_driver, audio_do_config);
if (status < 0) if (status < 0)
......
...@@ -193,17 +193,11 @@ static int __init cdc_bind(struct usb_composite_dev *cdev) ...@@ -193,17 +193,11 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
init_utsname()->sysname, init_utsname()->release, init_utsname()->sysname, init_utsname()->release,
gadget->name); gadget->name);
status = usb_string_id(cdev); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
goto fail1; goto fail1;
strings_dev[STRING_MANUFACTURER_IDX].id = status; device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
device_desc.iManufacturer = status; device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
status = usb_string_id(cdev);
if (status < 0)
goto fail1;
strings_dev[STRING_PRODUCT_IDX].id = status;
device_desc.iProduct = status;
/* register our configuration */ /* register our configuration */
status = usb_add_config(cdev, &cdc_config_driver, cdc_do_config); status = usb_add_config(cdev, &cdc_config_driver, cdc_do_config);
......
...@@ -345,17 +345,11 @@ static int __init eth_bind(struct usb_composite_dev *cdev) ...@@ -345,17 +345,11 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
init_utsname()->sysname, init_utsname()->release, init_utsname()->sysname, init_utsname()->release,
gadget->name); gadget->name);
status = usb_string_id(cdev); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
goto fail; goto fail;
strings_dev[STRING_MANUFACTURER_IDX].id = status; device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
device_desc.iManufacturer = status; device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
status = usb_string_id(cdev);
if (status < 0)
goto fail;
strings_dev[STRING_PRODUCT_IDX].id = status;
device_desc.iProduct = status;
/* register our configuration(s); RNDIS first, if it's used */ /* register our configuration(s); RNDIS first, if it's used */
if (has_rndis()) { if (has_rndis()) {
......
...@@ -140,25 +140,12 @@ static int __init midi_bind(struct usb_composite_dev *cdev) ...@@ -140,25 +140,12 @@ static int __init midi_bind(struct usb_composite_dev *cdev)
struct usb_gadget *gadget = cdev->gadget; struct usb_gadget *gadget = cdev->gadget;
int gcnum, status; int gcnum, status;
status = usb_string_id(cdev); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
return status; return status;
strings_dev[STRING_MANUFACTURER_IDX].id = status; device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
device_desc.iManufacturer = status; device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id;
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;
gcnum = usb_gadget_controller_number(gadget); gcnum = usb_gadget_controller_number(gadget);
if (gcnum < 0) { if (gcnum < 0) {
......
...@@ -176,17 +176,12 @@ static int __init hid_bind(struct usb_composite_dev *cdev) ...@@ -176,17 +176,12 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
init_utsname()->sysname, init_utsname()->release, init_utsname()->sysname, init_utsname()->release,
gadget->name); 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) if (status < 0)
return status; return status;
strings_dev[STRING_PRODUCT_IDX].id = status; device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
device_desc.iProduct = status; device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
/* register our configuration */ /* register our configuration */
status = usb_add_config(cdev, &config_driver, do_config); status = usb_add_config(cdev, &config_driver, do_config);
......
...@@ -180,17 +180,11 @@ static int __init gncm_bind(struct usb_composite_dev *cdev) ...@@ -180,17 +180,11 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
init_utsname()->sysname, init_utsname()->release, init_utsname()->sysname, init_utsname()->release,
gadget->name); gadget->name);
status = usb_string_id(cdev); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
goto fail; goto fail;
strings_dev[STRING_MANUFACTURER_IDX].id = status; device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
device_desc.iManufacturer = status; device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
status = usb_string_id(cdev);
if (status < 0)
goto fail;
strings_dev[STRING_PRODUCT_IDX].id = status;
device_desc.iProduct = status;
status = usb_add_config(cdev, &ncm_config_driver, status = usb_add_config(cdev, &ncm_config_driver,
ncm_do_config); ncm_do_config);
......
...@@ -164,26 +164,12 @@ static int __init nokia_bind(struct usb_composite_dev *cdev) ...@@ -164,26 +164,12 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
if (status < 0) if (status < 0)
goto err_ether; goto err_ether;
status = usb_string_id(cdev); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
goto err_usb; goto err_usb;
strings_dev[STRING_MANUFACTURER_IDX].id = status; device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
device_desc.iManufacturer = status; status = strings_dev[STRING_DESCRIPTION_IDX].id;
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;
nokia_config_500ma_driver.iConfiguration = status; nokia_config_500ma_driver.iConfiguration = status;
nokia_config_100ma_driver.iConfiguration = status; nokia_config_100ma_driver.iConfiguration = status;
......
...@@ -175,26 +175,12 @@ static int __init gs_bind(struct usb_composite_dev *cdev) ...@@ -175,26 +175,12 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
init_utsname()->sysname, init_utsname()->release, init_utsname()->sysname, init_utsname()->release,
gadget->name); gadget->name);
status = usb_string_id(cdev); status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0) if (status < 0)
goto fail; goto fail;
strings_dev[STRING_MANUFACTURER_IDX].id = status; device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
device_desc.iManufacturer = status; status = strings_dev[STRING_DESCRIPTION_IDX].id;
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;
serial_config_driver.iConfiguration = status; serial_config_driver.iConfiguration = status;
/* set up other descriptors */ /* set up other descriptors */
......
...@@ -355,20 +355,15 @@ webcam_bind(struct usb_composite_dev *cdev) ...@@ -355,20 +355,15 @@ webcam_bind(struct usb_composite_dev *cdev)
/* Allocate string descriptor numbers ... note that string contents /* Allocate string descriptor numbers ... note that string contents
* can be overridden by the composite_dev glue. * 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; goto error;
webcam_strings[STRING_MANUFACTURER_IDX].id = ret; webcam_device_descriptor.iManufacturer =
webcam_device_descriptor.iManufacturer = ret; webcam_strings[STRING_MANUFACTURER_IDX].id;
webcam_device_descriptor.iProduct =
if ((ret = usb_string_id(cdev)) < 0) webcam_strings[STRING_PRODUCT_IDX].id;
goto error; webcam_config_driver.iConfiguration =
webcam_strings[STRING_PRODUCT_IDX].id = ret; webcam_strings[STRING_DESCRIPTION_IDX].id;
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;
/* Register our configuration. */ /* Register our configuration. */
if ((ret = usb_add_config(cdev, &webcam_config_driver, if ((ret = usb_add_config(cdev, &webcam_config_driver,
......
...@@ -264,28 +264,18 @@ static int __init zero_bind(struct usb_composite_dev *cdev) ...@@ -264,28 +264,18 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
{ {
int gcnum; int gcnum;
struct usb_gadget *gadget = cdev->gadget; struct usb_gadget *gadget = cdev->gadget;
int id; int status;
/* Allocate string descriptor numbers ... note that string /* Allocate string descriptor numbers ... note that string
* contents can be overridden by the composite_dev glue. * contents can be overridden by the composite_dev glue.
*/ */
id = usb_string_id(cdev); status = usb_string_ids_tab(cdev, strings_dev);
if (id < 0) if (status < 0)
return id; return status;
strings_dev[STRING_MANUFACTURER_IDX].id = id;
device_desc.iManufacturer = id; device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
id = usb_string_id(cdev); device_desc.iSerialNumber = strings_dev[STRING_SERIAL_IDX].id;
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;
setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev); setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册