[PATCH net-next 2/2] selftests: net: improve error handling in passive TFO test

Yohei Kojima posted 2 patches 3 weeks, 6 days ago
There is a newer version of this series
[PATCH net-next 2/2] selftests: net: improve error handling in passive TFO test
Posted by Yohei Kojima 3 weeks, 6 days ago
This commit improves the error handling in passive TFO test to check the
return value from sendto(), and  to fail if read() failed.

Signed-off-by: Yohei Kojima <yk@y-koj.net>
---
 tools/testing/selftests/net/tfo.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/net/tfo.c b/tools/testing/selftests/net/tfo.c
index 8d82140f0f76..4572eb9b8968 100644
--- a/tools/testing/selftests/net/tfo.c
+++ b/tools/testing/selftests/net/tfo.c
@@ -82,7 +82,8 @@ static void run_server(void)
 		error(1, errno, "getsockopt(SO_INCOMING_NAPI_ID)");
 
 	if (read(connfd, buf, 64) < 0)
-		perror("read()");
+		error(1, errno, "read()");
+
 	fprintf(outfile, "%d\n", opt);
 
 	fclose(outfile);
@@ -92,14 +93,17 @@ static void run_server(void)
 
 static void run_client(void)
 {
-	int fd;
+	int fd, ret;
 	char *msg = "Hello, world!";
 
 	fd = socket(AF_INET6, SOCK_STREAM, 0);
 	if (fd == -1)
 		error(1, errno, "socket()");
 
-	sendto(fd, msg, strlen(msg), MSG_FASTOPEN, (struct sockaddr *)&cfg_addr, sizeof(cfg_addr));
+	ret = sendto(fd, msg, strlen(msg), MSG_FASTOPEN,
+		     (struct sockaddr *)&cfg_addr, sizeof(cfg_addr));
+	if (ret < 0)
+		error(1, errno, "sendto()");
 
 	close(fd);
 }
-- 
2.52.0
Re: [PATCH net-next 2/2] selftests: net: improve error handling in passive TFO test
Posted by Markus Elfring 3 weeks, 5 days ago
> This commit improves the error handling in passive TFO test to check the
> return value from … and  to fail if read() failed.

Would any developers and system testers like to care more also for data output failures?
https://elixir.bootlin.com/linux/v6.19-rc4/source/tools/testing/selftests/net/tfo.c#L86-L88
https://cwe.mitre.org/data/definitions/252.html

Regards,
Markus
Re: [PATCH net-next 2/2] selftests: net: improve error handling in passive TFO test
Posted by Yohei Kojima 3 weeks, 5 days ago
On Tue, Jan 13, 2026 at 10:46:10AM +0100, Markus Elfring wrote:
> > This commit improves the error handling in passive TFO test to check the
> > return value from … and  to fail if read() failed.
> 
> Would any developers and system testers like to care more also for data output failures?
> https://elixir.bootlin.com/linux/v6.19-rc4/source/tools/testing/selftests/net/tfo.c#L86-L88
> https://cwe.mitre.org/data/definitions/252.html

That's right. Although we can assume that fprintf() usually succeeds,
it worth checking its return value as tfo_passive.sh relies on the
content of the output.

I posted the v2 series adding fprintf() error handling here:
https://lore.kernel.org/netdev/cover.1768312014.git.yk@y-koj.net/

Thank you,
Yohei

> 
> Regards,
> Markus
Re: [PATCH net-next 2/2] selftests: net: improve error handling in passive TFO test
Posted by Markus Elfring 3 weeks, 5 days ago
> This commit improves the error handling in …

See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc4#n94

Regards,
Markus
Re: [PATCH net-next 2/2] selftests: net: improve error handling in passive TFO test
Posted by Yohei Kojima 3 weeks, 5 days ago
On Mon, Jan 12, 2026 at 08:55:10PM +0100, Markus Elfring wrote:
> > This commit improves the error handling in …
> 
> See also once more:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc4#n94

Thank you for the feedback. I will rephrase the patch description in
imperative mood as suggested.

(I also found a typo "cliend", which will be fixed in v2 too.)

> 
> Regards,
> Markus