selftest: net: fix variable sized type issue not at the end of a struct
Subsystems (5)
PATCH v2 1/1 selftest: net: fix variable sized type issue not at the end of a struct
Some network selftests defined variable-sized types variable at the middle of struct causing -Wgnu-variable-sized-type-not-at-end warning.
warning:
timestamping.c:285:18: warning: field 'cm' with variable sized type 'struct cmsghdr' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
285 | struct cmsghdr cm;
| ^
ipsec.c:835:5: warning: field 'u' with variable sized type 'union (unnamed union at ipsec.c:831:3)' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
835 | } u;
| ^
This patch move these field at the end of struct to fix these warnings.
---
Changelog:
v2: https://lore.kernel.org/linux-kselftest/[email protected]/
- fixed typos in the commit msg.
--- tools/testing/selftests/net/ipsec.c | 2 +- tools/testing/selftests/net/timestamping.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/net/ipsec.c +1 -1
@@ -828,12 +828,12 @@ static int xfrm_state_pack_algo(struct nlmsghdr *nh, size_t req_sz, struct xfrm_desc *desc) {struct { +char buf[XFRM_ALGO_KEY_BUF_SIZE ];union {struct xfrm_algo alg;struct xfrm_algo_aead aead;struct xfrm_algo_auth auth; } u; -char buf[XFRM_ALGO_KEY_BUF_SIZE ]; } alg = {};size_t alen, elen, clen, aelen;unsigned short type;
tools/testing/selftests/net/timestamping.c +1 -1
@@ -282,8 +282,8 @@ static void recvpacket(int sock, int recvmsg_flags,struct iovec entry;struct sockaddr_in from_addr;struct { -struct cmsghdr cm;char control[512 ]; +struct cmsghdr cm; } control;int res;
Signature · 1 line
2.51.0
Quoted 53 lines · Ankit Khushwaha
Some network selftests defined variable-sized types variable at the middle of struct causing -Wgnu-variable-sized-type-not-at-end warning.
warning:
timestamping.c:285:18: warning: field 'cm' with variable sized type 'struct cmsghdr' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
285 | struct cmsghdr cm;
| ^ipsec.c:835:5: warning: field 'u' with variable sized type 'union (unnamed union at ipsec.c:831:3)' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
835 | } u;
| ^This patch move these field at the end of struct to fix these warnings.
Signed-off-by Ankit Khushwaha <[email protected]>---
Changelog:
v2: https://lore.kernel.org/linux-kselftest/[email protected]/
- fixed typos in the commit msg.--- tools/testing/selftests/net/ipsec.c | 2 +- tools/testing/selftests/net/timestamping.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/net/ipsec.c +1
-1@@ -828,12 +828,12 @@ static int xfrm_state_pack_algo(struct nlmsghdr *nh, size_t req_sz, struct xfrm_desc *desc) {struct { +char buf[XFRM_ALGO_KEY_BUF_SIZE ];union {struct xfrm_algo alg;struct xfrm_algo_aead aead;struct xfrm_algo_auth auth; } u; -char buf[XFRM_ALGO_KEY_BUF_SIZE ]; } alg = {};size_t alen, elen, clen, aelen;unsigned short type;tools/testing/selftests/net/timestamping.c +0
-0
tools/testing/selftests/net/timestamping.c static void recvpacket(int sock, int recvmsg_flags, · line 288
Quoted 8 lines
tools/testing/selftests/net/timestamping.c +1
-1@@ -282,8 +282,8 @@ static void recvpacket(int sock, int recvmsg_flags,struct iovec entry;struct sockaddr_in from_addr;struct { -struct cmsghdr cm;char control[512 ]; +struct cmsghdr cm; } control;int res;
For the timestamping part:
Thanks,
Jason
Jakub Kicinski
maintainertools/testing/selftests/net/timestamping.c static void recvpacket(int sock, int recvmsg_flags, · line 286
Quoted 3 lines · On Mon, 27 Oct 2025 11:01:56 +0530 Ankit Khushwaha wrote:
tools/testing/selftests/net/timestamping.c +1
-1-struct cmsghdr cm;char control[512 ]; +struct cmsghdr cm;
This is no longer in the order in which it will appear in the msg. If the struct placement is not important just use a raw char buffer for the whole thing.
Before you repost please read at least the TLDR section of:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html
Signature · 1 line
pw-bot: cr