2021-03-16 21:18:10

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v5 01/13] media: v4l2-ioctl: Fix check_ext_ctrls

Drivers that do not use the ctrl-framework use this function instead.

- Return error when handling of REQUEST_VAL.
- Do not check for multiple classes when getting the DEF_VAL.

Fixes v4l2-compliance:
Control ioctls (Input 0):
fail: v4l2-test-controls.cpp(813): doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls)
test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL

Cc: [email protected]
Fixes: 6fa6f831f095 ("media: v4l2-ctrls: add core request support")
Suggested-by: Hans Verkuil <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
Reviewed-by: Laurent Pinchart <[email protected]>
---
drivers/media/v4l2-core/v4l2-ioctl.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 31d1342e61e8..9406e90ff805 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -917,15 +917,24 @@ static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
for (i = 0; i < c->count; i++)
c->controls[i].reserved2[0] = 0;

- /* V4L2_CID_PRIVATE_BASE cannot be used as control class
- when using extended controls.
- Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
- is it allowed for backwards compatibility.
- */
- if (!allow_priv && c->which == V4L2_CID_PRIVATE_BASE)
- return 0;
- if (!c->which)
+ switch (c->which) {
+ case V4L2_CID_PRIVATE_BASE:
+ /*
+ * V4L2_CID_PRIVATE_BASE cannot be used as control class
+ * when using extended controls.
+ * Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
+ * is it allowed for backwards compatibility.
+ */
+ if (!allow_priv)
+ return 0;
+ break;
+ case V4L2_CTRL_WHICH_DEF_VAL:
+ case V4L2_CTRL_WHICH_CUR_VAL:
return 1;
+ case V4L2_CTRL_WHICH_REQUEST_VAL:
+ return 0;
+ }
+
/* Check that all controls are from the same control class. */
for (i = 0; i < c->count; i++) {
if (V4L2_CTRL_ID2WHICH(c->controls[i].id) != c->which) {
--
2.31.0.rc2.261.g7f71774620-goog


2021-03-17 10:39:32

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH v5 01/13] media: v4l2-ioctl: Fix check_ext_ctrls

On 16/03/2021 18:59, Ricardo Ribalda wrote:
> Drivers that do not use the ctrl-framework use this function instead.
>
> - Return error when handling of REQUEST_VAL.
> - Do not check for multiple classes when getting the DEF_VAL.
>
> Fixes v4l2-compliance:
> Control ioctls (Input 0):
> fail: v4l2-test-controls.cpp(813): doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls)
> test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
>
> Cc: [email protected]
> Fixes: 6fa6f831f095 ("media: v4l2-ctrls: add core request support")
> Suggested-by: Hans Verkuil <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>
> Reviewed-by: Laurent Pinchart <[email protected]>
> ---
> drivers/media/v4l2-core/v4l2-ioctl.c | 25 +++++++++++++++++--------
> 1 file changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 31d1342e61e8..9406e90ff805 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -917,15 +917,24 @@ static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)

allow_priv really should be a bool.

> for (i = 0; i < c->count; i++)
> c->controls[i].reserved2[0] = 0;
>
> - /* V4L2_CID_PRIVATE_BASE cannot be used as control class
> - when using extended controls.
> - Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
> - is it allowed for backwards compatibility.
> - */
> - if (!allow_priv && c->which == V4L2_CID_PRIVATE_BASE)
> - return 0;
> - if (!c->which)
> + switch (c->which) {
> + case V4L2_CID_PRIVATE_BASE:
> + /*
> + * V4L2_CID_PRIVATE_BASE cannot be used as control class
> + * when using extended controls.
> + * Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
> + * is it allowed for backwards compatibility.
> + */
> + if (!allow_priv)
> + return 0;
> + break;
> + case V4L2_CTRL_WHICH_DEF_VAL:

I think it would be better if a second bool 'is_get' argument is added that is true
for g_ctrl and g_ext_ctrls: then you can do a 'return is_get;' here. That way drivers
do not need to take care of V4L2_CTRL_WHICH_DEF_VAL for set/try.

Regards,

Hans

> + case V4L2_CTRL_WHICH_CUR_VAL:
> return 1;
> + case V4L2_CTRL_WHICH_REQUEST_VAL:
> + return 0;
> + }
> +
> /* Check that all controls are from the same control class. */
> for (i = 0; i < c->count; i++) {
> if (V4L2_CTRL_ID2WHICH(c->controls[i].id) != c->which) {
>