From: Felipe Balbi Date: Wed, 22 Feb 2017 09:22:37 +0000 (+0200) Subject: usb: gadget: g_dnl: fix g_dnl_set_serialnumber() X-Git-Tag: v2017.03-rc3~7^2~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=949bf79e73a12961cf1310baf411647083f34b34;p=u-boot usb: gadget: g_dnl: fix g_dnl_set_serialnumber() instead of only copying if strlen(s) is less than 32 characters, let's just copy at most 31 characters regardless of the size of serial#. This will guarantee that we always have a serial number if serial# environment variable is set to anything. Note that without a proper serial number, USB Command Verifier fails our test of Device Descriptor since we will claim to have a serial number without really providing one when requested. Signed-off-by: Felipe Balbi --- diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c index 45a484c4b7..4ba7c1da7c 100644 --- a/drivers/usb/gadget/g_dnl.c +++ b/drivers/usb/gadget/g_dnl.c @@ -49,8 +49,7 @@ static const char manufacturer[] = CONFIG_G_DNL_MANUFACTURER; void g_dnl_set_serialnumber(char *s) { memset(g_dnl_serial, 0, MAX_STRING_SERIAL); - if (strlen(s) < MAX_STRING_SERIAL) - strncpy(g_dnl_serial, s, strlen(s)); + strncpy(g_dnl_serial, s, MAX_STRING_SERIAL - 1); } static struct usb_device_descriptor device_desc = {