diff mbox series

[net] selftests/net: fix clang issues for target arch PowerPC and others

Message ID 20200724181757.2331172-1-tannerlove.kernel@gmail.com
State Changes Requested
Delegated to: David Miller
Headers show
Series [net] selftests/net: fix clang issues for target arch PowerPC and others | expand

Commit Message

Tanner Love July 24, 2020, 6:17 p.m. UTC
From: Tanner Love <tannerlove@google.com>

Address these warnings observed with clang 9.

rxtimestamp:
The signedness of char is implementation-dependent. Some systems
(including PowerPC and ARM) use unsigned char.
Compilation yielded:
warning: result of comparison of constant -1 with expression of type \
'char' is always true [-Wtautological-constant-out-of-range-compare]
                                  &arg_index)) != -1) {

psock_fanout:
Compilation yielded warnings like:
warning: format specifies type 'unsigned short' but the argument has \
type 'int' [-Wformat]
                typeflags, PORT_BASE, PORT_BASE + port_off);

so_txtime:
On powerpcle, int64_t maps to long long.
Compilation yielded:
warning: absolute value function 'labs' given an argument of type \
'long long' but has parameter of type 'long' which may cause \
truncation of value [-Wabsolute-value]
        if (labs(tstop - texpect) > cfg_variance_us)

tcp_mmap:
Compilation yielded:
warning: result of comparison of constant 34359738368 with \
expression of type 'size_t' (aka 'unsigned int') is always true \
[-Wtautological-constant-out-of-range-compare]
        while (total < FILE_SZ) {

Tested: make -C tools/testing/selftests TARGETS="net" run_tests

Fixes: 16e781224198 ("selftests/net: Add a test to validate behavior of rx timestamps")
Fixes: af5136f95045 ("selftests/net: SO_TXTIME with ETF and FQ")
Fixes: 77f65ebdca50 ("packet: packet fanout rollover during socket overload")
Fixes: 192dc405f308 ("selftests: net: add tcp_mmap program")
Signed-off-by: Tanner Love <tannerlove@google.com>
Acked-by: Willem de Bruijn <willemb@google.com>
---
 tools/testing/selftests/net/psock_fanout.c | 3 ++-
 tools/testing/selftests/net/rxtimestamp.c  | 3 +--
 tools/testing/selftests/net/so_txtime.c    | 2 +-
 tools/testing/selftests/net/tcp_mmap.c     | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

Comments

Eric Dumazet July 24, 2020, 7:01 p.m. UTC | #1
On 7/24/20 11:17 AM, Tanner Love wrote:
> From: Tanner Love <tannerlove@google.com>
> 
> Address these warnings observed with clang 9.
> 
> 
> tcp_mmap:
> Compilation yielded:
> warning: result of comparison of constant 34359738368 with \
> expression of type 'size_t' (aka 'unsigned int') is always true \

size_t is not generally 'unsigned int', not sure how you get this ?

> [-Wtautological-constant-out-of-range-compare]
>         while (total < FILE_SZ) {
> 
> Tested: make -C tools/testing/selftests TARGETS="net" run_tests
> 
>


> diff --git a/tools/testing/selftests/net/tcp_mmap.c b/tools/testing/selftests/net/tcp_mmap.c
> index 4555f88252ba..92086d65bd87 100644
> --- a/tools/testing/selftests/net/tcp_mmap.c
> +++ b/tools/testing/selftests/net/tcp_mmap.c
> @@ -344,7 +344,7 @@ int main(int argc, char *argv[])
>  {
>  	struct sockaddr_storage listenaddr, addr;
>  	unsigned int max_pacing_rate = 0;
> -	size_t total = 0;
> +	unsigned long total = 0;
>  	char *host = NULL;
>  	int fd, c, on = 1;
>  	char *buffer;
> 

This will break on 32bit arches, where sizeof(unsigned long) == 4
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/psock_fanout.c b/tools/testing/selftests/net/psock_fanout.c
index 8c8c7d79c38d..2c522f7a0aec 100644
--- a/tools/testing/selftests/net/psock_fanout.c
+++ b/tools/testing/selftests/net/psock_fanout.c
@@ -350,7 +350,8 @@  static int test_datapath(uint16_t typeflags, int port_off,
 	int fds[2], fds_udp[2][2], ret;
 
 	fprintf(stderr, "\ntest: datapath 0x%hx ports %hu,%hu\n",
-		typeflags, PORT_BASE, PORT_BASE + port_off);
+		typeflags, (uint16_t)PORT_BASE,
+		(uint16_t)(PORT_BASE + port_off));
 
 	fds[0] = sock_fanout_open(typeflags, 0);
 	fds[1] = sock_fanout_open(typeflags, 0);
diff --git a/tools/testing/selftests/net/rxtimestamp.c b/tools/testing/selftests/net/rxtimestamp.c
index 422e7761254d..bcb79ba1f214 100644
--- a/tools/testing/selftests/net/rxtimestamp.c
+++ b/tools/testing/selftests/net/rxtimestamp.c
@@ -329,8 +329,7 @@  int main(int argc, char **argv)
 	bool all_tests = true;
 	int arg_index = 0;
 	int failures = 0;
-	int s, t;
-	char opt;
+	int s, t, opt;
 
 	while ((opt = getopt_long(argc, argv, "", long_options,
 				  &arg_index)) != -1) {
diff --git a/tools/testing/selftests/net/so_txtime.c b/tools/testing/selftests/net/so_txtime.c
index ceaad78e9667..3155fbbf644b 100644
--- a/tools/testing/selftests/net/so_txtime.c
+++ b/tools/testing/selftests/net/so_txtime.c
@@ -121,7 +121,7 @@  static bool do_recv_one(int fdr, struct timed_send *ts)
 	if (rbuf[0] != ts->data)
 		error(1, 0, "payload mismatch. expected %c", ts->data);
 
-	if (labs(tstop - texpect) > cfg_variance_us)
+	if (llabs(tstop - texpect) > cfg_variance_us)
 		error(1, 0, "exceeds variance (%d us)", cfg_variance_us);
 
 	return false;
diff --git a/tools/testing/selftests/net/tcp_mmap.c b/tools/testing/selftests/net/tcp_mmap.c
index 4555f88252ba..92086d65bd87 100644
--- a/tools/testing/selftests/net/tcp_mmap.c
+++ b/tools/testing/selftests/net/tcp_mmap.c
@@ -344,7 +344,7 @@  int main(int argc, char *argv[])
 {
 	struct sockaddr_storage listenaddr, addr;
 	unsigned int max_pacing_rate = 0;
-	size_t total = 0;
+	unsigned long total = 0;
 	char *host = NULL;
 	int fd, c, on = 1;
 	char *buffer;