Skip to contentSkip to conversation

v4l2-compliance: Fix V4L2_CTRL_WHICH_DEF_VAL in multi_classes

PATCH In review Ricardo Ribalda 2 participants 5 messages Mar 10, 2021 – Mar 11, 2021 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 v4l2-compliance: Fix V4L2_CTRL_WHICH_DEF_VAL in multi_classes

If there are multiple classes, the ioctl should fail.

Fixes 0884b19adada ("v4l2-compliance: add test for V4L2_CTRL_WHICH_DEF_VAL")
---
 utils/v4l2-compliance/v4l2-test-controls.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
utils/v4l2-compliance/v4l2-test-controls.cpp +4 -1
index 9a68b7e847b0..79982bc15054 100644
@@ -793,7 +793,10 @@ int testExtendedControls(struct node *node)
 	ctrls.which = V4L2_CTRL_WHICH_DEF_VAL;
 	fail_on_test(!doioctl(node, VIDIOC_S_EXT_CTRLS, &ctrls));
 	fail_on_test(!doioctl(node, VIDIOC_TRY_EXT_CTRLS, &ctrls));
-	fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
+	if (multiple_classes)
+		fail_on_test(!doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
+	else
+		fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
 	return 0;
 }
 
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
#1 lore raw
Quoted 1 line · Ricardo Ribalda

If there are multiple classes, the ioctl should fail.

It shouldn't matter if there are multiple classes or not, it should work.

What is the exact error you get with which driver?

Regards,

Hans

Quoted 24 lines
Fixes 0884b19adada ("v4l2-compliance: add test for V4L2_CTRL_WHICH_DEF_VAL")
---
 utils/v4l2-compliance/v4l2-test-controls.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
utils/v4l2-compliance/v4l2-test-controls.cpp +4 -1
index 9a68b7e847b0..79982bc15054 100644
@@ -793,7 +793,10 @@ int testExtendedControls(struct node *node)
 	ctrls.which = V4L2_CTRL_WHICH_DEF_VAL;
 	fail_on_test(!doioctl(node, VIDIOC_S_EXT_CTRLS, &ctrls));
 	fail_on_test(!doioctl(node, VIDIOC_TRY_EXT_CTRLS, &ctrls));
-	fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
+	if (multiple_classes)
+		fail_on_test(!doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
+	else
+		fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
 	return 0;
 }
 
#2 lore raw

Hi Hans

Thanks for your review!

Quoted 6 lines · Hans Verkuil
Quoted 1 line · Ricardo Ribalda

If there are multiple classes, the ioctl should fail.

It shouldn't matter if there are multiple classes or not, it should work.

I believe this is the part of the kernel that is triggering the issue:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/media/v4l2-core/v4l2-ioctl.c#n929

I can send a patch if that is not the intended behaviour ;)

/* 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;
return 0;

Quoted 2 lines

What is the exact error you get with which driver?

I am trying to fix uvc compliance

fail: v4l2-test-controls.cpp(813): doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls)
test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL

Quoted 2 lines

Regards,

Best regards!

Quoted 28 lines

Hans

Quoted 24 lines
Fixes 0884b19adada ("v4l2-compliance: add test for V4L2_CTRL_WHICH_DEF_VAL")
---
 utils/v4l2-compliance/v4l2-test-controls.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
utils/v4l2-compliance/v4l2-test-controls.cpp +4 -1
index 9a68b7e847b0..79982bc15054 100644
@@ -793,7 +793,10 @@ int testExtendedControls(struct node *node)
      ctrls.which = V4L2_CTRL_WHICH_DEF_VAL;
      fail_on_test(!doioctl(node, VIDIOC_S_EXT_CTRLS, &ctrls));
      fail_on_test(!doioctl(node, VIDIOC_TRY_EXT_CTRLS, &ctrls));
-     fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
+     if (multiple_classes)
+             fail_on_test(!doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
+     else
+             fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
      return 0;
 }
 
Signature · 1 line
Ricardo Ribalda
#3 lore raw
Quoted 17 lines · Ricardo Ribalda

Hi Hans

Thanks for your review!

Quoted 6 lines · Hans Verkuil
Quoted 1 line · Ricardo Ribalda

If there are multiple classes, the ioctl should fail.

It shouldn't matter if there are multiple classes or not, it should work.

I believe this is the part of the kernel that is triggering the issue:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/media/v4l2-core/v4l2-ioctl.c#n929

Quoted 7 lines

I can send a patch if that is not the intended behaviour ;)

/* 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;
return 0;

Ah, and this is only called for drivers that do not use the control framework.

This is a bug, just before that for-loop it says:

        if (!c->which)
                return 1;

This should be:

	if (!c->which || c->which == V4L2_CTRL_WHICH_DEF_VAL)
                return 1;
	if (c->which == V4L2_CTRL_WHICH_REQUEST_VAL)
		return 0;

Regards,

Hans

Quoted 45 lines
Quoted 3 lines

What is the exact error you get with which driver?

I am trying to fix uvc compliance

fail: v4l2-test-controls.cpp(813): doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls)
test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL

Quoted 2 lines

Regards,

Best regards!

Quoted 28 lines

Hans

Quoted 24 lines
Fixes 0884b19adada ("v4l2-compliance: add test for V4L2_CTRL_WHICH_DEF_VAL")
---
 utils/v4l2-compliance/v4l2-test-controls.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
utils/v4l2-compliance/v4l2-test-controls.cpp +4 -1
index 9a68b7e847b0..79982bc15054 100644
@@ -793,7 +793,10 @@ int testExtendedControls(struct node *node)
      ctrls.which = V4L2_CTRL_WHICH_DEF_VAL;
      fail_on_test(!doioctl(node, VIDIOC_S_EXT_CTRLS, &ctrls));
      fail_on_test(!doioctl(node, VIDIOC_TRY_EXT_CTRLS, &ctrls));
-     fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
+     if (multiple_classes)
+             fail_on_test(!doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
+     else
+             fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
      return 0;
 }
 
#4 lore raw
Quoted 34 lines · Hans Verkuil
Quoted 17 lines · Ricardo Ribalda

Hi Hans

Thanks for your review!

Quoted 6 lines · Hans Verkuil
Quoted 1 line · Ricardo Ribalda

If there are multiple classes, the ioctl should fail.

It shouldn't matter if there are multiple classes or not, it should work.

I believe this is the part of the kernel that is triggering the issue:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/media/v4l2-core/v4l2-ioctl.c#n929

Quoted 7 lines

I can send a patch if that is not the intended behaviour ;)

/* 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;
return 0;

Ah, and this is only called for drivers that do not use the control framework.

This is a bug, just before that for-loop it says:

        if (!c->which)
                return 1;
Quoted 6 lines

This should be:

        if (!c->which || c->which == V4L2_CTRL_WHICH_DEF_VAL)
                return 1;
        if (c->which == V4L2_CTRL_WHICH_REQUEST_VAL)
                return 0;

Can I send a patch for that?

Quoted 51 lines

Regards,

Hans

Quoted 45 lines
Quoted 3 lines

What is the exact error you get with which driver?

I am trying to fix uvc compliance

fail: v4l2-test-controls.cpp(813): doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls)
test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL

Quoted 2 lines

Regards,

Best regards!

Quoted 28 lines

Hans

Quoted 24 lines
Fixes 0884b19adada ("v4l2-compliance: add test for V4L2_CTRL_WHICH_DEF_VAL")
---
 utils/v4l2-compliance/v4l2-test-controls.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
utils/v4l2-compliance/v4l2-test-controls.cpp +4 -1
index 9a68b7e847b0..79982bc15054 100644
@@ -793,7 +793,10 @@ int testExtendedControls(struct node *node)
      ctrls.which = V4L2_CTRL_WHICH_DEF_VAL;
      fail_on_test(!doioctl(node, VIDIOC_S_EXT_CTRLS, &ctrls));
      fail_on_test(!doioctl(node, VIDIOC_TRY_EXT_CTRLS, &ctrls));
-     fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
+     if (multiple_classes)
+             fail_on_test(!doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
+     else
+             fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls));
      return 0;
 }
 
Signature · 1 line
Ricardo Ribalda