summaryrefslogtreecommitdiff
path: root/drivers/usb/gadget/usbstring.c
diff options
context:
space:
mode:
authorTao Ren <rentao.bupt@gmail.com>2020-03-15 12:16:28 -0700
committerFelipe Balbi <balbi@kernel.org>2020-05-05 10:58:51 +0300
commit17309a6a43561bd7f4d4b51d7987225eb2b13d05 (patch)
treeac43215c4142fe3e783955d1af712f340fddf4c0 /drivers/usb/gadget/usbstring.c
parent5cc0710f23689455d40d590ebbcbcd21b0d84c77 (diff)
usb: gadget: add "usb_validate_langid" function
The USB LANGID validation code in "check_user_usb_string" function is moved to "usb_validate_langid" function which can be used by other usb gadget drivers. Signed-off-by: Tao Ren <rentao.bupt@gmail.com> Signed-off-by: Felipe Balbi <balbi@kernel.org>
Diffstat (limited to 'drivers/usb/gadget/usbstring.c')
-rw-r--r--drivers/usb/gadget/usbstring.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c
index 7c24d1ce1088..58a4d3325090 100644
--- a/drivers/usb/gadget/usbstring.c
+++ b/drivers/usb/gadget/usbstring.c
@@ -65,3 +65,27 @@ usb_gadget_get_string (const struct usb_gadget_strings *table, int id, u8 *buf)
return buf [0];
}
EXPORT_SYMBOL_GPL(usb_gadget_get_string);
+
+/**
+ * usb_validate_langid - validate usb language identifiers
+ * @lang: usb language identifier
+ *
+ * Returns true for valid language identifier, otherwise false.
+ */
+bool usb_validate_langid(u16 langid)
+{
+ u16 primary_lang = langid & 0x3ff; /* bit [9:0] */
+ u16 sub_lang = langid >> 10; /* bit [15:10] */
+
+ switch (primary_lang) {
+ case 0:
+ case 0x62 ... 0xfe:
+ case 0x100 ... 0x3ff:
+ return false;
+ }
+ if (!sub_lang)
+ return false;
+
+ return true;
+}
+EXPORT_SYMBOL_GPL(usb_validate_langid);