Skip to contentSkip to conversation

selftests/net: Fix clang warnings on powerpc

PATCH In review Tanner Love 3 participants 7 messages Jul 27, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover selftests/net: Fix clang warnings on powerpc

From: Tanner Love <[email protected]>

This is essentially a v2 of http://patchwork.ozlabs.org/project/netdev/patch/[email protected]/, but it has been split up in order to have only one "Fixes" tag per patch.

Tanner Love (4):
selftests/net: rxtimestamp: fix clang issues for target arch PowerPC selftests/net: psock_fanout: fix clang issues for target arch PowerPC selftests/net: so_txtime: fix clang issues for target arch PowerPC selftests/net: tcp_mmap: fix clang warning for target arch PowerPC

 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     | 6 +++---
 4 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
2.28.0.rc0.142.g3c755180ce-goog
#2 lore raw

PATCH 2/4 selftests/net: psock_fanout: fix clang issues for target arch PowerPC

From: Tanner Love <[email protected]>

Clang 9 threw:
warning: format specifies type 'unsigned short' but the argument has \
type 'int' [-Wformat]

                typeflags, PORT_BASE, PORT_BASE + port_off);

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

Fixes 77f65ebdca50 ("packet: packet fanout rollover during socket overload")
---
 tools/testing/selftests/net/psock_fanout.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/net/psock_fanout.c +2 -1
index 8c8c7d79c38d..2c522f7a0aec 100644
@@ -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);
Signature · 1 line
2.28.0.rc0.142.g3c755180ce-goog
#1 lore raw

PATCH 1/4 selftests/net: rxtimestamp: fix clang issues for target arch PowerPC

In reply to Tanner Love

From: Tanner Love <[email protected]>

The signedness of char is implementation-dependent. Some systems (including PowerPC and ARM) use unsigned char. Clang 9 threw:
warning: result of comparison of constant -1 with expression of type \
'char' is always true [-Wtautological-constant-out-of-range-compare]

                                  &arg_index)) != -1) {

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

Fixes 16e781224198 ("selftests/net: Add a test to validate behavior of rx timestamps")
---
 tools/testing/selftests/net/rxtimestamp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/net/rxtimestamp.c +1 -2
index 422e7761254d..bcb79ba1f214 100644
@@ -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) {
Signature · 1 line
2.28.0.rc0.142.g3c755180ce-goog
#3 lore raw

PATCH 3/4 selftests/net: so_txtime: fix clang issues for target arch PowerPC

In reply to Tanner Love

From: Tanner Love <[email protected]>

On powerpcle, int64_t maps to long long. Clang 9 threw:
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)

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

Fixes af5136f95045 ("selftests/net: SO_TXTIME with ETF and FQ")
---
 tools/testing/selftests/net/so_txtime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/so_txtime.c +1 -1
index ceaad78e9667..3155fbbf644b 100644
@@ -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;
Signature · 1 line
2.28.0.rc0.142.g3c755180ce-goog
#4 lore raw

PATCH 4/4 selftests/net: tcp_mmap: fix clang warning for target arch PowerPC

In reply to Tanner Love

From: Tanner Love <[email protected]>

When size_t maps to unsigned int (e.g. on 32-bit powerpc), then the comparison with 1<<35 is always true. Clang 9 threw:
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 192dc405f308 ("selftests: net: add tcp_mmap program")
---
 tools/testing/selftests/net/tcp_mmap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/net/tcp_mmap.c +3 -3
index 4555f88252ba..a61b7b3da549 100644
@@ -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;
+	uint64_t total = 0;
 	char *host = NULL;
 	int fd, c, on = 1;
 	char *buffer;
@@ -473,12 +473,12 @@ int main(int argc, char *argv[])
 		zflg = 0;
 	}
 	while (total < FILE_SZ) {
-		ssize_t wr = FILE_SZ - total;
+		int64_t wr = FILE_SZ - total;
 
 		if (wr > chunk_size)
 			wr = chunk_size;
 		/* Note : we just want to fill the pipe with 0 bytes */
-		wr = send(fd, buffer, wr, zflg ? MSG_ZEROCOPY : 0);
+		wr = send(fd, buffer, (size_t)wr, zflg ? MSG_ZEROCOPY : 0);
 		if (wr <= 0)
 			break;
 		total += wr;
Signature · 1 line
2.28.0.rc0.142.g3c755180ce-goog
Reviewed-by on v1 4/4
#5 lore raw

Re: [PATCH net 4/4] selftests/net: tcp_mmap: fix clang warning for target arch PowerPC

Quoted 7 lines · Tanner Love

From: Tanner Love <[email protected]>

When size_t maps to unsigned int (e.g. on 32-bit powerpc), then the comparison with 1<<35 is always true. Clang 9 threw:
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]

Quoted 7 lines
        while (total < FILE_SZ) {

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

Fixes 192dc405f308 ("selftests: net: add tcp_mmap program")

Thanks !