]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: uvcvideo: Handle uvc menu translation inside uvc_set_le_value
authorRicardo Ribalda <ribalda@chromium.org>
Mon, 3 Feb 2025 11:55:41 +0000 (11:55 +0000)
committerHans Verkuil <hverkuil@xs4all.nl>
Mon, 3 Mar 2025 17:23:35 +0000 (18:23 +0100)
Be consistent with uvc_get_le_value() and do the menu translation there.

Note that in this case, the refactor does not provide much... but
consistency is a nice feature.

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Yunke Cao <yunkec@google.com>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Link: https://lore.kernel.org/r/20250203-uvc-roi-v17-5-5900a9fed613@chromium.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
drivers/media/usb/uvc/uvc_ctrl.c

index 4a55cf78ec5261fa1db1cdeb055edccf655fbabd..3108d2fa1ff9a2f9c35dae8b3e9da30142929e43 100644 (file)
@@ -939,14 +939,22 @@ static void uvc_set_le_value(struct uvc_control_mapping *mapping,
        int offset = mapping->offset;
        u8 mask;
 
-       /*
-        * According to the v4l2 spec, writing any value to a button control
-        * should result in the action belonging to the button control being
-        * triggered. UVC devices however want to see a 1 written -> override
-        * value.
-        */
-       if (mapping->v4l2_type == V4L2_CTRL_TYPE_BUTTON)
+       switch (mapping->v4l2_type) {
+       case V4L2_CTRL_TYPE_MENU:
+               value = uvc_mapping_get_menu_value(mapping, value);
+               break;
+       case V4L2_CTRL_TYPE_BUTTON:
+               /*
+                * According to the v4l2 spec, writing any value to a button
+                * control should result in the action belonging to the button
+                * control being triggered. UVC devices however want to see a 1
+                * written -> override value.
+                */
                value = -1;
+               break;
+       default:
+               break;
+       }
 
        data += offset / 8;
        offset &= 7;
@@ -2033,23 +2041,23 @@ int uvc_ctrl_set(struct uvc_fh *handle,
                if (!test_bit(xctrl->value, &mapping->menu_mask))
                        return -EINVAL;
 
-               value = uvc_mapping_get_menu_value(mapping, xctrl->value);
-
                /*
                 * Valid menu indices are reported by the GET_RES request for
                 * UVC controls that support it.
                 */
                if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK) {
+                       int val = uvc_mapping_get_menu_value(mapping,
+                                                            xctrl->value);
                        if (!ctrl->cached) {
                                ret = uvc_ctrl_populate_cache(chain, ctrl);
                                if (ret < 0)
                                        return ret;
                        }
 
-                       if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & value))
+                       if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & val))
                                return -EINVAL;
                }
-
+               value = xctrl->value;
                break;
 
        default: