]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: uvcvideo: Fix support for V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX
authorRicardo Ribalda <ribalda@chromium.org>
Wed, 19 Nov 2025 20:17:36 +0000 (20:17 +0000)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Mon, 5 Jan 2026 11:21:21 +0000 (12:21 +0100)
The VIDIOC_G_EXT_CTRLS with which V4L2_CTRL_WHICH_(MIN|MAX)_VAL can only
work for controls that have previously announced support for it.

This patch fixes the following v4l2-compliance error:

  info: checking extended control 'User Controls' (0x00980001)
  fail: v4l2-test-controls.cpp(980): ret != EINVAL (got 13)
        test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL

Fixes: 39d2c891c96e ("media: uvcvideo: support V4L2_CTRL_WHICH_MIN/MAX_VAL")
Cc: stable@vger.kernel.org
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
drivers/media/usb/uvc/uvc_ctrl.c
drivers/media/usb/uvc/uvc_v4l2.c
drivers/media/usb/uvc/uvcvideo.h

index d58bd888f0bf6588197df305ad3c68ba471a3b86..ec5aaeb99928cdb4042e0bcc30050743f9408b71 100644 (file)
@@ -1432,7 +1432,7 @@ static bool uvc_ctrl_is_readable(u32 which, struct uvc_control *ctrl,
  * auto_exposure=1, exposure_time_absolute=251.
  */
 int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
-                          const struct v4l2_ext_controls *ctrls,
+                          const struct v4l2_ext_controls *ctrls, u32 which,
                           unsigned long ioctl)
 {
        struct uvc_control_mapping *master_map = NULL;
@@ -1442,14 +1442,24 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
        s32 val;
        int ret;
        int i;
+       /*
+        * There is no need to check the ioctl, all the ioctls except
+        * VIDIOC_G_EXT_CTRLS use which=V4L2_CTRL_WHICH_CUR_VAL.
+        */
+       bool is_which_min_max = which == V4L2_CTRL_WHICH_MIN_VAL ||
+                               which == V4L2_CTRL_WHICH_MAX_VAL;
 
        if (__uvc_query_v4l2_class(chain, v4l2_id, 0) >= 0)
-               return -EACCES;
+               return is_which_min_max ? -EINVAL : -EACCES;
 
        ctrl = uvc_find_control(chain, v4l2_id, &mapping);
        if (!ctrl)
                return -EINVAL;
 
+       if ((!(ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) ||
+            !(ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX)) && is_which_min_max)
+               return -EINVAL;
+
        if (ioctl == VIDIOC_G_EXT_CTRLS)
                return uvc_ctrl_is_readable(ctrls->which, ctrl, mapping);
 
index 9e4a251eca88085a1b4e0e854370015855be92ee..30c160daed8cb057b31ec00d665107dfdf4be1dc 100644 (file)
@@ -765,14 +765,15 @@ static int uvc_ioctl_query_ext_ctrl(struct file *file, void *priv,
 
 static int uvc_ctrl_check_access(struct uvc_video_chain *chain,
                                 struct v4l2_ext_controls *ctrls,
-                                unsigned long ioctl)
+                                u32 which, unsigned long ioctl)
 {
        struct v4l2_ext_control *ctrl = ctrls->controls;
        unsigned int i;
        int ret = 0;
 
        for (i = 0; i < ctrls->count; ++ctrl, ++i) {
-               ret = uvc_ctrl_is_accessible(chain, ctrl->id, ctrls, ioctl);
+               ret = uvc_ctrl_is_accessible(chain, ctrl->id, ctrls, which,
+                                            ioctl);
                if (ret)
                        break;
        }
@@ -806,7 +807,7 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *priv,
                which = V4L2_CTRL_WHICH_CUR_VAL;
        }
 
-       ret = uvc_ctrl_check_access(chain, ctrls, VIDIOC_G_EXT_CTRLS);
+       ret = uvc_ctrl_check_access(chain, ctrls, which, VIDIOC_G_EXT_CTRLS);
        if (ret < 0)
                return ret;
 
@@ -840,7 +841,8 @@ static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle,
        if (!ctrls->count)
                return 0;
 
-       ret = uvc_ctrl_check_access(chain, ctrls, ioctl);
+       ret = uvc_ctrl_check_access(chain, ctrls, V4L2_CTRL_WHICH_CUR_VAL,
+                                   ioctl);
        if (ret < 0)
                return ret;
 
index ed7bad31f75ca474c1037d666d5310c78dd764df..d583425893a5f716185153a07aae9bfe20182964 100644 (file)
@@ -786,7 +786,7 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which,
                 struct v4l2_ext_control *xctrl);
 int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl);
 int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
-                          const struct v4l2_ext_controls *ctrls,
+                          const struct v4l2_ext_controls *ctrls, u32 which,
                           unsigned long ioctl);
 
 int uvc_xu_ctrl_query(struct uvc_video_chain *chain,