[PATCH 3/3] usb/gadgets: push iSerialNumber into gadgets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
---
 drivers/usb/gadget/composite.c |   16 +++++++++-------
 drivers/usb/gadget/printer.c   |    6 +-----
 include/linux/usb/composite.h  |    7 ++++++-
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 3cdc3c1..011c722 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -40,10 +40,6 @@ static char *iProduct;
 module_param(iProduct, charp, S_IRUGO);
 MODULE_PARM_DESC(iProduct, "USB Product string");
 
-static char *iSerialNumber;
-module_param(iSerialNumber, charp, S_IRUGO);
-MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
-
 static char composite_manufacturer[50];
 
 /*-------------------------------------------------------------------------*/
@@ -925,7 +921,7 @@ static int get_string(struct usb_composite_dev *cdev,
 	else if (cdev->product_override == id)
 		str = iProduct ?: cdriver->iProduct;
 	else if (cdev->serial_override == id)
-		str = iSerialNumber ?: cdriver->iSerialNumber;
+		str = cdriver->iSerialNumber;
 	else
 		str = NULL;
 	if (str) {
@@ -1505,8 +1501,7 @@ static int composite_bind(struct usb_gadget *gadget,
 		cdev->product_override =
 			override_id(cdev, &cdev->desc.iProduct);
 
-	if (iSerialNumber ||
-	    (!cdev->desc.iSerialNumber && cdriver->iSerialNumber))
+	if (cdriver->iSerialNumber)
 		cdev->serial_override =
 			override_id(cdev, &cdev->desc.iSerialNumber);
 
@@ -1698,6 +1693,8 @@ void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
 		struct usb_composite_overwrite *covr)
 {
 	struct usb_device_descriptor	*desc = &cdev->desc;
+	struct usb_gadget_strings	*gstr = cdev->driver->strings[0];
+	struct usb_string		*dev_strings = gstr->strings;
 
 	if (covr->idVendor)
 		desc->idVendor = cpu_to_le16(covr->idVendor);
@@ -1707,4 +1704,9 @@ void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
 
 	if (covr->bcdDevice)
 		desc->bcdDevice = cpu_to_le16(covr->bcdDevice);
+
+	if (covr->iSerialNumber) {
+		desc->iSerialNumber = dev_strings[USB_GADGET_SERIAL_IDX].id;
+		dev_strings[USB_GADGET_SERIAL_IDX].s = covr->iSerialNumber;
+	}
 }
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index f02434a..794601a 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -118,8 +118,7 @@ static struct printer_dev usb_printer_gadget;
  * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
  */
 
-static char *iSerialNum;
-module_param(iSerialNum, charp, S_IRUGO);
+module_param_named(iSerialNum, coverwrite.iSerialNumber, charp, S_IRUGO);
 MODULE_PARM_DESC(iSerialNum, "1");
 
 static char *iPNPstring;
@@ -1170,9 +1169,6 @@ static int __init printer_bind_config(struct usb_configuration *c)
 		init_utsname()->sysname, init_utsname()->release,
 		gadget->name);
 
-	if (iSerialNum)
-		strlcpy(serial_num, iSerialNum, sizeof serial_num);
-
 	if (iPNPstring)
 		strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2);
 
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 367bbb6..35e8c87 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -398,6 +398,7 @@ struct usb_composite_overwrite {
 	u16	idVendor;
 	u16	idProduct;
 	u16	bcdDevice;
+	char	*iSerialNumber;
 };
 #define USB_GADGET_COMPOSITE_OPTIONS()					\
 	static struct usb_composite_overwrite coverwrite;		\
@@ -409,7 +410,11 @@ struct usb_composite_overwrite {
 	MODULE_PARM_DESC(idProduct, "USB Product ID");			\
 									\
 	module_param_named(bcdDevice, coverwrite.bcdDevice, ushort, S_IRUGO); \
-	MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)")
+	MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");	\
+									\
+	module_param_named(iSerialNumber, coverwrite.iSerialNumber, charp, \
+			S_IRUGO); \
+	MODULE_PARM_DESC(iSerialNumber, "SerialNumber string")
 
 void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
 		struct usb_composite_overwrite *covr);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux