Skip to contentSkip to conversation

selftest: af_unix: Enable -Wall and -Wflex-array-member-not-at-end.

PATCH Applied Kuniyuki Iwashima 3 participants 8 messages Aug 11, 2025 – Aug 13, 2025

Subsystems (4)
lore
Share & tools
lore

Kuniyuki Iwashima

author maintainer
#0 lore raw

cover selftest: af_unix: Enable -Wall and -Wflex-array-member-not-at-end.

This series fix 4 warnings caught by -Wall and
-Wflex-array-member-not-at-end.

Kuniyuki Iwashima (4):
selftest: af_unix: Add -Wall and -Wflex-array-member-not-at-end.
selftest: af_unix: Silence -Wflex-array-member-not-at-end warning for

    scm_inq.c.

selftest: af_unix: Silence -Wflex-array-member-not-at-end warning for
scm_rights.c.
selftest: af_unix: Silence -Wall warning for scm_pid.c.

 tools/testing/selftests/net/af_unix/Makefile  |  2 +-
 tools/testing/selftests/net/af_unix/scm_inq.c | 26 ++++++++---------
 .../testing/selftests/net/af_unix/scm_pidfd.c |  2 --
 .../selftests/net/af_unix/scm_rights.c        | 28 +++++++++----------
 4 files changed, 26 insertions(+), 32 deletions(-)
Signature · 1 line
2.51.0.rc0.155.g4a0f42376b-goog
author maintainer
#1 lore raw

PATCH 1/4 selftest: af_unix: Add -Wall and -Wflex-array-member-not-at-end to CFLAGS.

-Wall and -Wflex-array-member-not-at-end caught some warnings that will be fixed in later patches.

---
 tools/testing/selftests/net/af_unix/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/af_unix/Makefile +1 -1
index a4b61c6d0290..0a20c98bbcfd 100644
@@ -1,4 +1,4 @@
-CFLAGS += $(KHDR_INCLUDES)
+CFLAGS += $(KHDR_INCLUDES) -Wall -Wflex-array-member-not-at-end
 TEST_GEN_PROGS := diag_uid msg_oob scm_inq scm_pidfd scm_rights unix_connect
 
 include ../../lib.mk
Signature · 1 line
2.51.0.rc0.155.g4a0f42376b-goog
maintainer
#2 lore raw

Re: [PATCH v1 net-next 1/4] selftest: af_unix: Add -Wall and -Wflex-array-member-not-at-end to CFLAGS.

Quoted 2 lines · On Mon, 11 Aug 2025 21:53:04 +0000 Kuniyuki Iwashima wrote:

-Wall and -Wflex-array-member-not-at-end caught some warnings that will be fixed in later patches.

Makes sense to enable the warnings first when writing the patches, but I think we should commit in the opposite order. Fixes fix then arm the warnings. I'll reorder when applying.

author maintainer
#3 lore raw

Re: [PATCH v1 net-next 1/4] selftest: af_unix: Add -Wall and -Wflex-array-member-not-at-end to CFLAGS.

Quoted 8 lines · Jakub Kicinski
Quoted 2 lines · On Mon, 11 Aug 2025 21:53:04 +0000 Kuniyuki Iwashima wrote:

-Wall and -Wflex-array-member-not-at-end caught some warnings that will be fixed in later patches.

Makes sense to enable the warnings first when writing the patches, but I think we should commit in the opposite order. Fixes fix then arm the warnings. I'll reorder when applying.

Exactly, thank you Jakub!

author maintainer
#4 lore raw

PATCH 2/4 selftest: af_unix: Silence -Wflex-array-member-not-at-end warning for scm_inq.c.

In reply to Kuniyuki Iwashima

scm_inq.c has no problem in functionality, but when compiled with -Wflex-array-member-not-at-end, it shows this warning:

scm_inq.c:15:24: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
15 | struct cmsghdr cmsghdr;
| ^~~~~~~

Let's silence it.

---
 tools/testing/selftests/net/af_unix/scm_inq.c | 26 +++++++++----------
 1 file changed, 12 insertions(+), 14 deletions(-)
tools/testing/selftests/net/af_unix/scm_inq.c +12 -14
index 9d22561e7b8f..fc467714387e 100644
@@ -11,11 +11,6 @@
 #define NR_CHUNKS	100
 #define MSG_LEN		256
 
-struct scm_inq {
-	struct cmsghdr cmsghdr;
-	int inq;
-};
-
 FIXTURE(scm_inq)
 {
 	int fd[2];
@@ -70,35 +65,38 @@ static void send_chunks(struct __test_metadata *_metadata,
 static void recv_chunks(struct __test_metadata *_metadata,
 			FIXTURE_DATA(scm_inq) *self)
 {
+	char cmsg_buf[CMSG_SPACE(sizeof(int))];
 	struct msghdr msg = {};
 	struct iovec iov = {};
-	struct scm_inq cmsg;
+	struct cmsghdr *cmsg;
 	char buf[MSG_LEN];
 	int i, ret;
 	int inq;
 
 	msg.msg_iov = &iov;
 	msg.msg_iovlen = 1;
-	msg.msg_control = &cmsg;
-	msg.msg_controllen = CMSG_SPACE(sizeof(cmsg.inq));
+	msg.msg_control = cmsg_buf;
+	msg.msg_controllen = sizeof(cmsg_buf);
 
 	iov.iov_base = buf;
 	iov.iov_len = sizeof(buf);
 
 	for (i = 0; i < NR_CHUNKS; i++) {
 		memset(buf, 0, sizeof(buf));
-		memset(&cmsg, 0, sizeof(cmsg));
+		memset(cmsg_buf, 0, sizeof(cmsg_buf));
 
 		ret = recvmsg(self->fd[1], &msg, 0);
 		ASSERT_EQ(MSG_LEN, ret);
-		ASSERT_NE(NULL, CMSG_FIRSTHDR(&msg));
-		ASSERT_EQ(CMSG_LEN(sizeof(cmsg.inq)), cmsg.cmsghdr.cmsg_len);
-		ASSERT_EQ(SOL_SOCKET, cmsg.cmsghdr.cmsg_level);
-		ASSERT_EQ(SCM_INQ, cmsg.cmsghdr.cmsg_type);
+
+		cmsg = CMSG_FIRSTHDR(&msg);
+		ASSERT_NE(NULL, cmsg);
+		ASSERT_EQ(CMSG_LEN(sizeof(int)), cmsg->cmsg_len);
+		ASSERT_EQ(SOL_SOCKET, cmsg->cmsg_level);
+		ASSERT_EQ(SCM_INQ, cmsg->cmsg_type);
 
 		ret = ioctl(self->fd[1], SIOCINQ, &inq);
 		ASSERT_EQ(0, ret);
-		ASSERT_EQ(cmsg.inq, inq);
+		ASSERT_EQ(*(int *)CMSG_DATA(cmsg), inq);
 	}
 }
 
Signature · 1 line
2.51.0.rc0.155.g4a0f42376b-goog
author maintainer
#5 lore raw

PATCH 3/4 selftest: af_unix: Silence -Wflex-array-member-not-at-end warning for scm_rights.c.

In reply to Kuniyuki Iwashima

scm_rights.c has no problem in functionality, but when compiled with -Wflex-array-member-not-at-end, it shows this warning:

scm_rights.c: In function ‘__send_fd’:
scm_rights.c:275:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
275 | struct cmsghdr cmsghdr;
| ^~~~~~~

Let's silence it.

---
 .../selftests/net/af_unix/scm_rights.c        | 28 +++++++++----------
 1 file changed, 13 insertions(+), 15 deletions(-)
tools/testing/selftests/net/af_unix/scm_rights.c +13 -15
index 8b015f16c03d..914f99d153ce 100644
@@ -271,20 +271,11 @@ void __send_fd(struct __test_metadata *_metadata,
 {
 #define MSG "x"
 #define MSGLEN 1
-	struct {
-		struct cmsghdr cmsghdr;
-		int fd[2];
-	} cmsg = {
-		.cmsghdr = {
-			.cmsg_len = CMSG_LEN(sizeof(cmsg.fd)),
-			.cmsg_level = SOL_SOCKET,
-			.cmsg_type = SCM_RIGHTS,
-		},
-		.fd = {
-			self->fd[inflight * 2],
-			self->fd[inflight * 2],
-		},
+	int fds[2] = {
+		self->fd[inflight * 2],
+		self->fd[inflight * 2],
 	};
+	char cmsg_buf[CMSG_SPACE(sizeof(fds))];
 	struct iovec iov = {
 		.iov_base = MSG,
 		.iov_len = MSGLEN,
@@ -294,11 +285,18 @@ void __send_fd(struct __test_metadata *_metadata,
 		.msg_namelen = 0,
 		.msg_iov = &iov,
 		.msg_iovlen = 1,
-		.msg_control = &cmsg,
-		.msg_controllen = CMSG_SPACE(sizeof(cmsg.fd)),
+		.msg_control = cmsg_buf,
+		.msg_controllen = sizeof(cmsg_buf),
 	};
+	struct cmsghdr *cmsg;
 	int ret;
 
+	cmsg = CMSG_FIRSTHDR(&msg);
+	cmsg->cmsg_level = SOL_SOCKET;
+	cmsg->cmsg_type = SCM_RIGHTS;
+	cmsg->cmsg_len = CMSG_LEN(sizeof(fds));
+	memcpy(CMSG_DATA(cmsg), fds, sizeof(fds));
+
 	ret = sendmsg(self->fd[receiver * 2 + 1], &msg, variant->flags);
 
 	if (variant->disabled) {
Signature · 1 line
2.51.0.rc0.155.g4a0f42376b-goog
author maintainer
#6 lore raw

PATCH 4/4 selftest: af_unix: Silence -Wall warning for scm_pid.c.

In reply to Kuniyuki Iwashima

-Wall found 2 unused variables in scm_pid.c:

scm_pidfd.c: In function ‘parse_cmsg’:
scm_pidfd.c:140:13: warning: unused variable ‘data’ [-Wunused-variable]

  140 |         int data = 0;
      |             ^~~~
scm_pidfd.c: In function ‘cmsg_check_dead’:
scm_pidfd.c:246:15: warning: unused variable ‘client_pid’ [-Wunused-variable]
  246 |         pid_t client_pid;
      |               ^~~~~~~~~~

Let's remove these variables.

---
 tools/testing/selftests/net/af_unix/scm_pidfd.c | 2 --
 1 file changed, 2 deletions(-)
tools/testing/selftests/net/af_unix/scm_pidfd.c +0 -2
index 37e034874034..ef2921988e5f 100644
@@ -137,7 +137,6 @@ struct cmsg_data {
 static int parse_cmsg(struct msghdr *msg, struct cmsg_data *res)
 {
 	struct cmsghdr *cmsg;
-	int data = 0;
 
 	if (msg->msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {
 		log_err("recvmsg: truncated");
@@ -243,7 +242,6 @@ static int cmsg_check_dead(int fd, int expected_pid)
 	int data = 0;
 	char control[CMSG_SPACE(sizeof(struct ucred)) +
 		     CMSG_SPACE(sizeof(int))] = { 0 };
-	pid_t client_pid;
 	struct pidfd_info info = {
 		.mask = PIDFD_INFO_EXIT,
 	};
Signature · 1 line
2.51.0.rc0.155.g4a0f42376b-goog
#7 lore raw
In reply to Kuniyuki Iwashima
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 7 lines · On Mon, 11 Aug 2025 21:53:03 +0000 you wrote:

This series fix 4 warnings caught by -Wall and
-Wflex-array-member-not-at-end.

Kuniyuki Iwashima (4):
selftest: af_unix: Add -Wall and -Wflex-array-member-not-at-end.
selftest: af_unix: Silence -Wflex-array-member-not-at-end warning for

Quoted 6 lines
    scm_inq.c.

selftest: af_unix: Silence -Wflex-array-member-not-at-end warning for
scm_rights.c.
selftest: af_unix: Silence -Wall warning for scm_pid.c.

[...]

Here is the summary with links:
- [v1,net-next,1/4] selftest: af_unix: Add -Wall and -Wflex-array-member-not-at-end to CFLAGS.

    https://git.kernel.org/netdev/net-next/c/1838731f1072
  - [v1,net-next,2/4] selftest: af_unix: Silence -Wflex-array-member-not-at-end warning for scm_inq.c.
    https://git.kernel.org/netdev/net-next/c/942224e6baca
  - [v1,net-next,3/4] selftest: af_unix: Silence -Wflex-array-member-not-at-end warning for scm_rights.c.
    https://git.kernel.org/netdev/net-next/c/9a58d8e68252
  - [v1,net-next,4/4] selftest: af_unix: Silence -Wall warning for scm_pid.c.
    https://git.kernel.org/netdev/net-next/c/fd9faac372cc

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html