usb: gadget: uvc: Use custom strings if available
authorDaniel Scally <dan.scally@ideasonboard.com>
Mon, 6 Feb 2023 16:18:02 +0000 (16:18 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 7 Feb 2023 07:46:37 +0000 (08:46 +0100)
If the user has defined a custom string descriptor for the IAD or the
VideoStreaming interfaces then set their index field to point to the
custom descriptor instead of the hardcoded defaults. If no custom
descriptors have been linked to, then use the default ones.

Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
Link: https://lore.kernel.org/r/20230206161802.892954-12-dan.scally@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_uvc.c

index 7588ab21f95297a133ad36ab179652ab56f5576d..5e919fb6583301f285174711f03cc5d087a06f13 100644 (file)
@@ -745,6 +745,10 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
                if (xu->string_descriptor_index)
                        xu->desc.iExtension = cdev->usb_strings[xu->string_descriptor_index].id;
 
+       /*
+        * We attach the hard-coded defaults incase the user does not provide
+        * any more appropriate strings through configfs.
+        */
        uvc_en_us_strings[UVC_STRING_CONTROL_IDX].s = opts->function_name;
        us = usb_gstrings_attach(cdev, uvc_function_strings,
                                 ARRAY_SIZE(uvc_en_us_strings));
@@ -752,11 +756,15 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
                ret = PTR_ERR(us);
                goto error;
        }
-       uvc_iad.iFunction = us[UVC_STRING_CONTROL_IDX].id;
-       uvc_control_intf.iInterface = us[UVC_STRING_CONTROL_IDX].id;
-       ret = us[UVC_STRING_STREAMING_IDX].id;
-       uvc_streaming_intf_alt0.iInterface = ret;
-       uvc_streaming_intf_alt1.iInterface = ret;
+
+       uvc_iad.iFunction = opts->iad_index ? cdev->usb_strings[opts->iad_index].id :
+                           us[UVC_STRING_CONTROL_IDX].id;
+       uvc_streaming_intf_alt0.iInterface = opts->vs0_index ?
+                                            cdev->usb_strings[opts->vs0_index].id :
+                                            us[UVC_STRING_STREAMING_IDX].id;
+       uvc_streaming_intf_alt1.iInterface = opts->vs1_index ?
+                                            cdev->usb_strings[opts->vs1_index].id :
+                                            us[UVC_STRING_STREAMING_IDX].id;
 
        /* Allocate interface IDs. */
        if ((ret = usb_interface_id(c, f)) < 0)