Skip to contentSkip to conversation

usb: gadget: g_dnl: hold maximum string descriptor

PATCH New Felipe Balbi 1 participant 3 messages Feb 22, 2017 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 usb: gadget: g_dnl: hold maximum string descriptor

A USB String descriptor can be up to 255 characters long and it's not NULL terminated according to the USB spec. This means our MAX_STRING_SERIAL should be 256 (to cope with NULL terminator).

---

No access to a board right now, compile tested only

 drivers/usb/gadget/g_dnl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/g_dnl.c +1 -1
index 4ba7c1da7cb0..fcedb554c4c6 100644
@@ -36,7 +36,7 @@
 #define STRING_USBDOWN 2
 /* Index of String serial */
 #define STRING_SERIAL  3
-#define MAX_STRING_SERIAL	32
+#define MAX_STRING_SERIAL	256
 /* Number of supported configurations */
 #define CONFIGURATION_NUMBER 1
 
Signature · 1 line
2.11.0.295.gd7dffce1ce
#1 lore raw

PATCH 2/3 usb: gadget: g_dnl: only set iSerialNumber if we have a serial#

We don't want to claim that we support a serial number string and later return nothing. Because of that, if g_dnl_serial is an empty string, let's skip setting iSerialNumber to a valid number.

---

No access to a board right now, compile tested only

 drivers/usb/gadget/g_dnl.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/usb/gadget/g_dnl.c +7 -5
index fcedb554c4c6..4cc4438fdb4a 100644
@@ -224,12 +224,14 @@ static int g_dnl_bind(struct usb_composite_dev *cdev)
 	g_dnl_string_defs[1].id = id;
 	device_desc.iProduct = id;
 
-	id = usb_string_id(cdev);
-	if (id < 0)
-		return id;
+	if (strlen(g_dnl_serial)) {
+		id = usb_string_id(cdev);
+		if (id < 0)
+			return id;
 
-	g_dnl_string_defs[2].id = id;
-	device_desc.iSerialNumber = id;
+		g_dnl_string_defs[2].id = id;
+		device_desc.iSerialNumber = id;
+	}
 
 	g_dnl_bind_fixup(&device_desc, cdev->driver->name);
 	ret = g_dnl_config_register(cdev);
Signature · 1 line
2.11.0.295.gd7dffce1ce
#2 lore raw

PATCH 3/3 usb: gadget: g_dnl: don't set iProduct nor iSerialNumber

In reply to Felipe Balbi

Both these numbers are calculated in runtime and dynamically assigned to the device descriptor during bind().

---

No access to a board right now, compile tested only

 drivers/usb/gadget/g_dnl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/g_dnl.c +2 -2
index 4cc4438fdb4a..d4bee9b03e4f 100644
@@ -62,8 +62,8 @@ static struct usb_device_descriptor device_desc = {
 
 	.idVendor = __constant_cpu_to_le16(CONFIG_G_DNL_VENDOR_NUM),
 	.idProduct = __constant_cpu_to_le16(CONFIG_G_DNL_PRODUCT_NUM),
-	.iProduct = STRING_PRODUCT,
-	.iSerialNumber = STRING_SERIAL,
+	/* .iProduct = DYNAMIC */
+	/* .iSerialNumber = DYNAMIC */
 	.bNumConfigurations = 1,
 };
 
Signature · 1 line
2.11.0.295.gd7dffce1ce