Skip to content

Commit e2a4539

Browse files
ribaldaSasha Levin
authored andcommitted
media: uvcvideo: Fix support for V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX
[ Upstream commit 4238bd6 ] 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: 39d2c89 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 451cc65 commit e2a4539

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

drivers/media/usb/uvc/uvc_ctrl.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ static bool uvc_ctrl_is_readable(u32 which, struct uvc_control *ctrl,
14321432
* auto_exposure=1, exposure_time_absolute=251.
14331433
*/
14341434
int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
1435-
const struct v4l2_ext_controls *ctrls,
1435+
const struct v4l2_ext_controls *ctrls, u32 which,
14361436
unsigned long ioctl)
14371437
{
14381438
struct uvc_control_mapping *master_map = NULL;
@@ -1442,14 +1442,24 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
14421442
s32 val;
14431443
int ret;
14441444
int i;
1445+
/*
1446+
* There is no need to check the ioctl, all the ioctls except
1447+
* VIDIOC_G_EXT_CTRLS use which=V4L2_CTRL_WHICH_CUR_VAL.
1448+
*/
1449+
bool is_which_min_max = which == V4L2_CTRL_WHICH_MIN_VAL ||
1450+
which == V4L2_CTRL_WHICH_MAX_VAL;
14451451

14461452
if (__uvc_query_v4l2_class(chain, v4l2_id, 0) >= 0)
1447-
return -EACCES;
1453+
return is_which_min_max ? -EINVAL : -EACCES;
14481454

14491455
ctrl = uvc_find_control(chain, v4l2_id, &mapping);
14501456
if (!ctrl)
14511457
return -EINVAL;
14521458

1459+
if ((!(ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) ||
1460+
!(ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX)) && is_which_min_max)
1461+
return -EINVAL;
1462+
14531463
if (ioctl == VIDIOC_G_EXT_CTRLS)
14541464
return uvc_ctrl_is_readable(ctrls->which, ctrl, mapping);
14551465

drivers/media/usb/uvc/uvc_v4l2.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -765,14 +765,15 @@ static int uvc_ioctl_query_ext_ctrl(struct file *file, void *priv,
765765

766766
static int uvc_ctrl_check_access(struct uvc_video_chain *chain,
767767
struct v4l2_ext_controls *ctrls,
768-
unsigned long ioctl)
768+
u32 which, unsigned long ioctl)
769769
{
770770
struct v4l2_ext_control *ctrl = ctrls->controls;
771771
unsigned int i;
772772
int ret = 0;
773773

774774
for (i = 0; i < ctrls->count; ++ctrl, ++i) {
775-
ret = uvc_ctrl_is_accessible(chain, ctrl->id, ctrls, ioctl);
775+
ret = uvc_ctrl_is_accessible(chain, ctrl->id, ctrls, which,
776+
ioctl);
776777
if (ret)
777778
break;
778779
}
@@ -806,7 +807,7 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *priv,
806807
which = V4L2_CTRL_WHICH_CUR_VAL;
807808
}
808809

809-
ret = uvc_ctrl_check_access(chain, ctrls, VIDIOC_G_EXT_CTRLS);
810+
ret = uvc_ctrl_check_access(chain, ctrls, which, VIDIOC_G_EXT_CTRLS);
810811
if (ret < 0)
811812
return ret;
812813

@@ -840,7 +841,8 @@ static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle,
840841
if (!ctrls->count)
841842
return 0;
842843

843-
ret = uvc_ctrl_check_access(chain, ctrls, ioctl);
844+
ret = uvc_ctrl_check_access(chain, ctrls, V4L2_CTRL_WHICH_CUR_VAL,
845+
ioctl);
844846
if (ret < 0)
845847
return ret;
846848

drivers/media/usb/uvc/uvcvideo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which,
787787
struct v4l2_ext_control *xctrl);
788788
int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl);
789789
int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
790-
const struct v4l2_ext_controls *ctrls,
790+
const struct v4l2_ext_controls *ctrls, u32 which,
791791
unsigned long ioctl);
792792

793793
int uvc_xu_ctrl_query(struct uvc_video_chain *chain,

0 commit comments

Comments
 (0)