From e1f15ccbae40b55a4e2591373ea5f1808cf29855 Mon Sep 17 00:00:00 2001 From: Sebastian Andrzej Siewior Date: Thu, 6 Sep 2012 20:11:16 +0200 Subject: 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 Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Felipe Balbi --- drivers/usb/gadget/acm_ms.c | 12 +++--------- drivers/usb/gadget/audio.c | 12 +++--------- drivers/usb/gadget/cdc2.c | 12 +++--------- drivers/usb/gadget/ether.c | 12 +++--------- drivers/usb/gadget/gmidi.c | 21 ++++----------------- drivers/usb/gadget/hid.c | 11 +++-------- drivers/usb/gadget/ncm.c | 12 +++--------- drivers/usb/gadget/nokia.c | 22 ++++------------------ drivers/usb/gadget/serial.c | 22 ++++------------------ drivers/usb/gadget/webcam.c | 21 ++++++++------------- drivers/usb/gadget/zero.c | 26 ++++++++------------------ 11 files changed, 46 insertions(+), 137 deletions(-) (limited to 'drivers/usb/gadget') diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c index 5db661d8590b..ea349bab7f15 100644 --- a/drivers/usb/gadget/acm_ms.c +++ b/drivers/usb/gadget/acm_ms.c @@ -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); diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c index 689d1422a1c0..5702ce3777fb 100644 --- a/drivers/usb/gadget/audio.c +++ b/drivers/usb/gadget/audio.c @@ -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) diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c index 8e386cf377a5..3b89fe2bd0b8 100644 --- a/drivers/usb/gadget/cdc2.c +++ b/drivers/usb/gadget/cdc2.c @@ -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); diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 39eb718f796a..004c6ed79e3b 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -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()) { diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index 0c70708ef80f..68f8c032ba6b 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c @@ -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) { diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c index 4880cdd9de43..1e3f03be94df 100644 --- a/drivers/usb/gadget/hid.c +++ b/drivers/usb/gadget/hid.c @@ -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); diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c index 69b660b79c09..6c7e15984535 100644 --- a/drivers/usb/gadget/ncm.c +++ b/drivers/usb/gadget/ncm.c @@ -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); diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c index 6834c6204df3..b0893136a05d 100644 --- a/drivers/usb/gadget/nokia.c +++ b/drivers/usb/gadget/nokia.c @@ -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; diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index 098c3d03dedd..9962504e14f1 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c @@ -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 */ diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c index 66dfca86b215..d44a4510a65a 100644 --- a/drivers/usb/gadget/webcam.c +++ b/drivers/usb/gadget/webcam.c @@ -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, diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index 9a9adee2911a..dbc336e3ba98 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c @@ -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); -- cgit v1.2.3