+/* Helper to make usb string size */
+#define USBSTRLEN(x) (x * 2 + 2)
+
+/* Populates usbstr with: (len) + (0x03) + unicode(str). Each char in str
+ * takes two bytes in unicode format.
+ * Returns the resulting length of the string in usbstr.
+ * This function can accept overlapping usbstr and str as long as the overlap
+ * does not cause data written to usbstr to overwrite data not yet read from
+ * str.
+ */
+static int make_usb_string(char *usbstr, size_t usblen, char *src,
+ size_t srclen)
+{
+ int len = 0;
+
+ if (usbstr && usblen >= 2 && src && *src && srclen) {
+ char *p;
+
+ if (usblen > 255)
+ usblen = 255;
+
+ p = usbstr + 1;
+ *p++ = 0x03;
+ len = 2;
+ while (srclen && len < usblen) {
+ *p++ = *src++;
+ *p++ = 0;
+ len += 2;
+ srclen--;
+ }
+ *usbstr = (char)len;
+ }
+ return len;
+}
+