Skip to contentSkip to conversation

Bluetooth: Avoid a couple dozen -Wflex-array-member-not-at-end warnings

PATCH Applied Gustavo A. R. Silva 6 participants 7 messages Sep 9, 2025 – Sep 25, 2025

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

PATCH v2 1/1 Bluetooth: Avoid a couple dozen -Wflex-array-member-not-at-end warnings

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Use the __struct_group() helper to fix 31 instances of the following type of warnings:

30 net/bluetooth/mgmt_config.c:16:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] 1 net/bluetooth/mgmt_config.c:22:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
Changes in v2:
- Use __struct_group() instead of TRAILING_OVERLAP().

v1:
- Link: https://lore.kernel.org/linux-hardening/aLSCu8U62Hve7Dau@kspp/

 include/net/bluetooth/mgmt.h | 9 +++++++--
 net/bluetooth/mgmt_config.c  | 4 ++--
 2 files changed, 9 insertions(+), 4 deletions(-)
include/net/bluetooth/mgmt.h +7 -2
index 3575cd16049a..74edea06985b 100644
@@ -53,10 +53,15 @@ struct mgmt_hdr {
 } __packed;
 
 struct mgmt_tlv {
-	__le16 type;
-	__u8   length;
+	/* New members MUST be added within the __struct_group() macro below. */
+	__struct_group(mgmt_tlv_hdr, __hdr, __packed,
+		__le16 type;
+		__u8   length;
+	);
 	__u8   value[];
 } __packed;
+static_assert(offsetof(struct mgmt_tlv, value) == sizeof(struct mgmt_tlv_hdr),
+	      "struct member likely outside of __struct_group()");
 
 struct mgmt_addr_info {
 	bdaddr_t	bdaddr;
net/bluetooth/mgmt_config.c +2 -2
index 6ef701c27da4..c4063d200c0a 100644
@@ -13,13 +13,13 @@
 
 #define HDEV_PARAM_U16(_param_name_) \
 	struct {\
-		struct mgmt_tlv entry; \
+		struct mgmt_tlv_hdr entry; \
 		__le16 value; \
 	} __packed _param_name_
 
 #define HDEV_PARAM_U8(_param_name_) \
 	struct {\
-		struct mgmt_tlv entry; \
+		struct mgmt_tlv_hdr entry; \
 		__u8 value; \
 	} __packed _param_name_
 
Signature · 1 line
2.43.0
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1000473

---Test result---

Test Summary:

CheckPatch                    PENDING   0.50 seconds
GitLint                       PENDING   0.25 seconds
SubjectPrefix                 PASS      0.08 seconds
BuildKernel                   PASS      24.72 seconds
CheckAllWarning               PASS      27.53 seconds
CheckSparse                   PASS      30.82 seconds
BuildKernel32                 PASS      24.53 seconds
TestRunnerSetup               PASS      486.66 seconds
TestRunner_l2cap-tester       PASS      25.33 seconds
TestRunner_iso-tester         PASS      39.31 seconds
TestRunner_bnep-tester        PASS      5.99 seconds
TestRunner_mgmt-tester        FAIL      127.39 seconds
TestRunner_rfcomm-tester      PASS      9.29 seconds
TestRunner_sco-tester         PASS      14.82 seconds
TestRunner_ioctl-tester       PASS      10.08 seconds
TestRunner_mesh-tester        FAIL      11.54 seconds
TestRunner_smp-tester         PASS      8.63 seconds
TestRunner_userchan-tester    PASS      6.27 seconds
IncrementalBuild              PENDING   0.56 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 490, Passed: 485 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success Failed 0.107 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases

Mesh - Send cancel - 1                               Timed out    1.991 seconds
Mesh - Send cancel - 2                               Timed out    1.998 seconds

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth

reviewer Reviewed-by on v2 1/1
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 9 lines · Gustavo A. R. Silva

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Use the __struct_group() helper to fix 31 instances of the following type of warnings:

30 net/bluetooth/mgmt_config.c:16:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] 1 net/bluetooth/mgmt_config.c:22:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Quoted 7 lines

---
Changes in v2:
- Use __struct_group() instead of TRAILING_OVERLAP().

v1:
- Link: https://lore.kernel.org/linux-hardening/aLSCu8U62Hve7Dau@kspp/

#3 lore raw
In reply to Gustavo A. R. Silva

Dear Gustavo,

Thank you for your patch.

Am 09.09.25 um 14:13 schrieb Gustavo A. R. Silva:

Quoted 8 lines

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Use the __struct_group() helper to fix 31 instances of the following type of warnings:

30 net/bluetooth/mgmt_config.c:16:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] 1 net/bluetooth/mgmt_config.c:22:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

You could add an explanation, why the macro __struct_group() defined in include/uapi/linux/stddef.h fixes this, and why it is preferred over TRAILING_OVERLAP(). Also, the two underscores would suggest to me, it’s some kind of internal implementation.

Quoted 45 lines

---
Changes in v2:
- Use __struct_group() instead of TRAILING_OVERLAP().

v1:
- Link: https://lore.kernel.org/linux-hardening/aLSCu8U62Hve7Dau@kspp/

  include/net/bluetooth/mgmt.h | 9 +++++++--
  net/bluetooth/mgmt_config.c  | 4 ++--
  2 files changed, 9 insertions(+), 4 deletions(-)
include/net/bluetooth/mgmt.h +7 -2
index 3575cd16049a..74edea06985b 100644
@@ -53,10 +53,15 @@ struct mgmt_hdr {
  } __packed;
 
  struct mgmt_tlv {
-	__le16 type;
-	__u8   length;
+	/* New members MUST be added within the __struct_group() macro below. */
+	__struct_group(mgmt_tlv_hdr, __hdr, __packed,
+		__le16 type;
+		__u8   length;
+	);
  	__u8   value[];
  } __packed;
+static_assert(offsetof(struct mgmt_tlv, value) == sizeof(struct mgmt_tlv_hdr),
+	      "struct member likely outside of __struct_group()");
 
  struct mgmt_addr_info {
  	bdaddr_t	bdaddr;
net/bluetooth/mgmt_config.c +1 -1
index 6ef701c27da4..c4063d200c0a 100644
@@ -13,13 +13,13 @@
 
  #define HDEV_PARAM_U16(_param_name_) \
  	struct {\
-		struct mgmt_tlv entry; \
+		struct mgmt_tlv_hdr entry; \

net/bluetooth/mgmt_config.c line 25

Quoted 10 lines
net/bluetooth/mgmt_config.c +1 -1
  		__le16 value; \
  	} __packed _param_name_
 
  #define HDEV_PARAM_U8(_param_name_) \
  	struct {\
-		struct mgmt_tlv entry; \
+		struct mgmt_tlv_hdr entry; \
  		__u8 value; \
  	} __packed _param_name_
 

Kind regards,

Paul

#4 lore raw
In reply to Gustavo A. R. Silva

Hi all,

Friendly ping: who can take this, please? :)

Thanks!
-Gustavo

Quoted 63 lines · Gustavo A. R. Silva

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Use the __struct_group() helper to fix 31 instances of the following type of warnings:

30 net/bluetooth/mgmt_config.c:16:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] 1 net/bluetooth/mgmt_config.c:22:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
Changes in v2:
- Use __struct_group() instead of TRAILING_OVERLAP().

v1:
- Link: https://lore.kernel.org/linux-hardening/aLSCu8U62Hve7Dau@kspp/

  include/net/bluetooth/mgmt.h | 9 +++++++--
  net/bluetooth/mgmt_config.c  | 4 ++--
  2 files changed, 9 insertions(+), 4 deletions(-)
include/net/bluetooth/mgmt.h +7 -2
index 3575cd16049a..74edea06985b 100644
@@ -53,10 +53,15 @@ struct mgmt_hdr {
  } __packed;
 
  struct mgmt_tlv {
-	__le16 type;
-	__u8   length;
+	/* New members MUST be added within the __struct_group() macro below. */
+	__struct_group(mgmt_tlv_hdr, __hdr, __packed,
+		__le16 type;
+		__u8   length;
+	);
  	__u8   value[];
  } __packed;
+static_assert(offsetof(struct mgmt_tlv, value) == sizeof(struct mgmt_tlv_hdr),
+	      "struct member likely outside of __struct_group()");
 
  struct mgmt_addr_info {
  	bdaddr_t	bdaddr;
net/bluetooth/mgmt_config.c +2 -2
index 6ef701c27da4..c4063d200c0a 100644
@@ -13,13 +13,13 @@
 
  #define HDEV_PARAM_U16(_param_name_) \
  	struct {\
-		struct mgmt_tlv entry; \
+		struct mgmt_tlv_hdr entry; \
  		__le16 value; \
  	} __packed _param_name_
 
  #define HDEV_PARAM_U8(_param_name_) \
  	struct {\
-		struct mgmt_tlv entry; \
+		struct mgmt_tlv_hdr entry; \
  		__u8 value; \
  	} __packed _param_name_
 
#5 lore raw
In reply to Gustavo A. R. Silva
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · On Tue, 9 Sep 2025 14:13:35 +0200 you wrote:

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Use the __struct_group() helper to fix 31 instances of the following type of warnings:

30 net/bluetooth/mgmt_config.c:16:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] 1 net/bluetooth/mgmt_config.c:22:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

[...]

Here is the summary with links:
- [v2,next] Bluetooth: Avoid a couple dozen -Wflex-array-member-not-at-end warnings

    https://git.kernel.org/bluetooth/bluetooth-next/c/33c9dc51e8b4

You are awesome, thank you!

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