Skip to contentSkip to conversation

Use correct ioctl request for termios

PATCH Superseded Marius Kittler 2 participants 4 messages Sep 4, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use correct ioctl request for termios

With the termios struct one is supposed to use TCGETS instead of TCGETA, see man ioctl_tty.

Related issue: https://github.com/linux-test-project/ltp/issues/637#issuecomment-1705334874

---
 testcases/kernel/syscalls/ioctl/ioctl01.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
testcases/kernel/syscalls/ioctl/ioctl01.c +10 -9
index 1be38e79d..983208925 100644
@@ -36,34 +36,35 @@ static struct termios termios;
 
 static struct tcase {
 	int *fd;
-	int request;
+	int request_tio;
+	int request_tios;
 	struct termio *s_tio;
 	struct termios *s_tios;
 	int error;
 } tcases[] = {
 	/* file descriptor is invalid */
-	{&bfd, TCGETA, &termio, &termios, EBADF},
+	{&bfd, TCGETA, TCGETS, &termio, &termios, EBADF},
 	/* termio address is invalid */
-	{&fd, TCGETA, (struct termio *)-1, (struct termios *)-1, EFAULT},
-	/* command is invalid */
+	{&fd, TCGETA, TCGETS, (struct termio *)-1, (struct termios *)-1, EFAULT},
+	// /* command is invalid */
 	/* This errno value was changed from EINVAL to ENOTTY
 	 * by kernel commit 07d106d0 and bbb63c51
 	 */
-	{&fd, INVAL_IOCTL, &termio, &termios, ENOTTY},
+	{&fd, INVAL_IOCTL, INVAL_IOCTL, &termio, &termios, ENOTTY},
 	/* file descriptor is for a regular file */
-	{&fd_file, TCGETA, &termio, &termios, ENOTTY},
+	{&fd_file, TCGETA, TCGETS, &termio, &termios, ENOTTY},
 	/* termio is NULL */
-	{&fd, TCGETA, NULL, NULL, EFAULT}
+	{&fd, TCGETA, TCGETS, NULL, NULL, EFAULT}
 };
 
 static char *device;
 
 static void verify_ioctl(unsigned int i)
 {
-	TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request, tcases[i].s_tio),
+	TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request_tio, tcases[i].s_tio),
 		     tcases[i].error);
 
-	TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request, tcases[i].s_tios),
+	TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request_tios, tcases[i].s_tios),
 		     tcases[i].error);
 }
 
Signature · 5 lines
2.41.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 8 lines
 testcases/kernel/syscalls/ioctl/ioctl01.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
testcases/kernel/syscalls/ioctl/ioctl01.c +0 -0
index 1be38e79d..983208925 100644

testcases/kernel/syscalls/ioctl/ioctl01.c static struct termios termios; · line 43

Quoted 9 lines
testcases/kernel/syscalls/ioctl/ioctl01.c +2 -1
@@ -36,34 +36,35 @@ static struct termios termios;
 
 static struct tcase {
 	int *fd;
-	int request;
+	int request_tio;
+	int request_tios;
 	struct termio *s_tio;
 	struct termios *s_tios;
 	int error;

I guess that it would be cleaner to keep the single request, but define the s_tio as a void * here.

That way we can add test on a separate lines:

	{&bfd, TCGETA, &termio, EBADF},
	{&bfd, TCGETS, &termios, EBADF},
	...

And have single TST_EXP_FAIL() in the verify function.

Quoted 41 lines
testcases/kernel/syscalls/ioctl/ioctl01.c +8 -8
 } tcases[] = {
 	/* file descriptor is invalid */
-	{&bfd, TCGETA, &termio, &termios, EBADF},
+	{&bfd, TCGETA, TCGETS, &termio, &termios, EBADF},
 	/* termio address is invalid */
-	{&fd, TCGETA, (struct termio *)-1, (struct termios *)-1, EFAULT},
-	/* command is invalid */
+	{&fd, TCGETA, TCGETS, (struct termio *)-1, (struct termios *)-1, EFAULT},
+	// /* command is invalid */
 	/* This errno value was changed from EINVAL to ENOTTY
 	 * by kernel commit 07d106d0 and bbb63c51
 	 */
-	{&fd, INVAL_IOCTL, &termio, &termios, ENOTTY},
+	{&fd, INVAL_IOCTL, INVAL_IOCTL, &termio, &termios, ENOTTY},
 	/* file descriptor is for a regular file */
-	{&fd_file, TCGETA, &termio, &termios, ENOTTY},
+	{&fd_file, TCGETA, TCGETS, &termio, &termios, ENOTTY},
 	/* termio is NULL */
-	{&fd, TCGETA, NULL, NULL, EFAULT}
+	{&fd, TCGETA, TCGETS, NULL, NULL, EFAULT}
 };
 
 static char *device;
 
 static void verify_ioctl(unsigned int i)
 {
-	TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request, tcases[i].s_tio),
+	TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request_tio, tcases[i].s_tio),
 		     tcases[i].error);
 
-	TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request, tcases[i].s_tios),
+	TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request_tios, tcases[i].s_tios),
 		     tcases[i].error);
 }
 
Signature · 5 lines
2.41.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Am Montag, 4. September 2023, 17:04:51 CEST schrieb Cyril Hrubis:

Quoted 10 lines

I guess that it would be cleaner to keep the single request, but define the s_tio as a void * here.

That way we can add test on a separate lines:

	{&bfd, TCGETA, &termio, EBADF},
	{&bfd, TCGETS, &termios, EBADF},
	...

But we have currently 4 tests that are all executed via both termio and termios. To keep this kind of coverage we would need to duplicate all of those lines. That would be 4 new test lines in total. Is that what you're suggesting? I'm just asking twice because I'm not sure whether it is better (but don't have a strong opinion).

By the way, how would I submit an amendment here? Just submit the amended commit again in the same way (I used git send-email -- [email protected])?

And how is this merged? I saw that in another case patchwork was used? How does that come into play?

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 5 lines

But we have currently 4 tests that are all executed via both termio and termios. To keep this kind of coverage we would need to duplicate all of those lines. That would be 4 new test lines in total. Is that what you're suggesting? I'm just asking twice because I'm not sure whether it is better (but don't have a strong opinion).

Yes, as far as I can tell one test per entry is much cleaner and easier to read.

Quoted 3 lines

By the way, how would I submit an amendment here? Just submit the amended commit again in the same way (I used git send-email -- [email protected])?

Yes, and you are supposed to version the commits, so add to format-patch -v2 for second version, etc.

Quoted 2 lines

And how is this merged? I saw that in another case patchwork was used? How does that come into play?

Things get merged by maintainers who apply the patch to their local git tree and then push to github. Patchwork is just a tool that monitors the mailing list and saves a list of patches that needs review, which makes things easier for developers as it's easy for patches to get burried in their mailboxes.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp