Skip to contentSkip to conversation

v4l2-ctl/rds-ctl: support optional ioctl and migrate some code to it

PATCH Superseded Quentin Schulz 3 participants 11 messages Sep 5, 2025 – Oct 7, 2025 Media (V4L/DVB)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover v4l2-ctl/rds-ctl: support optional ioctl and migrate some code to it

Some ioctls are optional and the logic around it handle it nicely, except that doioctl (via doioctl_name) sets app_result static variable to -1 if the ioctl fails.

However, both rds-ctl and v4l2-ctl exit code is from app_result. So it is possible to have those tools perform the expected task (albeit failing to use an optional ioctl) and still report to the user that it failed to do so.

Let's add a new function doioctl_opt which allows to NOT set the app_result variable when the ioctl fails.

This migrates two ioctl VIDIOC_SUBDEV_S_CLIENT_CAP and VIDIOC_SUBDEV_QUERYCAP to be optional ioctls.

Note:
- rds-ctl receives the same patch but doesn't make use of it, simply for consistency, but can be dropped if desired,
- wondering if VIDIOC_SUBDEV_QUERYCAP really is optional considering the code in v4l2-compliance/v4l2-test-subdevs:
fail_on_test(doioctl(node, VIDIOC_SUBDEV_QUERYCAP, &caps)); which also has a nice comment above saying "// Must always be there"
- wondering if there aren't more optional ioctl considering how many doioctl calls aren't actually exiting early the tools, Should we add something like __attribute__ ((warn_unused_result)) so we know for sure doioctl shouldn't be used if we don't check its result, though that wouldn't catch if(do_ioctl(...)) for optional ioctls like VIDIOC_SUBDEV_S_CLIENT_CAP here for example,
- I assume we may want to backport those to stable branches? (e.g. Debian Trixie is using 1.30.1 and I experienced this bug with that package version)

---
Quentin Schulz (3):
v4l2-ctl/rds-ctl: do not set app_result if an ioctl is optional
v4l2-ctl: do not fail on kernel not implementing VIDIOC_SUBDEV_S_CLIENT_CAP
v4l2-ctl: do not fail on kernel not implementing VIDIOC_SUBDEV_QUERYCAP

 utils/rds-ctl/rds-ctl.cpp   | 7 ++++---
 utils/v4l2-ctl/v4l2-ctl.cpp | 8 ++++----
 utils/v4l2-ctl/v4l2-ctl.h   | 5 +++--
 3 files changed, 11 insertions(+), 9 deletions(-)

---
base-commit: fc46fc8771bff905204e7463ab03ed1f355436b1
change-id: 20250905-opt-ioctl-387192021068

Best regards,

Signature · 1 line
Quentin Schulz <[email protected]>
#1 lore raw

PATCH 1/3 v4l2-ctl/rds-ctl: do not set app_result if an ioctl is optional

From: Quentin Schulz <[email protected]>

Some ioctls are optional and the logic around it handle it nicely, except that doioctl (via doioctl_name) sets app_result static variable to -1 if the ioctl fails.

However, both rds-ctl and v4l2-ctl exit code is from app_result. So it is possible to have those tools perform the expected task (albeit failing to use an optional ioctl) and still report to the user that it failed to do so.

Instead, let's add doioctl_opt which allows to NOT set the app_result variable when the ioctl fails.

---
 utils/rds-ctl/rds-ctl.cpp   | 7 ++++---
 utils/v4l2-ctl/v4l2-ctl.cpp | 4 ++--
 utils/v4l2-ctl/v4l2-ctl.h   | 5 +++--
 3 files changed, 9 insertions(+), 7 deletions(-)
utils/rds-ctl/rds-ctl.cpp +4 -3
index 813b4f282ff06af82845a93249d5b41bb20f361c..bcd68ed7c7c360906bd30f0df60a983e54fa8344 100644
@@ -169,11 +169,11 @@ static void signal_handler_interrupt(int signum)
 	params.terminate_decoding = true;
 }
 
-static int doioctl_name(int fd, unsigned long int request, void *parm, const char *name)
+static int doioctl_name(int fd, unsigned long int request, void *parm, const char *name, const bool optional)
 {
 	int retval = ioctl(fd, request, parm);
 
-	if (retval < 0) {
+	if (retval < 0 && !optional) {
 		app_result = -1;
 	}
 	if (params.options[OptSilent]) return retval;
@@ -185,7 +185,8 @@ static int doioctl_name(int fd, unsigned long int request, void *parm, const cha
 	return retval;
 }
 
-#define doioctl(n, r, p) doioctl_name(n, r, p, #r)
+#define doioctl(n, r, p) doioctl_name(n, r, p, #r, false)
+#define doioctl_opt(n, r, p) doioctl_name(n, r, p, #r, true)
 
 static bool is_radio_dev(const char *name)
 {
utils/v4l2-ctl/v4l2-ctl.cpp +2 -2
index 9b5b878951495f66082f1b5b13e7a744e45ae4ce..b71b24dab9aafd3538bd2ebc5999a32a5c3c3dfa 100644
@@ -312,11 +312,11 @@ int test_ioctl(int fd, unsigned long cmd, void *arg)
 	return options[OptUseWrapper] ? v4l2_ioctl(fd, cmd, arg) : ioctl(fd, cmd, arg);
 }
 
-int doioctl_name(int fd, unsigned long int request, void *parm, const char *name)
+int doioctl_name(int fd, unsigned long int request, void *parm, const char *name, const bool optional)
 {
 	int retval = test_ioctl(fd, request, parm);
 
-	if (retval < 0)
+	if (retval < 0 && !optional)
 		app_result = -1;
 	if (options[OptSilent]) return retval;
 	if (retval < 0)
utils/v4l2-ctl/v4l2-ctl.h +3 -2
index b0d42110ca0fbbf05dc3957a6fe08f426947b871..209a882fc1c8adf1dc08295fbbbe23964ce67649 100644
@@ -296,7 +296,7 @@ extern int verbose;
 #define FmtSizeImage		(1L<<14)
 
 // v4l2-ctl.cpp
-int doioctl_name(int fd, unsigned long int request, void *parm, const char *name);
+int doioctl_name(int fd, unsigned long int request, void *parm, const char *name, const bool optional);
 int test_ioctl(int fd, unsigned long cmd, void *arg);
 int parse_subopt(char **subs, const char * const *subopts, char **value);
 __u32 parse_field(const char *s);
@@ -331,7 +331,8 @@ static inline bool subscribe_event(cv4l_fd &fd, __u32 type)
 	return !fd.subscribe_event(sub);
 }
 
-#define doioctl(n, r, p) doioctl_name(n, r, p, #r)
+#define doioctl(n, r, p) doioctl_name(n, r, p, #r, false)
+#define doioctl_opt(n, r, p) doioctl_name(n, r, p, #r, true)
 
 #define info(fmt, args...) 			\
 	do {					\
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/3 v4l2-ctl: do not fail on kernel not implementing VIDIOC_SUBDEV_S_CLIENT_CAP

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

VIDIOC_SUBDEV_S_CLIENT_CAP is only available in kernels 6.4 and later.

The current logic has a fallback in case the ioctl fails by simply stating there's no capabilities available for the subdev.

Let's mark this ioctl as optional to avoid kernels lacking it making v4l2-ctl command fail (but still doing what it's been asked to do).

Fixes 2b2ba7e0e86c ("v4l2-ctl/compliance: read and show the subdev client capabilities")
---
 utils/v4l2-ctl/v4l2-ctl.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils/v4l2-ctl/v4l2-ctl.cpp +1 -1
index b71b24dab9aafd3538bd2ebc5999a32a5c3c3dfa..c287c74d5dff869b2a74a2e2bfebc77d0b9e3f1e 100644
@@ -1371,7 +1371,7 @@ int main(int argc, char **argv)
 		// exit if this ioctl returns an error.
 		doioctl(fd, VIDIOC_SUBDEV_QUERYCAP, &subdevcap);
 		subdevclientcap.capabilities = ~0ULL;
-		if (doioctl(fd, VIDIOC_SUBDEV_S_CLIENT_CAP, &subdevclientcap))
+		if (doioctl_opt(fd, VIDIOC_SUBDEV_S_CLIENT_CAP, &subdevclientcap))
 			subdevclientcap.capabilities = 0ULL;
 	}
 	if (!is_subdev) {
Signature · 1 line
2.51.0
#3 lore raw

PATCH 3/3 v4l2-ctl: do not fail on kernel not implementing VIDIOC_SUBDEV_QUERYCAP

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

The comment above the code snippet specifies that we do not want to fail on kernels not implementing VIDIOC_SUBDEV_QUERYCAP (5.9 and earlier) but calling doioctl will still set app_result to a negative value if the kernel doesn't implement it.

Therefore, let's mark this ioctl as optional to avoid falsely reporting an error.

Fixes fc89f67d9fe0 ("v4l2-ctl: add support for VIDIOC_SUBDEV_QUERYCAP")
---
 utils/v4l2-ctl/v4l2-ctl.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils/v4l2-ctl/v4l2-ctl.cpp +1 -1
index c287c74d5dff869b2a74a2e2bfebc77d0b9e3f1e..afaffd71b1e9a50a7975dc3200825aaba16e1473 100644
@@ -1369,7 +1369,7 @@ int main(int argc, char **argv)
 	} else if (is_subdev) {
 		// This ioctl was introduced in kernel 5.10, so don't
 		// exit if this ioctl returns an error.
-		doioctl(fd, VIDIOC_SUBDEV_QUERYCAP, &subdevcap);
+		doioctl_opt(fd, VIDIOC_SUBDEV_QUERYCAP, &subdevcap);
 		subdevclientcap.capabilities = ~0ULL;
 		if (doioctl_opt(fd, VIDIOC_SUBDEV_S_CLIENT_CAP, &subdevclientcap))
 			subdevclientcap.capabilities = 0ULL;
Signature · 1 line
2.51.0
#4 lore raw
In reply to Quentin Schulz
Quoted 9 lines · Quentin Schulz

Some ioctls are optional and the logic around it handle it nicely, except that doioctl (via doioctl_name) sets app_result static variable to -1 if the ioctl fails.

However, both rds-ctl and v4l2-ctl exit code is from app_result. So it is possible to have those tools perform the expected task (albeit failing to use an optional ioctl) and still report to the user that it failed to do so.

Quoted 5 lines

Let's add a new function doioctl_opt which allows to NOT set the app_result variable when the ioctl fails.

This migrates two ioctl VIDIOC_SUBDEV_S_CLIENT_CAP and VIDIOC_SUBDEV_QUERYCAP to be optional ioctls.

Actually, those ioctls must be present, unless you run an old kernel, but they've been around since kernel 6.4.

I'm dropping this series as this isn't quite the way to do this.

Perhaps you should explain the problem you encounter first (and mention the kernel version you are using)?

Regards,

Hans

Quoted 34 lines

Note:
- rds-ctl receives the same patch but doesn't make use of it, simply for consistency, but can be dropped if desired,
- wondering if VIDIOC_SUBDEV_QUERYCAP really is optional considering the code in v4l2-compliance/v4l2-test-subdevs:
fail_on_test(doioctl(node, VIDIOC_SUBDEV_QUERYCAP, &caps)); which also has a nice comment above saying "// Must always be there"
- wondering if there aren't more optional ioctl considering how many doioctl calls aren't actually exiting early the tools, Should we add something like __attribute__ ((warn_unused_result)) so we know for sure doioctl shouldn't be used if we don't check its result, though that wouldn't catch if(do_ioctl(...)) for optional ioctls like VIDIOC_SUBDEV_S_CLIENT_CAP here for example,
- I assume we may want to backport those to stable branches? (e.g. Debian Trixie is using 1.30.1 and I experienced this bug with that package version)

---
Quentin Schulz (3):
v4l2-ctl/rds-ctl: do not set app_result if an ioctl is optional
v4l2-ctl: do not fail on kernel not implementing VIDIOC_SUBDEV_S_CLIENT_CAP
v4l2-ctl: do not fail on kernel not implementing VIDIOC_SUBDEV_QUERYCAP

 utils/rds-ctl/rds-ctl.cpp   | 7 ++++---
 utils/v4l2-ctl/v4l2-ctl.cpp | 8 ++++----
 utils/v4l2-ctl/v4l2-ctl.h   | 5 +++--
 3 files changed, 11 insertions(+), 9 deletions(-)

---
base-commit: fc46fc8771bff905204e7463ab03ed1f355436b1
change-id: 20250905-opt-ioctl-387192021068

Best regards,

#5 lore raw

Hi Hans,

Quoted 12 lines · Hans Verkuil

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 9 lines · Quentin Schulz

Some ioctls are optional and the logic around it handle it nicely, except that doioctl (via doioctl_name) sets app_result static variable to -1 if the ioctl fails.

However, both rds-ctl and v4l2-ctl exit code is from app_result. So it is possible to have those tools perform the expected task (albeit failing to use an optional ioctl) and still report to the user that it failed to do so.

Quoted 9 lines
Quoted 5 lines

Let's add a new function doioctl_opt which allows to NOT set the app_result variable when the ioctl fails.

This migrates two ioctl VIDIOC_SUBDEV_S_CLIENT_CAP and VIDIOC_SUBDEV_QUERYCAP to be optional ioctls.

Actually, those ioctls must be present, unless you run an old kernel, but they've been around since kernel 6.4.

Yes, I am using a 6.1 kernel, which is supported until Dec. 2027, c.f. https://www.kernel.org/releases.html

5.10 is also supported until Dec. 2026.

Quoted 2 lines

I'm dropping this series as this isn't quite the way to do this.

Could you explain what is the issue with those patches so I can suggest something else?

Quoted 3 lines

Perhaps you should explain the problem you encounter first (and mention the kernel version you are using)?

Run v4l-utils on an older kernel (6.1 for example) and it'll try to use the ioctl that isn't supported. Since it's optional (the return code isn't checked directly) it'll happily actually do what's expected from it but the program will end with a non-zero exit code, thus failing my CI tests while still actually performing what it is requested to do. This is due to the failing ioctl setting app_result global variable but the failing calls not actually being checked right after in the calling function so the program continues as if everything went well but the last line of the main function (std::exit(options[OptAll] ? 0 : app_result);) actually returns the exit code matching app_result value, which is set when the (deemed optional) ioctl fails.

I use v4l2-ctl to set a test pattern on a camera and now my CI simply doesn't pass anymore on Trixie because of that. For now, I ignore the exit code of v4l2-ctl -c test_pattern=1 and validate it actually was run by running v4l2-ctl -C test_pattern afterwards (but still not checking the exit code of this command as it's still returning that it failed).

Kernel is 6.1.

Cheers,
Quentin

#6 lore raw
Quoted 52 lines · Quentin Schulz

Hi Hans,

Quoted 12 lines · Hans Verkuil

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 9 lines · Quentin Schulz

Some ioctls are optional and the logic around it handle it nicely, except that doioctl (via doioctl_name) sets app_result static variable to -1 if the ioctl fails.

However, both rds-ctl and v4l2-ctl exit code is from app_result. So it is possible to have those tools perform the expected task (albeit failing to use an optional ioctl) and still report to the user that it failed to do so.

Quoted 9 lines
Quoted 5 lines

Let's add a new function doioctl_opt which allows to NOT set the app_result variable when the ioctl fails.

This migrates two ioctl VIDIOC_SUBDEV_S_CLIENT_CAP and VIDIOC_SUBDEV_QUERYCAP to be optional ioctls.

Actually, those ioctls must be present, unless you run an old kernel, but they've been around since kernel 6.4.

Yes, I am using a 6.1 kernel, which is supported until Dec. 2027, c.f.
https://www.kernel.org/releases.html

5.10 is also supported until Dec. 2026.

Quoted 2 lines

I'm dropping this series as this isn't quite the way to do this.

Could you explain what is the issue with those patches so I can suggest something else?

Quoted 3 lines

Perhaps you should explain the problem you encounter first (and mention the kernel version you are using)?

Run v4l-utils on an older kernel (6.1 for example) and it'll try to use the ioctl that isn't supported. Since it's optional (the return code isn't checked directly) it'll happily actually do what's expected from it but the program will end with a non-zero exit code, thus failing my CI tests while still actually performing what it is requested to do. This is due to the failing ioctl setting app_result global variable but the failing calls not actually being checked right after in the calling function so the program continues as if everything went well but the last line of the main function (std::exit(options[OptAll] ? 0 :
app_result);) actually returns the exit code matching app_result value, which is set when the (deemed optional) ioctl fails.

Quoted 7 lines

I use v4l2-ctl to set a test pattern on a camera and now my CI simply doesn't pass anymore on Trixie because of that. For now, I ignore the exit code of v4l2-ctl -c test_pattern=1 and validate it actually was run by running v4l2-ctl -C test_pattern afterwards (but still not checking the exit code of this command as it's still returning that it failed).

Kernel is 6.1.

Isn't debian trixie on 6.12? Why are you on 6.1?

Honest question, I just want to better understand why you are on that old kernel.

Anyway, the application result is of limited use: it is never tested by me and failing on non-existing ioctls is probably not a good idea anyway. v4l2-ctl calls lots of ioctls: if present, then do A, if not, then do B (or nothing). And each time an ioctl fails fails with ENOTTY app_result would be set.

Going through the v4l2-ctl code and checking all places where an ioctl can be optional would be a substantial amount of work and is probably hard to get right.

It might be better to only set app_result if the ioctl result is < 0 && errno != ENOTTY. I.e. missing ioctls are just ignored as being 'normal' behavior. I think that's reasonable.

Regards,

Hans

#7 lore raw

Hi Hans,

Quoted 61 lines · Hans Verkuil

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 58 lines · Quentin Schulz

Hi Hans,

Quoted 12 lines · Hans Verkuil

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 9 lines · Quentin Schulz

Some ioctls are optional and the logic around it handle it nicely, except that doioctl (via doioctl_name) sets app_result static variable to -1 if the ioctl fails.

However, both rds-ctl and v4l2-ctl exit code is from app_result. So it is possible to have those tools perform the expected task (albeit failing to use an optional ioctl) and still report to the user that it failed to do so.

Quoted 9 lines
Quoted 5 lines

Let's add a new function doioctl_opt which allows to NOT set the app_result variable when the ioctl fails.

This migrates two ioctl VIDIOC_SUBDEV_S_CLIENT_CAP and VIDIOC_SUBDEV_QUERYCAP to be optional ioctls.

Actually, those ioctls must be present, unless you run an old kernel, but they've been around since kernel 6.4.

Yes, I am using a 6.1 kernel, which is supported until Dec. 2027, c.f.
https://www.kernel.org/releases.html

5.10 is also supported until Dec. 2026.

Quoted 2 lines

I'm dropping this series as this isn't quite the way to do this.

Could you explain what is the issue with those patches so I can suggest something else?

Quoted 3 lines

Perhaps you should explain the problem you encounter first (and mention the kernel version you are using)?

Run v4l-utils on an older kernel (6.1 for example) and it'll try to use the ioctl that isn't supported. Since it's optional (the return code isn't checked directly) it'll happily actually do what's expected from it but the program will end with a non-zero exit code, thus failing my CI tests while still actually performing what it is requested to do. This is due to the failing ioctl setting app_result global variable but the failing calls not actually being checked right after in the calling function so the program continues as if everything went well but the last line of the main function (std::exit(options[OptAll] ? 0 :
app_result);) actually returns the exit code matching app_result value, which is set when the (deemed optional) ioctl fails.

I use v4l2-ctl to set a test pattern on a camera and now my CI simply doesn't pass anymore on Trixie because of that. For now, I ignore the exit code of v4l2-ctl -c test_pattern=1 and validate it actually was run by running v4l2-ctl -C test_pattern afterwards (but still not checking the exit code of this command as it's still returning that it failed).

Quoted 4 lines
Quoted 1 line

Kernel is 6.1.

Isn't debian trixie on 6.12? Why are you on 6.1?

Typical embedded ARM devices setup (sadly). 6.1 is the vendor kernel with support for cameras while upstream catches up (no camera stack on RK3588 yet). So we essentially only have the userspace stack of Trixie. I mentioned Trixie but it doesn't really matter to be honest, I could be compiling v4l-utils on Yocto with that kernel if I wanted to and the issue would be the same. It just happens that our CI is running Debian at the moment.

Quoted 10 lines

Honest question, I just want to better understand why you are on that old kernel.

Anyway, the application result is of limited use: it is never tested by me and failing on non-existing ioctls is probably not a good idea anyway. v4l2-ctl calls lots of ioctls: if present, then do A, if not, then do B (or nothing). And each time an ioctl fails fails with ENOTTY app_result would be set.

Going through the v4l2-ctl code and checking all places where an ioctl can be optional would be a substantial amount of work and is probably hard to get right.

Fair.

Quoted 4 lines

It might be better to only set app_result if the ioctl result is < 0 && errno != ENOTTY. I.e. missing ioctls are just ignored as being 'normal' behavior. I think that's reasonable.

Do we want to silently ignore ENOTTY even for the return code of the doioctl function? This would make it impossible to know if the ioctl was run or doesn't exist, which I assume may be desired?

If we don't ignore ENOTTY for the return code, then we may have an issue with app_result not being set (so = 0) but the return code of the function being != 0. Then we would need to check that no existing call of doioctl is relying on the app_result variable for the exit code of the program when this happens. I'm thinking something along the lines of

if (doioctl(foo...)

    goto exit;
[...]
exit:
    std::exit(app_result);

This would be an issue for example.

Let's agree on the way forward and then I can try to figure out if there are such cases and how to handle them.

Cheers,
Quentin

#8 lore raw
Quoted 90 lines · Quentin Schulz

Hi Hans,

Quoted 61 lines · Hans Verkuil

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 58 lines · Quentin Schulz

Hi Hans,

Quoted 12 lines · Hans Verkuil

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 9 lines · Quentin Schulz

Some ioctls are optional and the logic around it handle it nicely, except that doioctl (via doioctl_name) sets app_result static variable to -1 if the ioctl fails.

However, both rds-ctl and v4l2-ctl exit code is from app_result. So it is possible to have those tools perform the expected task (albeit failing to use an optional ioctl) and still report to the user that it failed to do so.

Quoted 9 lines
Quoted 5 lines

Let's add a new function doioctl_opt which allows to NOT set the app_result variable when the ioctl fails.

This migrates two ioctl VIDIOC_SUBDEV_S_CLIENT_CAP and VIDIOC_SUBDEV_QUERYCAP to be optional ioctls.

Actually, those ioctls must be present, unless you run an old kernel, but they've been around since kernel 6.4.

Yes, I am using a 6.1 kernel, which is supported until Dec. 2027, c.f.
https://www.kernel.org/releases.html

5.10 is also supported until Dec. 2026.

Quoted 2 lines

I'm dropping this series as this isn't quite the way to do this.

Could you explain what is the issue with those patches so I can suggest something else?

Quoted 3 lines

Perhaps you should explain the problem you encounter first (and mention the kernel version you are using)?

Run v4l-utils on an older kernel (6.1 for example) and it'll try to use the ioctl that isn't supported. Since it's optional (the return code isn't checked directly) it'll happily actually do what's expected from it but the program will end with a non-zero exit code, thus failing my CI tests while still actually performing what it is requested to do. This is due to the failing ioctl setting app_result global variable but the failing calls not actually being checked right after in the calling function so the program continues as if everything went well but the last line of the main function (std::exit(options[OptAll] ? 0 :
app_result);) actually returns the exit code matching app_result value, which is set when the (deemed optional) ioctl fails.

I use v4l2-ctl to set a test pattern on a camera and now my CI simply doesn't pass anymore on Trixie because of that. For now, I ignore the exit code of v4l2-ctl -c test_pattern=1 and validate it actually was run by running v4l2-ctl -C test_pattern afterwards (but still not checking the exit code of this command as it's still returning that it failed).

Quoted 4 lines
Quoted 1 line

Kernel is 6.1.

Isn't debian trixie on 6.12? Why are you on 6.1?

Typical embedded ARM devices setup (sadly). 6.1 is the vendor kernel with support for cameras while upstream catches up (no camera stack on RK3588 yet). So we essentially only have the userspace stack of Trixie. I mentioned Trixie but it doesn't really matter to be honest, I could be compiling v4l-utils on Yocto with that kernel if I wanted to and the issue would be the same. It just happens that our CI is running Debian at the moment.

Quoted 10 lines

Honest question, I just want to better understand why you are on that old kernel.

Anyway, the application result is of limited use: it is never tested by me and failing on non-existing ioctls is probably not a good idea anyway. v4l2-ctl calls lots of ioctls: if present, then do A, if not, then do B (or nothing). And each time an ioctl fails fails with ENOTTY app_result would be set.

Going through the v4l2-ctl code and checking all places where an ioctl can be optional would be a substantial amount of work and is probably hard to get right.

Fair.

Quoted 8 lines
Quoted 4 lines

It might be better to only set app_result if the ioctl result is < 0 && errno != ENOTTY. I.e. missing ioctls are just ignored as being 'normal' behavior. I think that's reasonable.

Do we want to silently ignore ENOTTY even for the return code of the doioctl function? This would make it impossible to know if the ioctl was run or doesn't exist, which I assume may be desired?

No, the idea was to just ignore ENOTTY when it comes to setting app_result. But I don't think that's the right approach.

I looked a bit more closely at the code, and I think the right thing to do is to use test_ioctl() instead of doioctl for those cases where an ioctl might fail.

That's already the case for ENUM ioctls (since they return EINVAL when the index reaches the end of the enumeration), and so this can also be used for VIDIOC_SUBDEV_QUERYCAP and VIDIOC_SUBDEV_S_CLIENT_CAP.

So make a patch for that and mention in a comment that VIDIOC_SUBDEV_S_CLIENT_CAP was introduced in v6.4.

No need to create a doioctl_opt, since basically that's what test_ioctl already does.

Regards,

Hans

Quoted 20 lines

If we don't ignore ENOTTY for the return code, then we may have an issue with app_result not being set (so = 0) but the return code of the function being != 0. Then we would need to check that no existing call of doioctl is relying on the app_result variable for the exit code of the program when this happens. I'm thinking something along the lines of

if (doioctl(foo...)

     goto exit;
[...]
exit:
     std::exit(app_result);

This would be an issue for example.

Let's agree on the way forward and then I can try to figure out if there are such cases and how to handle them.

Cheers,
Quentin

#9 lore raw
Quoted 100 lines · Hans Verkuil
Quoted 90 lines · Quentin Schulz

Hi Hans,

Quoted 61 lines · Hans Verkuil

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 58 lines · Quentin Schulz

Hi Hans,

Quoted 12 lines · Hans Verkuil

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 9 lines · Quentin Schulz

Some ioctls are optional and the logic around it handle it nicely, except that doioctl (via doioctl_name) sets app_result static variable to -1 if the ioctl fails.

However, both rds-ctl and v4l2-ctl exit code is from app_result. So it is possible to have those tools perform the expected task (albeit failing to use an optional ioctl) and still report to the user that it failed to do so.

Quoted 9 lines
Quoted 5 lines

Let's add a new function doioctl_opt which allows to NOT set the app_result variable when the ioctl fails.

This migrates two ioctl VIDIOC_SUBDEV_S_CLIENT_CAP and VIDIOC_SUBDEV_QUERYCAP to be optional ioctls.

Actually, those ioctls must be present, unless you run an old kernel, but they've been around since kernel 6.4.

Yes, I am using a 6.1 kernel, which is supported until Dec. 2027, c.f.
https://www.kernel.org/releases.html

5.10 is also supported until Dec. 2026.

Quoted 2 lines

I'm dropping this series as this isn't quite the way to do this.

Could you explain what is the issue with those patches so I can suggest something else?

Quoted 3 lines

Perhaps you should explain the problem you encounter first (and mention the kernel version you are using)?

Run v4l-utils on an older kernel (6.1 for example) and it'll try to use the ioctl that isn't supported. Since it's optional (the return code isn't checked directly) it'll happily actually do what's expected from it but the program will end with a non-zero exit code, thus failing my CI tests while still actually performing what it is requested to do. This is due to the failing ioctl setting app_result global variable but the failing calls not actually being checked right after in the calling function so the program continues as if everything went well but the last line of the main function (std::exit(options[OptAll] ? 0 :
app_result);) actually returns the exit code matching app_result value, which is set when the (deemed optional) ioctl fails.

I use v4l2-ctl to set a test pattern on a camera and now my CI simply doesn't pass anymore on Trixie because of that. For now, I ignore the exit code of v4l2-ctl -c test_pattern=1 and validate it actually was run by running v4l2-ctl -C test_pattern afterwards (but still not checking the exit code of this command as it's still returning that it failed).

Quoted 4 lines
Quoted 1 line

Kernel is 6.1.

Isn't debian trixie on 6.12? Why are you on 6.1?

Typical embedded ARM devices setup (sadly). 6.1 is the vendor kernel with support for cameras while upstream catches up (no camera stack on RK3588 yet). So we essentially only have the userspace stack of Trixie. I mentioned Trixie but it doesn't really matter to be honest, I could be compiling v4l-utils on Yocto with that kernel if I wanted to and the issue would be the same. It just happens that our CI is running Debian at the moment.

Quoted 10 lines

Honest question, I just want to better understand why you are on that old kernel.

Anyway, the application result is of limited use: it is never tested by me and failing on non-existing ioctls is probably not a good idea anyway. v4l2-ctl calls lots of ioctls: if present, then do A, if not, then do B (or nothing). And each time an ioctl fails fails with ENOTTY app_result would be set.

Going through the v4l2-ctl code and checking all places where an ioctl can be optional would be a substantial amount of work and is probably hard to get right.

Fair.

Quoted 8 lines
Quoted 4 lines

It might be better to only set app_result if the ioctl result is < 0 && errno != ENOTTY. I.e. missing ioctls are just ignored as being 'normal' behavior. I think that's reasonable.

Do we want to silently ignore ENOTTY even for the return code of the doioctl function? This would make it impossible to know if the ioctl was run or doesn't exist, which I assume may be desired?

Quoted 6 lines

No, the idea was to just ignore ENOTTY when it comes to setting app_result. But I don't think that's the right approach.

I looked a bit more closely at the code, and I think the right thing to do is to use test_ioctl() instead of doioctl for those cases where an ioctl might fail.

This means we won't have logging of the failing (deemed optional) ioctl that doioctl_name does for example. Which is one of the reasons why I went for a new doioctl_opt in the first place. Another reason is that if the ioctl fails with something else than ENOTTY, each caller of the test_ioctl would be responsible for ignoring ENOTTY but handle the rest of the error code (and possibly printing logs). Which I felt was something we could avoid.

Quoted 9 lines

That's already the case for ENUM ioctls (since they return EINVAL when the index reaches the end of the enumeration), and so this can also be used for VIDIOC_SUBDEV_QUERYCAP and VIDIOC_SUBDEV_S_CLIENT_CAP.

So make a patch for that and mention in a comment that VIDIOC_SUBDEV_S_CLIENT_CAP was introduced in v6.4.

No need to create a doioctl_opt, since basically that's what test_ioctl already does.

but keeps printing logs on failing ioctls.

Up to you, just wanted to give all my arguments for a new wrapper around test_ioctl before replacing doioctl() with test_ioctl().

Cheers,
Quentin

#10 lore raw
Quoted 123 lines · Quentin Schulz
Quoted 100 lines · Hans Verkuil
Quoted 90 lines · Quentin Schulz

Hi Hans,

Quoted 61 lines · Hans Verkuil

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 58 lines · Quentin Schulz

Hi Hans,

Quoted 12 lines · Hans Verkuil

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Quoted 9 lines · Quentin Schulz

Some ioctls are optional and the logic around it handle it nicely, except that doioctl (via doioctl_name) sets app_result static variable to -1 if the ioctl fails.

However, both rds-ctl and v4l2-ctl exit code is from app_result. So it is possible to have those tools perform the expected task (albeit failing to use an optional ioctl) and still report to the user that it failed to do so.

Quoted 9 lines
Quoted 5 lines

Let's add a new function doioctl_opt which allows to NOT set the app_result variable when the ioctl fails.

This migrates two ioctl VIDIOC_SUBDEV_S_CLIENT_CAP and VIDIOC_SUBDEV_QUERYCAP to be optional ioctls.

Actually, those ioctls must be present, unless you run an old kernel, but they've been around since kernel 6.4.

Yes, I am using a 6.1 kernel, which is supported until Dec. 2027, c.f.
https://www.kernel.org/releases.html

5.10 is also supported until Dec. 2026.

Quoted 2 lines

I'm dropping this series as this isn't quite the way to do this.

Could you explain what is the issue with those patches so I can suggest something else?

Quoted 3 lines

Perhaps you should explain the problem you encounter first (and mention the kernel version you are using)?

Run v4l-utils on an older kernel (6.1 for example) and it'll try to use the ioctl that isn't supported. Since it's optional (the return code isn't checked directly) it'll happily actually do what's expected from it but the program will end with a non-zero exit code, thus failing my CI tests while still actually performing what it is requested to do. This is due to the failing ioctl setting app_result global variable but the failing calls not actually being checked right after in the calling function so the program continues as if everything went well but the last line of the main function (std::exit(options[OptAll] ? 0 :
app_result);) actually returns the exit code matching app_result value, which is set when the (deemed optional) ioctl fails.

I use v4l2-ctl to set a test pattern on a camera and now my CI simply doesn't pass anymore on Trixie because of that. For now, I ignore the exit code of v4l2-ctl -c test_pattern=1 and validate it actually was run by running v4l2-ctl -C test_pattern afterwards (but still not checking the exit code of this command as it's still returning that it failed).

Quoted 4 lines
Quoted 1 line

Kernel is 6.1.

Isn't debian trixie on 6.12? Why are you on 6.1?

Typical embedded ARM devices setup (sadly). 6.1 is the vendor kernel with support for cameras while upstream catches up (no camera stack on RK3588 yet). So we essentially only have the userspace stack of Trixie. I mentioned Trixie but it doesn't really matter to be honest, I could be compiling v4l-utils on Yocto with that kernel if I wanted to and the issue would be the same. It just happens that our CI is running Debian at the moment.

Quoted 10 lines

Honest question, I just want to better understand why you are on that old kernel.

Anyway, the application result is of limited use: it is never tested by me and failing on non-existing ioctls is probably not a good idea anyway. v4l2-ctl calls lots of ioctls: if present, then do A, if not, then do B (or nothing). And each time an ioctl fails fails with ENOTTY app_result would be set.

Going through the v4l2-ctl code and checking all places where an ioctl can be optional would be a substantial amount of work and is probably hard to get right.

Fair.

Quoted 8 lines
Quoted 4 lines

It might be better to only set app_result if the ioctl result is < 0 && errno != ENOTTY. I.e. missing ioctls are just ignored as being 'normal' behavior. I think that's reasonable.

Do we want to silently ignore ENOTTY even for the return code of the doioctl function? This would make it impossible to know if the ioctl was run or doesn't exist, which I assume may be desired?

Quoted 6 lines

No, the idea was to just ignore ENOTTY when it comes to setting app_result. But I don't think that's the right approach.

I looked a bit more closely at the code, and I think the right thing to do is to use test_ioctl() instead of doioctl for those cases where an ioctl might fail.

This means we won't have logging of the failing (deemed optional) ioctl that doioctl_name does for example. Which is one of the reasons why I went for a new doioctl_opt in the first place. Another reason is that if the ioctl fails with something else than ENOTTY, each caller of the test_ioctl would be responsible for ignoring ENOTTY but handle the rest of the error code (and possibly printing logs). Which I felt was something we could avoid.

Quoted 7 lines

That's already the case for ENUM ioctls (since they return EINVAL when the index reaches the end of the enumeration), and so this can also be used for VIDIOC_SUBDEV_QUERYCAP and VIDIOC_SUBDEV_S_CLIENT_CAP.

So make a patch for that and mention in a comment that VIDIOC_SUBDEV_S_CLIENT_CAP was introduced in v6.4.

Quoted 7 lines
Quoted 2 lines

No need to create a doioctl_opt, since basically that's what test_ioctl already does.

but keeps printing logs on failing ioctls.

Up to you, just wanted to give all my arguments for a new wrapper around test_ioctl before replacing doioctl() with test_ioctl().

Not worth the effort :-)

We're talking about just two specific ioctls here, so just use test_ioctl instead of doioctl.

Regards,

Hans

Quoted 3 lines

Cheers,
Quentin