From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lukasz Majewski Date: Wed, 22 Feb 2017 13:07:59 +0100 Subject: [U-Boot] [PATCH 1/2] usb: gadget: g_dnl: fix g_dnl_set_serialnumber() In-Reply-To: <20170222092238.1436-1-felipe.balbi@linux.intel.com> References: <20170222092238.1436-1-felipe.balbi@linux.intel.com> Message-ID: <20170222130759.1ce79ed3@jawa> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Wed, 22 Feb 2017 11:22:37 +0200 Felipe Balbi wrote: > 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 > --- > drivers/usb/gadget/g_dnl.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c > index 45a484c4b725..4ba7c1da7cb0 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 = { Acked-by: Lukasz Majewski Tested-by: Lukasz Majewski Test HW: BBB (am335x) - with tests/py/dfu Test SW: test/py/dfu I've applied it to u-boot-dfu tree. Best regards, Lukasz Majewski -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de