usb: gadget: composite: add iSerialNumber to usb_composite_driver
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Thu, 10 May 2012 08:08:00 +0000 (10:08 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 May 2012 19:22:43 +0000 (12:22 -0700)
Add iSerialNumber to usb_composite_driver to allow setting a default value.
This is useful when the module is compiled-in. Then the composite_bind
is executed at kernel boot and string id for iSerialNumber can be overridden
even if there is no iSerialNumber kernel commandline parameter.
If the string id is not overridden, then get_string will never attempt to
look for the alternative string contents using cdev->serial_override.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/composite.c
include/linux/usb/composite.h

index df2749052e2cfcd8fbd30fedf85fbd7783f59e6d..390749bbb0c316119de33dc2aa15d29ec5e37c0f 100644 (file)
@@ -938,7 +938,7 @@ static int get_string(struct usb_composite_dev *cdev,
        else if (cdev->product_override == id)
                str = iProduct ?: composite->iProduct;
        else if (cdev->serial_override == id)
-               str = iSerialNumber;
+               str = iSerialNumber ?: composite->iSerialNumber;
        else
                str = NULL;
        if (str) {
@@ -1503,7 +1503,8 @@ static int composite_bind(struct usb_gadget *gadget)
                cdev->product_override =
                        override_id(cdev, &cdev->desc.iProduct);
 
-       if (iSerialNumber)
+       if (iSerialNumber ||
+           (!cdev->desc.iSerialNumber && composite->iSerialNumber))
                cdev->serial_override =
                        override_id(cdev, &cdev->desc.iSerialNumber);
 
index 5d27a1fe5ce98cd59e7840e08c0f310ee6db6e8f..9d8c3b6344937fa8808962b17edc885e2180c2a3 100644 (file)
@@ -253,6 +253,8 @@ void usb_remove_config(struct usb_composite_dev *,
  * @iManufacturer: Used as iManufacturer override if @dev->iManufacturer is
  *     not set. If NULL a default "<system> <release> with <udc>" value
  *     will be used.
+ * @iSerialNumber: Used as iSerialNumber override if @dev->iSerialNumber is
+ *     not set.
  * @dev: Template descriptor for the device, including default device
  *     identifiers.
  * @strings: tables of strings, keyed by identifiers assigned during bind()
@@ -283,6 +285,7 @@ struct usb_composite_driver {
        const char                              *name;
        const char                              *iProduct;
        const char                              *iManufacturer;
+       const char                              *iSerialNumber;
        const struct usb_device_descriptor      *dev;
        struct usb_gadget_strings               **strings;
        enum usb_device_speed                   max_speed;