From d4f09c9b96c68a1c6b1387cd5674cd331a939f27 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Thu, 7 Nov 2024 19:04:44 +0100 Subject: [PATCH] util: Define small and big thresholds for socket buffers as unsigned long long On 32-bit architectures, clang-tidy reports: /home/pi/passt/tcp.c:728:11: error: performing an implicit widening conversion to type 'uint64_t' (aka 'unsigned long long') of a multiplication performed in type 'unsigned long' [bugprone-implicit-widening-of-multiplication-result,-warnings-as-errors] 728 | if (v >= SNDBUF_BIG) | ^ /home/pi/passt/util.h:158:22: note: expanded from macro 'SNDBUF_BIG' 158 | #define SNDBUF_BIG (4UL * 1024 * 1024) | ^ /home/pi/passt/tcp.c:728:11: note: make conversion explicit to silence this warning 728 | if (v >= SNDBUF_BIG) | ^ /home/pi/passt/util.h:158:22: note: expanded from macro 'SNDBUF_BIG' 158 | #define SNDBUF_BIG (4UL * 1024 * 1024) | ^~~~~~~~~~~~~~~~~ /home/pi/passt/tcp.c:728:11: note: perform multiplication in a wider type 728 | if (v >= SNDBUF_BIG) | ^ /home/pi/passt/util.h:158:22: note: expanded from macro 'SNDBUF_BIG' 158 | #define SNDBUF_BIG (4UL * 1024 * 1024) | ^~~~~~~~~~ /home/pi/passt/tcp.c:730:15: error: performing an implicit widening conversion to type 'uint64_t' (aka 'unsigned long long') of a multiplication performed in type 'unsigned long' [bugprone-implicit-widening-of-multiplication-result,-warnings-as-errors] 730 | else if (v > SNDBUF_SMALL) | ^ /home/pi/passt/util.h:159:24: note: expanded from macro 'SNDBUF_SMALL' 159 | #define SNDBUF_SMALL (128UL * 1024) | ^ /home/pi/passt/tcp.c:730:15: note: make conversion explicit to silence this warning 730 | else if (v > SNDBUF_SMALL) | ^ /home/pi/passt/util.h:159:24: note: expanded from macro 'SNDBUF_SMALL' 159 | #define SNDBUF_SMALL (128UL * 1024) | ^~~~~~~~~~~~ /home/pi/passt/tcp.c:730:15: note: perform multiplication in a wider type 730 | else if (v > SNDBUF_SMALL) | ^ /home/pi/passt/util.h:159:24: note: expanded from macro 'SNDBUF_SMALL' 159 | #define SNDBUF_SMALL (128UL * 1024) | ^~~~~ /home/pi/passt/tcp.c:731:17: error: performing an implicit widening conversion to type 'uint64_t' (aka 'unsigned long long') of a multiplication performed in type 'unsigned long' [bugprone-implicit-widening-of-multiplication-result,-warnings-as-errors] 731 | v -= v * (v - SNDBUF_SMALL) / (SNDBUF_BIG - SNDBUF_SMALL) / 2; | ^ /home/pi/passt/util.h:159:24: note: expanded from macro 'SNDBUF_SMALL' 159 | #define SNDBUF_SMALL (128UL * 1024) | ^ /home/pi/passt/tcp.c:731:17: note: make conversion explicit to silence this warning 731 | v -= v * (v - SNDBUF_SMALL) / (SNDBUF_BIG - SNDBUF_SMALL) / 2; | ^ /home/pi/passt/util.h:159:24: note: expanded from macro 'SNDBUF_SMALL' 159 | #define SNDBUF_SMALL (128UL * 1024) | ^~~~~~~~~~~~ /home/pi/passt/tcp.c:731:17: note: perform multiplication in a wider type 731 | v -= v * (v - SNDBUF_SMALL) / (SNDBUF_BIG - SNDBUF_SMALL) / 2; | ^ /home/pi/passt/util.h:159:24: note: expanded from macro 'SNDBUF_SMALL' 159 | #define SNDBUF_SMALL (128UL * 1024) | ^~~~~ because, wherever we use those thresholds, we define the other term of comparison as uint64_t. Define the thresholds as unsigned long long as well, to make sure we match types. Signed-off-by: Stefano Brivio Reviewed-by: David Gibson --- util.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util.h b/util.h index 582ef57..963f57b 100644 --- a/util.h +++ b/util.h @@ -158,9 +158,9 @@ int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags, (void *)(arg)); \ } while (0) -#define RCVBUF_BIG (2UL * 1024 * 1024) -#define SNDBUF_BIG (4UL * 1024 * 1024) -#define SNDBUF_SMALL (128UL * 1024) +#define RCVBUF_BIG (2ULL * 1024 * 1024) +#define SNDBUF_BIG (4ULL * 1024 * 1024) +#define SNDBUF_SMALL (128ULL * 1024) #include #include