Sebastian Andrzej Siewior <bige...@linutronix.de> writes:
> This patch pushes the iSerialNumber module argument from composite into
> each gadget. Each gadgets holds a dummy strings in its "struct
> usb_string" to ensure that usb_string_ids_tab() allocates a valid id.
> Once the user uses the module paramter, the string is overwritten with
> the final value.
> This is mostly the same change in each gadget with some minor
> exceptions:
> - printer accepts two arguments: iSerialNumber like everyone else and
>   iSerialNum which was used before it was converted to composite
> - g_ffs got a few ifdefs and an enum in order to get the proper index
> - mass_storage: gained a struct usb_gadget_strings
>
> Signed-off-by: Sebastian Andrzej Siewior <bige...@linutronix.de>

> diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
> index f34be59..63ef563 100644
> --- a/drivers/usb/gadget/acm_ms.c
> +++ b/drivers/usb/gadget/acm_ms.c
> @@ -92,12 +92,14 @@ static const struct usb_descriptor_header *otg_desc[] = {
>  
>  #define STRING_MANUFACTURER_IDX              0
>  #define STRING_PRODUCT_IDX           1
> +#define STRING_PRODUCT_SERIAL                2
>  
>  static char manufacturer[50];
>  
>  static struct usb_string strings_dev[] = {
>       [STRING_MANUFACTURER_IDX].s = manufacturer,
>       [STRING_PRODUCT_IDX].s = DRIVER_DESC,
> +     [STRING_PRODUCT_SERIAL].s = "",
>       {  } /* end of list */
>  };
>  
> @@ -205,6 +207,11 @@ static int __init acm_ms_bind(struct usb_composite_dev 
> *cdev)
>               goto fail1;
>  
>       USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(device_desc);
> +     if (iSerialNumber) {
> +             strings_dev[STRING_PRODUCT_SERIAL].s = iSerialNumber;
> +             device_desc.iSerialNumber =
> +                     strings_dev[STRING_PRODUCT_SERIAL].id;
> +     }

Could we instead have USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS handle
this?

This could be achieved by passing strings_dev and STRING_PRODUCT_SERIAL
to the macro.  It could also take care of "" initialisation if module
parameter was not given.

Alternatively, composite could require STRING_PRODUCT_SERIAL to always
be zero.  This way only strings_dev would have to be passed as
additional argument to the macro.

>       dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
>                       DRIVER_DESC);
>       fsg_common_put(&fsg_common);

> diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
> index 563feb5..948414d 100644
> --- a/drivers/usb/gadget/g_ffs.c
> +++ b/drivers/usb/gadget/g_ffs.c
> @@ -114,17 +114,33 @@ static const struct usb_descriptor_header 
> *gfs_otg_desc[] = {
>       NULL
>  };
>  
> +enum {
> +#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
> +     GFFS_FFS_RNDIS_IDX,
> +#endif
> +
> +#ifdef CONFIG_USB_FUNCTIONFS_ETH
> +     GFFS_FFS_ECM_IDX,
> +#endif
> +
> +#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
> +     GFFS_FFS_ECM_GEN_IDX,
> +#endif
> +     GFFS_SERIAL_IDX,
> +};
> +
>  /* String IDs are assigned dynamically */
>  static struct usb_string gfs_strings[] = {
>  #ifdef CONFIG_USB_FUNCTIONFS_RNDIS
> -     { .s = "FunctionFS + RNDIS" },
> +     [GFFS_FFS_RNDIS_IDX].s = "FunctionFS + RNDIS",
>  #endif
>  #ifdef CONFIG_USB_FUNCTIONFS_ETH
> -     { .s = "FunctionFS + ECM" },
> +     [GFFS_FFS_ECM_IDX].s = "FunctionFS + ECM",
>  #endif
>  #ifdef CONFIG_USB_FUNCTIONFS_GENERIC
> -     { .s = "FunctionFS" },
> +     [GFFS_FFS_ECM_IDX].s = "FunctionFS",
>  #endif
> +     [GFFS_SERIAL_IDX].s = "",
>       {  } /* end of list */
>  };
>  
> @@ -380,6 +396,11 @@ static int gfs_bind(struct usb_composite_dev *cdev)
>                       goto error_unbind;
>       }
>       USB_GADGET_COMPOSITE_OVERWRITE_OPTIONS(gfs_dev_desc);
> +     if (iSerialNumber) {
> +             gfs_strings[GFFS_SERIAL_IDX].s = iSerialNumber;
> +             gfs_dev_desc.iSerialNumber = gfs_strings[GFFS_SERIAL_IDX].id;
> +     }
> +

Alternatively, you could just define GFFS_SERIAL_IDX as zero and change:

-               c->c.label                      = gfs_strings[i].s;
-               c->c.iConfiguration             = gfs_strings[i].id;
+               c->c.label                      = gfs_strings[i + 1].s;
+               c->c.iConfiguration             = gfs_strings[i + 1].id;

(In fact, moving ++i from the for loop just above c.label assignment
would make it even easier.)

>       return 0;
>  
>  error_unbind:

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

Attachment: pgpJYt1k4Jy01.pgp
Description: PGP signature

Reply via email to