Re: [PATCH v2 1/2] usb: gadget: initialize serialnumber

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 23-10-27, Sascha Hauer wrote:
> On Fri, Oct 27, 2023 at 10:09:43AM +0200, Marco Felsch wrote:
> > On 23-10-27, Sascha Hauer wrote:
> > > On Thu, Oct 26, 2023 at 11:32:10PM +0200, Ahmad Fatoum wrote:
> > > > On 26.10.23 16:43, Marco Felsch wrote:
> > > > > Windows hosts do require the serial number to be set to any ascii string
> > > > > to enumerate correctly. Set the serial number if provided or to "unset"
> > > > > if not to provide a sane default which works for both hosts.
> > > > > 
> > > > > Reported-by: Andrey Zhizhikin <andrey.zhizhikin@xxxxxxxxxxxxxxxxxxxx>
> > > > > Signed-off-by: Marco Felsch <m.felsch@xxxxxxxxxxxxxx>
> > > > 
> > > > Reviewed-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
> > > > 
> > > > > ---
> > > > > Changelog
> > > > > 
> > > > > v2:
> > > > > - adapt commit message
> > > > > - use barebox_get_serial_number() and "unset"
> > > > > 
> > > > >  drivers/usb/gadget/udc/core.c | 2 +-
> > > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
> > > > > index b58498680ad1..e7cfa0d5d836 100644
> > > > > --- a/drivers/usb/gadget/udc/core.c
> > > > > +++ b/drivers/usb/gadget/udc/core.c
> > > > > @@ -1204,7 +1204,7 @@ int usb_add_gadget(struct usb_gadget *gadget)
> > > > >  	gadget->productname = xstrdup(barebox_get_model());
> > > > >  	dev_add_param_string(&gadget->dev, "productname", NULL, NULL,
> > > > >  			     &gadget->productname, NULL);
> > > > > -	gadget->serialnumber = xstrdup("");
> > > > > +	gadget->serialnumber = xstrdup(barebox_get_serial_number() ? : "unset");
> > > > 
> > > > Nitpick: xstrdup(NULL) == NULL, so the ternary could be moved out the xstrdup.
> > > 
> > > gadget->serialnumber is freed when the value of the variable is changed,
> > > so it must be an allocated string. gadget->serialnumber = "unset" would
> > > be wrong.
> > 
> > I would have done the following:
> > 
> > 	xstrdup(barebox_get_serial_number()) ? : xstrdup("unset");
> 
> Your original code looked better. This one looks like the ?: handles
> failures in xstrdup().

Right, thanks for the input.

Regards,
  Marco




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux