]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
USB: replace hardcode maximum usb string length by definition
authorMacpaul Lin <macpaul.lin@mediatek.com>
Thu, 18 Jun 2020 09:13:38 +0000 (17:13 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 Mar 2021 09:57:00 +0000 (10:57 +0100)
commit 81c7462883b0cc0a4eeef0687f80ad5b5baee5f6 upstream.

Replace hardcoded maximum USB string length (126 bytes) by definition
"USB_MAX_STRING_LEN".

Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/1592471618-29428-1-git-send-email-macpaul.lin@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/composite.c
drivers/usb/gadget/configfs.c
drivers/usb/gadget/usbstring.c
include/uapi/linux/usb/ch9.h

index 5688df02d9ab9689d5d6678141d4ae3e371aeb62..bb72d55a58b5a6c3dd87382c2a66ffd9f39f58e8 100644 (file)
@@ -933,7 +933,7 @@ static void collect_langs(struct usb_gadget_strings **sp, __le16 *buf)
        while (*sp) {
                s = *sp;
                language = cpu_to_le16(s->language);
-               for (tmp = buf; *tmp && tmp < &buf[126]; tmp++) {
+               for (tmp = buf; *tmp && tmp < &buf[USB_MAX_STRING_LEN]; tmp++) {
                        if (*tmp == language)
                                goto repeat;
                }
@@ -1008,7 +1008,7 @@ static int get_string(struct usb_composite_dev *cdev,
                        collect_langs(sp, s->wData);
                }
 
-               for (len = 0; len <= 126 && s->wData[len]; len++)
+               for (len = 0; len <= USB_MAX_STRING_LEN && s->wData[len]; len++)
                        continue;
                if (!len)
                        return -EINVAL;
index 98f1ce1d61b0b97365cde1673a96410032690fe6..97d059d10285902c28943ad0f91bfbb8a649ae33 100644 (file)
@@ -117,7 +117,7 @@ static int usb_string_copy(const char *s, char **s_copy)
        char *str;
        char *copy = *s_copy;
        ret = strlen(s);
-       if (ret > 126)
+       if (ret > USB_MAX_STRING_LEN)
                return -EOVERFLOW;
 
        str = kstrdup(s, GFP_KERNEL);
index 73a4dfba0edbf8076c6183b817c1599d8dc58adb..0173a9969b9a0d53fad61654d6c6c2b69591a558 100644 (file)
@@ -59,9 +59,9 @@ usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
                return -EINVAL;
 
        /* string descriptors have length, tag, then UTF16-LE text */
-       len = min ((size_t) 126, strlen (s->s));
+       len = min((size_t)USB_MAX_STRING_LEN, strlen(s->s));
        len = utf8s_to_utf16s(s->s, len, UTF16_LITTLE_ENDIAN,
-                       (wchar_t *) &buf[2], 126);
+                       (wchar_t *) &buf[2], USB_MAX_STRING_LEN);
        if (len < 0)
                return -EINVAL;
        buf [0] = (len + 1) * 2;
index ec6c8543732f2c531162d532c83681bea9c05929..9ca4b43122d7c799a6fabe335f99819b73f91720 100644 (file)
@@ -333,6 +333,9 @@ struct usb_config_descriptor {
 
 /*-------------------------------------------------------------------------*/
 
+/* USB String descriptors can contain at most 126 characters. */
+#define USB_MAX_STRING_LEN     126
+
 /* USB_DT_STRING: String descriptor */
 struct usb_string_descriptor {
        __u8  bLength;