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

- Return the right error_idx

If an error is found when validating the list of controls passed with
VIDIOC_G_EXT_CTRLS, then error_idx shall be set to ctrls->count to
indicate to userspace that no actual hardware was touched.

It would have been much nicer of course if error_idx could point to the
control index that failed the validation, but sadly that's not how the
API was designed.

Fixes v4l2-compliance:
Control ioctls (Input 0):
        warn: v4l2-test-controls.cpp(834): error_idx should be equal to count
        warn: v4l2-test-controls.cpp(855): error_idx should be equal to count

Cc: sta...@vger.kernel.org
Fixes: 6fa6f831f095 ("media: v4l2-ctrls: add core request support")
Signed-off-by: Ricardo Ribalda <riba...@chromium.org>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 76e2e595d88d..528eb5f420f6 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -932,13 +932,14 @@ static bool check_ext_ctrls(struct v4l2_ext_controls *c, 
unsigned long ioctl)
        case V4L2_CTRL_WHICH_CUR_VAL:
                return true;
        case V4L2_CTRL_WHICH_REQUEST_VAL:
+               c->error_idx = c->count;
                return false;
        }
 
        /* 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) {
-                       c->error_idx = i;
+                       c->error_idx = ioctl == VIDIOC_TRY_EXT_CTRLS ? i : 
c->count;
                        return false;
                }
        }
-- 
2.31.0.rc2.261.g7f71774620-goog

Reply via email to