Re: [PATCH 19/21] usb/gadget: Provide a default implementation of default manufacturer string

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

 



Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> writes:
> Some gadgets provide custom entry here. Some may override it with an
> etntry that is also created by composite if there was no value sumbitted
> at all.
> This patch removes all "custom manufacturer" strings which are the same
> as these which are created by composite. Then it moves the creation of
> the default manufacturer string to usb_composite_overwrite_options() in
> case no command line argument has been used and the entry is still an
> empty string.
> By doing this we get rid of the global variable "manufacturer" in
> composite.

It's actually called "composite_manufacturer". :)

> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>

Acked-by: Michal Nazarewicz <mina86@xxxxxxxxxx>


> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
> index b477d9e..20a1ace 100644
> --- a/drivers/usb/gadget/composite.c
> +++ b/drivers/usb/gadget/composite.c

> @@ -1672,6 +1628,28 @@ void usb_composite_setup_continue(struct usb_composite_dev *cdev)
>  	spin_unlock_irqrestore(&cdev->lock, flags);
>  }
>  
> +static char *composite_default_mfr(struct usb_gadget *gadget)
> +{
> +	char *mfr;
> +	int len;
> +
> +	len = snprintf(NULL, 0, "%s %s with %s", init_utsname()->sysname,
> +			init_utsname()->release, gadget->name);

I'd probably explicitly sum strlen() of the strings, but either is fine.

> +	if (len < 0)
> +		return NULL;

Can that even happen?

> +	len = min(32, len + 1);

Is min really needed here?  Just do ++len and let allocator worry. ;)

> +	mfr = kmalloc(len, GFP_KERNEL);
> +	if (!mfr)
> +		return NULL;
> +	len = snprintf(mfr, len, "%s %s with %s", init_utsname()->sysname,
> +			init_utsname()->release, gadget->name);
> +	if (len < 0) {

Again, can that even happen?

> +		kfree(mfr);
> +		return NULL;
> +	}
> +	return mfr;
> +}
> +
>  void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
>  		struct usb_composite_overwrite *covr)
>  {
> @@ -1695,6 +1673,11 @@ void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
>  	if (covr->manufacturer) {
>  		desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id;
>  		dev_str[USB_GADGET_MANUFACTURER_IDX].s = covr->manufacturer;
> +
> +	} else if (!strlen(dev_str[USB_GADGET_MANUFACTURER_IDX].s)) {

+	} else if (*dev_str[USB_GADGET_MANUFACTURER_IDX].s) {

> +		desc->iManufacturer = dev_str[USB_GADGET_MANUFACTURER_IDX].id;
> +		cdev->def_manufacturer = composite_default_mfr(cdev->gadget);
> +		dev_str[USB_GADGET_MANUFACTURER_IDX].s = cdev->def_manufacturer;
>  	}
>  
>  	if (covr->product) {

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@xxxxxxxxxx>--------------ooO--(_)--Ooo--

Attachment: pgp4ogyTu4fO4.pgp
Description: PGP signature


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux