selftests: net: tcp_ao: don't shift a size_t by 32
Subsystems (3)
PATCH 1/1 selftests: net: tcp_ao: don't shift a size_t by 32
gen_tcp_addr() shifts the size_t n right by 32 and masks it with BIT(32)
- 1. On 32-bit architectures both shifts are as wide as the type, which is undefined:
aolib.h:230:40: warning: right shift count >= width of type [-Wshift-count-overflow]
Convert n to uint64_t first and mask with 0xffffffff.
---
Found with 32-bit builds of the selftests (gcc 16 and clang 21 with -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without them now, and the x86_64 builds don't change.
tools/testing/selftests/net/tcp_ao/lib/aolib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/net/tcp_ao/lib/aolib.h +2 -2
@@ -226,8 +226,8 @@ static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n)union tcp_addr ret = net;#ifdef IPV6_TEST - ret.a6.s6_addr32[3 ] =htonl (n & (BIT (32 ) -1 )); - ret.a6.s6_addr32[2 ] =htonl ((n >>32 ) & (BIT (32 ) -1 )); + ret.a6.s6_addr32[3 ] =htonl ((uint64_t )n &0xffffffff ); + ret.a6.s6_addr32[2 ] =htonl ((uint64_t )n >>32 );#else ret.a4.s_addr =htonl (ntohl (net.a4.s_addr) + n);#endif
Signature · 1 line
2.53.0
Quoted 36 lines · Sasha Levin
gen_tcp_addr()shifts thesize_tn right by 32 and masks it with BIT(32)
- 1. On 32-bit architectures both shifts are as wide as the type, which is undefined:aolib.h:230:40: warning: right shift count >= width of type [-Wshift-count-overflow]
Convert n to
uint64_tfirst and mask with0xffffffff.Signed-off-by Sasha Levin <[email protected]>---
Found with 32-bit builds of the selftests (gcc 16 and clang 21 with -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without them now, and thex86_64builds don't change.tools/testing/selftests/net/tcp_ao/lib/aolib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/net/tcp_ao/lib/aolib.h +2
-2@@ -226,8 +226,8 @@ static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n)union tcp_addr ret = net;#ifdef IPV6_TEST - ret.a6.s6_addr32[3 ] =htonl (n & (BIT (32 ) -1 )); - ret.a6.s6_addr32[2 ] =htonl ((n >>32 ) & (BIT (32 ) -1 )); + ret.a6.s6_addr32[3 ] =htonl ((uint64_t )n &0xffffffff ); + ret.a6.s6_addr32[2 ] =htonl ((uint64_t )n >>32 );#else ret.a4.s_addr =htonl (ntohl (net.a4.s_addr) + n);#endif Signature · 1 line
2.53.0
Quoted 10 lines · Sasha Levin
gen_tcp_addr()shifts thesize_tn right by 32 and masks it with BIT(32)
- 1. On 32-bit architectures both shifts are as wide as the type, which is undefined:aolib.h:230:40: warning: right shift count >= width of type [-Wshift-count-overflow]
Convert n to
uint64_tfirst and mask with0xffffffff.Signed-off-by Sasha Levin <[email protected]>
Thanks!
Quoted 27 lines
---
Found with 32-bit builds of the selftests (gcc 16 and clang 21 with -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without them now, and thex86_64builds don't change.tools/testing/selftests/net/tcp_ao/lib/aolib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/net/tcp_ao/lib/aolib.h +2
-3@@ -226,8 +226,8 @@ static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n)union tcp_addr ret = net;#ifdef IPV6_TEST - ret.a6.s6_addr32[3 ] =htonl (n & (BIT (32 ) -1 )); - ret.a6.s6_addr32[2 ] =htonl ((n >>32 ) & (BIT (32 ) -1 )); + ret.a6.s6_addr32[3 ] =htonl ((uint64_t )n &0xffffffff ); + ret.a6.s6_addr32[2 ] =htonl ((uint64_t )n >>32 );#else ret.a4.s_addr =htonl (ntohl (net.a4.s_addr) + n);#endif --2.53.0
Quoted 23 lines · On Tue, 3 Nov 2026 11:39:21 -0500 Sasha Levin <[email protected]> wrote:
gen_tcp_addr()shifts thesize_tn right by 32 and masks it with BIT(32)
- 1. On 32-bit architectures both shifts are as wide as the type, which is undefined:aolib.h:230:40: warning: right shift count >= width of type [-Wshift-count-overflow]
Convert n to
uint64_tfirst and mask with0xffffffff.Signed-off-by Sasha Levin <[email protected]>---
Found with 32-bit builds of the selftests (gcc 16 and clang 21 with -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without them now, and thex86_64builds don't change.tools/testing/selftests/net/tcp_ao/lib/aolib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/net/tcp_ao/lib/aolib.h +0
-0
tools/testing/selftests/net/tcp_ao/lib/aolib.h static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n) · line 229
Quoted 6 lines
tools/testing/selftests/net/tcp_ao/lib/aolib.h +1
-2@@ -226,8 +226,8 @@ static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n)union tcp_addr ret = net;#ifdef IPV6_TEST - ret.a6.s6_addr32[3 ] =htonl (n & (BIT (32 ) -1 )); - ret.a6.s6_addr32[2 ] =htonl ((n >>32 ) & (BIT (32 ) -1 )); + ret.a6.s6_addr32[3 ] =htonl ((uint64_t )n &0xffffffff );
You don't need a cast or mask there.
tools/testing/selftests/net/tcp_ao/lib/aolib.h static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n) · line 230
Quoted 1 line
tools/testing/selftests/net/tcp_ao/lib/aolib.h +1
-0+ ret.a6.s6_addr32[2 ] =htonl ((uint64_t )n >>32 );
That can also be n >> 16 >> 16
Also see upper_32_bits() and lower_32_bits() in wordpart.h which might not be available for selftests?
David
Quoted 3 lines
tools/testing/selftests/net/tcp_ao/lib/aolib.h +0
-0#else ret.a4.s_addr =htonl (ntohl (net.a4.s_addr) + n);#endif
Quoted 10 lines · David Laight
tools/testing/selftests/net/tcp_ao/lib/aolib.h static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n) · line 229
Quoted 4 lines · On Tue, 3 Nov 2026 11:39:21 -0500 Sasha Levin <[email protected]> wrote:
#ifdef
IPV6_TESTtools/testing/selftests/net/tcp_ao/lib/aolib.h +1
-2- ret.a6.s6_addr32[3 ] =htonl (n & (BIT (32 ) -1 )); - ret.a6.s6_addr32[2 ] =htonl ((n >>32 ) & (BIT (32 ) -1 )); + ret.a6.s6_addr32[3 ] =htonl ((uint64_t )n &0xffffffff );You don't need a cast or mask there.
Quoted 6 lines
tools/testing/selftests/net/tcp_ao/lib/aolib.h static inline union tcp_addr gen_tcp_addr(union tcp_addr net, size_t n) · line 230
Quoted 1 line
tools/testing/selftests/net/tcp_ao/lib/aolib.h +1
-0+ ret.a6.s6_addr32[2 ] =htonl ((uint64_t )n >>32 );That can also be n >> 16 >> 16
Also see
upper_32_bits()andlower_32_bits()inwordpart.hwhich might not be available for selftests?
They aren't, tools/include has no copy of wordpart.h.
It works as is, but you're right, htonl(n) and htonl(n >> 16 >> 16) are enough. Happy to respin with those if the maintainers prefer.
Signature · 2 lines
Thanks, Sasha
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Tue, 3 Nov 2026 11:39:21 -0500 you wrote:
gen_tcp_addr()shifts thesize_tn right by 32 and masks it with BIT(32)
- 1. On 32-bit architectures both shifts are as wide as the type, which is undefined:aolib.h:230:40: warning: right shift count >= width of type [-Wshift-count-overflow]
Convert n to
uint64_tfirst and mask with0xffffffff.[...]
Here is the summary with links:
- selftests: net: tcp_ao: don't shift a size_t by 32
https://git.kernel.org/netdev/net-next/c/dc8410e0aad5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html