This patch moves the module options idVendor, idProduct and bcdDevice from composite.c into each gadgets. This ensures compatibility with current gadgets and removes the global variable which brings me step closer towards composite.c in libcomposite
Signed-off-by: Sebastian Andrzej Siewior <bige...@linutronix.de> --- drivers/usb/gadget/acm_ms.c | 2 ++ drivers/usb/gadget/audio.c | 3 +++ drivers/usb/gadget/cdc2.c | 2 ++ drivers/usb/gadget/composite.c | 23 ----------------------- drivers/usb/gadget/ether.c | 2 ++ drivers/usb/gadget/g_ffs.c | 4 +++- drivers/usb/gadget/gmidi.c | 4 +++- drivers/usb/gadget/hid.c | 2 ++ drivers/usb/gadget/mass_storage.c | 3 ++- drivers/usb/gadget/multi.c | 3 ++- drivers/usb/gadget/ncm.c | 2 ++ drivers/usb/gadget/nokia.c | 2 ++ drivers/usb/gadget/printer.c | 9 ++++++++- drivers/usb/gadget/serial.c | 2 ++ drivers/usb/gadget/tcm_usb_gadget.c | 5 +++++ drivers/usb/gadget/webcam.c | 2 ++ drivers/usb/gadget/zero.c | 2 ++ include/linux/usb/composite.h | 30 ++++++++++++++++++++++++++++++ 18 files changed, 74 insertions(+), 28 deletions(-) diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c index 5db661d..94a558a 100644 --- a/drivers/usb/gadget/acm_ms.c +++ b/drivers/usb/gadget/acm_ms.c @@ -47,6 +47,7 @@ #include "f_mass_storage.c" /*-------------------------------------------------------------------------*/ +USB_GADGET_COMPOSITE_OPTIONS(); static struct usb_device_descriptor device_desc = { .bLength = sizeof device_desc, @@ -209,6 +210,7 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev) if (status < 0) goto fail1; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC); fsg_common_put(&fsg_common); diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c index 689d142..a9c687a 100644 --- a/drivers/usb/gadget/audio.c +++ b/drivers/usb/gadget/audio.c @@ -13,6 +13,7 @@ #include <linux/kernel.h> #include <linux/utsname.h> +#include <linux/usb/composite.h> #include "gadget_chips.h" #define DRIVER_DESC "Linux USB Audio Gadget" @@ -28,6 +29,7 @@ * a "gcc --combine ... part1.c part2.c part3.c ... " build would. */ #include "composite.c" +USB_GADGET_COMPOSITE_OPTIONS(); /* string IDs are assigned dynamically */ @@ -180,6 +182,7 @@ static int __init audio_bind(struct usb_composite_dev *cdev) status = usb_add_config(cdev, &audio_config_driver, audio_do_config); if (status < 0) goto fail; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); INFO(cdev, "%s, version: %s\n", DRIVER_DESC, DRIVER_VERSION); return 0; diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c index 8e386cf..f0f8444 100644 --- a/drivers/usb/gadget/cdc2.c +++ b/drivers/usb/gadget/cdc2.c @@ -34,6 +34,7 @@ #define CDC_PRODUCT_NUM 0xa4aa /* CDC Composite: ECM + ACM */ /*-------------------------------------------------------------------------*/ +USB_GADGET_COMPOSITE_OPTIONS(); /* * Kbuild is not very cooperative with respect to linking separately @@ -210,6 +211,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev) if (status < 0) goto fail1; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC); diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 153efc4..aac450e 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -32,19 +32,6 @@ * published in the device descriptor, either numbers or strings or both. * String parameters are in UTF-8 (superset of ASCII's 7 bit characters). */ - -static ushort idVendor; -module_param(idVendor, ushort, S_IRUGO); -MODULE_PARM_DESC(idVendor, "USB Vendor ID"); - -static ushort idProduct; -module_param(idProduct, ushort, S_IRUGO); -MODULE_PARM_DESC(idProduct, "USB Product ID"); - -static ushort bcdDevice; -module_param(bcdDevice, ushort, S_IRUGO); -MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); - static char *iManufacturer; module_param(iManufacturer, charp, S_IRUGO); MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); @@ -1475,16 +1462,6 @@ static int composite_bind(struct usb_gadget *gadget, cdev->desc = *cdriver->dev; - /* standardized runtime overrides for device ID data */ - if (idVendor) - cdev->desc.idVendor = cpu_to_le16(idVendor); - - if (idProduct) - cdev->desc.idProduct = cpu_to_le16(idProduct); - - if (bcdDevice) - cdev->desc.bcdDevice = cpu_to_le16(bcdDevice); - /* string overrides */ if (iManufacturer || !cdev->desc.iManufacturer) { if (!iManufacturer && !cdriver->iManufacturer && diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 39eb718..3bd9982 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -114,6 +114,7 @@ static inline bool has_rndis(void) #include "u_ether.c" /*-------------------------------------------------------------------------*/ +USB_GADGET_COMPOSITE_OPTIONS(); /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! * Instead: allocate your own, using normal USB-IF procedures. @@ -369,6 +370,7 @@ static int __init eth_bind(struct usb_composite_dev *cdev) if (status < 0) goto fail; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC); diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index c3a583e..563feb5 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c @@ -73,6 +73,8 @@ struct gfs_ffs_obj { struct ffs_data *ffs_data; }; +USB_GADGET_COMPOSITE_OPTIONS(); + static struct usb_device_descriptor gfs_dev_desc = { .bLength = sizeof gfs_dev_desc, .bDescriptorType = USB_DT_DEVICE, @@ -377,7 +379,7 @@ static int gfs_bind(struct usb_composite_dev *cdev) if (unlikely(ret < 0)) goto error_unbind; } - + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(gfs_dev_desc); return 0; error_unbind: diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index 0c70708..5c624df 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c @@ -48,6 +48,8 @@ MODULE_LICENSE("GPL v2"); static const char shortname[] = "g_midi"; static const char longname[] = "MIDI Gadget"; +USB_GADGET_COMPOSITE_OPTIONS(); + static int index = SNDRV_DEFAULT_IDX1; module_param(index, int, S_IRUGO); MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter."); @@ -176,7 +178,7 @@ static int __init midi_bind(struct usb_composite_dev *cdev) status = usb_add_config(cdev, &midi_config, midi_bind_config); if (status < 0) return status; - + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); pr_info("%s\n", longname); return 0; } diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c index 4880cdd..942f12c 100644 --- a/drivers/usb/gadget/hid.c +++ b/drivers/usb/gadget/hid.c @@ -48,6 +48,7 @@ struct hidg_func_node { static LIST_HEAD(hidg_func_list); /*-------------------------------------------------------------------------*/ +USB_GADGET_COMPOSITE_OPTIONS(); static struct usb_device_descriptor device_desc = { .bLength = sizeof device_desc, @@ -193,6 +194,7 @@ static int __init hid_bind(struct usb_composite_dev *cdev) if (status < 0) return status; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); return 0; diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c index 0b0f008..2426927 100644 --- a/drivers/usb/gadget/mass_storage.c +++ b/drivers/usb/gadget/mass_storage.c @@ -52,6 +52,7 @@ #include "f_mass_storage.c" /*-------------------------------------------------------------------------*/ +USB_GADGET_COMPOSITE_OPTIONS(); static struct usb_device_descriptor msg_device_desc = { .bLength = sizeof msg_device_desc, @@ -143,7 +144,7 @@ static int __init msg_bind(struct usb_composite_dev *cdev) status = usb_add_config(cdev, &msg_config_driver, msg_do_config); if (status < 0) return status; - + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(msg_device_desc); dev_info(&cdev->gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); set_bit(0, &msg_registered); diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index 72fb301..e739771 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c @@ -58,7 +58,7 @@ MODULE_LICENSE("GPL"); #endif #include "u_ether.c" - +USB_GADGET_COMPOSITE_OPTIONS(); /***************************** Device Descriptor ****************************/ @@ -307,6 +307,7 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) status = cdc_config_register(cdev); if (unlikely(status < 0)) goto fail2; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); /* we're done */ dev_info(&gadget->dev, DRIVER_DESC "\n"); diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c index 69b660b..05be581 100644 --- a/drivers/usb/gadget/ncm.c +++ b/drivers/usb/gadget/ncm.c @@ -54,6 +54,7 @@ #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ /*-------------------------------------------------------------------------*/ +USB_GADGET_COMPOSITE_OPTIONS(); static struct usb_device_descriptor device_desc = { .bLength = sizeof device_desc, @@ -197,6 +198,7 @@ static int __init gncm_bind(struct usb_composite_dev *cdev) if (status < 0) goto fail; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); dev_info(&gadget->dev, "%s\n", DRIVER_DESC); return 0; diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c index 6834c62..ee69345 100644 --- a/drivers/usb/gadget/nokia.c +++ b/drivers/usb/gadget/nokia.c @@ -49,6 +49,7 @@ #include "u_ether.c" /*-------------------------------------------------------------------------*/ +USB_GADGET_COMPOSITE_OPTIONS(); #define NOKIA_VENDOR_ID 0x0421 /* Nokia */ #define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */ @@ -211,6 +212,7 @@ static int __init nokia_bind(struct usb_composite_dev *cdev) if (status < 0) goto err_usb; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME); return 0; diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index 3d3d20d..39279e2 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c @@ -54,6 +54,7 @@ #include "composite.c" /*-------------------------------------------------------------------------*/ +USB_GADGET_COMPOSITE_OPTIONS(); #define DRIVER_DESC "Printer Gadget" #define DRIVER_VERSION "2007 OCT 06" @@ -1263,7 +1264,13 @@ static int printer_unbind(struct usb_composite_dev *cdev) static int __init printer_bind(struct usb_composite_dev *cdev) { - return usb_add_config(cdev, &printer_cfg_driver, printer_bind_config); + int ret; + + ret = usb_add_config(cdev, &printer_cfg_driver, printer_bind_config); + if (ret) + return ret; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); + return 0; } static __refdata struct usb_composite_driver printer_driver = { diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index 098c3d0..3ed3071 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c @@ -45,6 +45,7 @@ #include "u_serial.c" /*-------------------------------------------------------------------------*/ +USB_GADGET_COMPOSITE_OPTIONS(); /* Thanks to NetChip Technologies for donating this product ID. * @@ -226,6 +227,7 @@ static int __init gs_bind(struct usb_composite_dev *cdev) if (status < 0) goto fail; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); INFO(cdev, "%s\n", GS_VERSION_NAME); return 0; diff --git a/drivers/usb/gadget/tcm_usb_gadget.c b/drivers/usb/gadget/tcm_usb_gadget.c index e64a759..5641ea1 100644 --- a/drivers/usb/gadget/tcm_usb_gadget.c +++ b/drivers/usb/gadget/tcm_usb_gadget.c @@ -29,6 +29,8 @@ #include "tcm_usb_gadget.h" +USB_GADGET_COMPOSITE_OPTIONS(); + static struct target_fabric_configfs *usbg_fabric_configfs; static inline struct f_uas *to_f_uas(struct usb_function *f) @@ -2430,6 +2432,9 @@ static int usb_target_bind(struct usb_composite_dev *cdev) ret = usb_add_config(cdev, &usbg_config_driver, usbg_cfg_bind); + if (ret) + return ret; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(usbg_device_desc); return 0; } diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c index 66dfca8..df79957 100644 --- a/drivers/usb/gadget/webcam.c +++ b/drivers/usb/gadget/webcam.c @@ -30,6 +30,7 @@ #include "uvc_v4l2.c" #include "f_uvc.c" +USB_GADGET_COMPOSITE_OPTIONS(); /* -------------------------------------------------------------------------- * Device descriptor */ @@ -375,6 +376,7 @@ webcam_bind(struct usb_composite_dev *cdev) webcam_config_bind)) < 0) goto error; + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(webcam_device_descriptor); INFO(cdev, "Webcam Video Gadget\n"); return 0; diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index 9a9adee..4a6ca25 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c @@ -64,6 +64,7 @@ #include "f_loopback.c" /*-------------------------------------------------------------------------*/ +USB_GADGET_COMPOSITE_OPTIONS(); #define DRIVER_VERSION "Cinco de Mayo 2008" @@ -315,6 +316,7 @@ static int __init zero_bind(struct usb_composite_dev *cdev) longname, gadget->name); device_desc.bcdDevice = cpu_to_le16(0x9999); } + USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc); INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname); diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index e970fba..fc25c54 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h @@ -381,6 +381,36 @@ extern int usb_string_ids_tab(struct usb_composite_dev *c, struct usb_string *str); extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); +/* + * Some systems will need runtime overrides for the product identifiers + * published in the device descriptor, either numbers or strings or both. + * String parameters are in UTF-8 (superset of ASCII's 7 bit characters). + */ +#define USB_GADGET_COMPOSITE_OPTIONS() \ + static ushort idVendor; \ + module_param(idVendor, ushort, S_IRUGO); \ + MODULE_PARM_DESC(idVendor, "USB Vendor ID"); \ + \ + static ushort idProduct; \ + module_param(idProduct, ushort, S_IRUGO); \ + MODULE_PARM_DESC(idProduct, "USB Product ID"); \ + \ + static ushort bcdDevice; \ + module_param(bcdDevice, ushort, S_IRUGO); \ + MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)") + +#define USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(__usb_desc) \ + do { \ + if (idVendor) \ + __usb_desc.idVendor = cpu_to_le16(idVendor); \ + \ + if (idProduct) \ + __usb_desc.idProduct = cpu_to_le16(idProduct); \ + \ + if (bcdDevice) \ + __usb_desc.bcdDevice = cpu_to_le16(bcdDevice); \ + } while (0) + /* messaging utils */ #define DBG(d, fmt, args...) \ -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html