Skip to content

Commit 46108b4

Browse files
ribaldamchehab
authored andcommitted
media: ioctl: Simulate v4l2_queryctrl with v4l2_query_ext_ctrl
v4l2_queryctrl is a subset of v4l2_query_ext_ctrl. If the driver does not implement v4l2_queryctrl we can implement it with v4l2_query_ext_ctrl. Suggested-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent a79efc4 commit 46108b4

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

drivers/media/v4l2-core/v4l2-dev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,8 @@ static void determine_valid_ioctls(struct video_device *vdev)
572572
and that can't be tested here. If the bit for these control ioctls
573573
is set, then the ioctl is valid. But if it is 0, then it can still
574574
be valid if the filehandle passed the control handler. */
575-
if (vdev->ctrl_handler || ops->vidioc_queryctrl)
575+
if (vdev->ctrl_handler || ops->vidioc_queryctrl ||
576+
ops->vidioc_query_ext_ctrl)
576577
__set_bit(_IOC_NR(VIDIOC_QUERYCTRL), valid_ioctls);
577578
if (vdev->ctrl_handler || ops->vidioc_query_ext_ctrl)
578579
__set_bit(_IOC_NR(VIDIOC_QUERY_EXT_CTRL), valid_ioctls);

drivers/media/v4l2-core/v4l2-ioctl.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2286,17 +2286,52 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
22862286
struct file *file, void *fh, void *arg)
22872287
{
22882288
struct video_device *vfd = video_devdata(file);
2289+
struct v4l2_query_ext_ctrl qec = {};
22892290
struct v4l2_queryctrl *p = arg;
22902291
struct v4l2_fh *vfh =
22912292
test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
2293+
int ret;
22922294

22932295
if (vfh && vfh->ctrl_handler)
22942296
return v4l2_queryctrl(vfh->ctrl_handler, p);
22952297
if (vfd->ctrl_handler)
22962298
return v4l2_queryctrl(vfd->ctrl_handler, p);
22972299
if (ops->vidioc_queryctrl)
22982300
return ops->vidioc_queryctrl(file, fh, p);
2299-
return -ENOTTY;
2301+
if (!ops->vidioc_query_ext_ctrl)
2302+
return -ENOTTY;
2303+
2304+
/* Simulate query_ext_ctr using query_ctrl. */
2305+
qec.id = p->id;
2306+
ret = ops->vidioc_query_ext_ctrl(file, fh, &qec);
2307+
if (ret)
2308+
return ret;
2309+
2310+
p->id = qec.id;
2311+
p->type = qec.type;
2312+
p->flags = qec.flags;
2313+
strscpy(p->name, qec.name, sizeof(p->name));
2314+
switch (p->type) {
2315+
case V4L2_CTRL_TYPE_INTEGER:
2316+
case V4L2_CTRL_TYPE_BOOLEAN:
2317+
case V4L2_CTRL_TYPE_MENU:
2318+
case V4L2_CTRL_TYPE_INTEGER_MENU:
2319+
case V4L2_CTRL_TYPE_STRING:
2320+
case V4L2_CTRL_TYPE_BITMASK:
2321+
p->minimum = qec.minimum;
2322+
p->maximum = qec.maximum;
2323+
p->step = qec.step;
2324+
p->default_value = qec.default_value;
2325+
break;
2326+
default:
2327+
p->minimum = 0;
2328+
p->maximum = 0;
2329+
p->step = 0;
2330+
p->default_value = 0;
2331+
break;
2332+
}
2333+
2334+
return 0;
23002335
}
23012336

23022337
static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,

0 commit comments

Comments
 (0)