linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Marcel Holtmann <marcel@holtmann.org>,
	Johan Hedberg <johan.hedberg@gmail.com>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-hardening@vger.kernel.org
Subject: [PATCH][next] Bluetooth: Avoid a couple dozen -Wflex-array-member-not-at-end warnings
Date: Sun, 31 Aug 2025 19:13:31 +0200	[thread overview]
Message-ID: <aLSCu8U62Hve7Dau@kspp> (raw)

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

Use the new TRAILING_OVERLAP() 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]

This helper creates a union between a flexible-array member (FAM)
and a set of members that would otherwise follow it. This overlays
the trailing members onto the FAM while preserving the original
memory layout.

Also, as the structs turn into unions, both members `entry` and
`value` cannot be statically initialized at once. Create another
macro to initialize everything after the declaration of `rp`.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 net/bluetooth/mgmt_config.c | 97 +++++++++++++++++++------------------
 1 file changed, 51 insertions(+), 46 deletions(-)

diff --git a/net/bluetooth/mgmt_config.c b/net/bluetooth/mgmt_config.c
index 6ef701c27da4..829c9cfcea7d 100644
--- a/net/bluetooth/mgmt_config.c
+++ b/net/bluetooth/mgmt_config.c
@@ -12,35 +12,71 @@
 #include "mgmt_config.h"
 
 #define HDEV_PARAM_U16(_param_name_) \
-	struct {\
-		struct mgmt_tlv entry; \
+	TRAILING_OVERLAP(struct mgmt_tlv, entry, value, \
 		__le16 value; \
-	} __packed _param_name_
+	) __packed _param_name_
 
 #define HDEV_PARAM_U8(_param_name_) \
-	struct {\
-		struct mgmt_tlv entry; \
+	TRAILING_OVERLAP(struct mgmt_tlv, entry, value, \
 		__u8 value; \
-	} __packed _param_name_
+	) __packed _param_name_
 
 #define TLV_SET_U16(_param_code_, _param_name_) \
 	{ \
-		{ cpu_to_le16(_param_code_), sizeof(__u16) }, \
-		cpu_to_le16(hdev->_param_name_) \
+		rp._param_name_.entry.type = cpu_to_le16(_param_code_); \
+		rp._param_name_.entry.length = sizeof(__u16); \
+		rp._param_name_.value = cpu_to_le16(hdev->_param_name_); \
 	}
 
 #define TLV_SET_U8(_param_code_, _param_name_) \
 	{ \
-		{ cpu_to_le16(_param_code_), sizeof(__u8) }, \
-		hdev->_param_name_ \
+		rp._param_name_.entry.type = cpu_to_le16(_param_code_); \
+		rp._param_name_.entry.length = sizeof(__u8); \
+		rp._param_name_.value = hdev->_param_name_; \
 	}
 
 #define TLV_SET_U16_JIFFIES_TO_MSECS(_param_code_, _param_name_) \
 	{ \
-		{ cpu_to_le16(_param_code_), sizeof(__u16) }, \
-		cpu_to_le16(jiffies_to_msecs(hdev->_param_name_)) \
+		rp._param_name_.entry.type = cpu_to_le16(_param_code_); \
+		rp._param_name_.entry.length = sizeof(__u16); \
+		rp._param_name_.value = cpu_to_le16(jiffies_to_msecs(hdev->_param_name_)); \
 	}
 
+#define TLV_SET_ALL() \
+{ \
+	TLV_SET_U16(0x0000, def_page_scan_type); \
+	TLV_SET_U16(0x0001, def_page_scan_int); \
+	TLV_SET_U16(0x0002, def_page_scan_window); \
+	TLV_SET_U16(0x0003, def_inq_scan_type);  \
+	TLV_SET_U16(0x0004, def_inq_scan_int); \
+	TLV_SET_U16(0x0005, def_inq_scan_window); \
+	TLV_SET_U16(0x0006, def_br_lsto); \
+	TLV_SET_U16(0x0007, def_page_timeout); \
+	TLV_SET_U16(0x0008, sniff_min_interval); \
+	TLV_SET_U16(0x0009, sniff_max_interval); \
+	TLV_SET_U16(0x000a, le_adv_min_interval); \
+	TLV_SET_U16(0x000b, le_adv_max_interval); \
+	TLV_SET_U16(0x000c, def_multi_adv_rotation_duration); \
+	TLV_SET_U16(0x000d, le_scan_interval); \
+	TLV_SET_U16(0x000e, le_scan_window); \
+	TLV_SET_U16(0x000f, le_scan_int_suspend); \
+	TLV_SET_U16(0x0010, le_scan_window_suspend); \
+	TLV_SET_U16(0x0011, le_scan_int_discovery); \
+	TLV_SET_U16(0x0012, le_scan_window_discovery); \
+	TLV_SET_U16(0x0013, le_scan_int_adv_monitor); \
+	TLV_SET_U16(0x0014, le_scan_window_adv_monitor); \
+	TLV_SET_U16(0x0015, le_scan_int_connect); \
+	TLV_SET_U16(0x0016, le_scan_window_connect); \
+	TLV_SET_U16(0x0017, le_conn_min_interval); \
+	TLV_SET_U16(0x0018, le_conn_max_interval); \
+	TLV_SET_U16(0x0019, le_conn_latency); \
+	TLV_SET_U16(0x001a, le_supv_timeout); \
+	TLV_SET_U16_JIFFIES_TO_MSECS(0x001b, def_le_autoconnect_timeout); \
+	TLV_SET_U16(0x001d, advmon_allowlist_duration); \
+	TLV_SET_U16(0x001e, advmon_no_filter_duration); \
+	TLV_SET_U8(0x001f, enable_advmon_interleave_scan); \
+}
+
 int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
 			   u16 data_len)
 {
@@ -78,40 +114,9 @@ int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
 		HDEV_PARAM_U16(advmon_allowlist_duration);
 		HDEV_PARAM_U16(advmon_no_filter_duration);
 		HDEV_PARAM_U8(enable_advmon_interleave_scan);
-	} __packed rp = {
-		TLV_SET_U16(0x0000, def_page_scan_type),
-		TLV_SET_U16(0x0001, def_page_scan_int),
-		TLV_SET_U16(0x0002, def_page_scan_window),
-		TLV_SET_U16(0x0003, def_inq_scan_type),
-		TLV_SET_U16(0x0004, def_inq_scan_int),
-		TLV_SET_U16(0x0005, def_inq_scan_window),
-		TLV_SET_U16(0x0006, def_br_lsto),
-		TLV_SET_U16(0x0007, def_page_timeout),
-		TLV_SET_U16(0x0008, sniff_min_interval),
-		TLV_SET_U16(0x0009, sniff_max_interval),
-		TLV_SET_U16(0x000a, le_adv_min_interval),
-		TLV_SET_U16(0x000b, le_adv_max_interval),
-		TLV_SET_U16(0x000c, def_multi_adv_rotation_duration),
-		TLV_SET_U16(0x000d, le_scan_interval),
-		TLV_SET_U16(0x000e, le_scan_window),
-		TLV_SET_U16(0x000f, le_scan_int_suspend),
-		TLV_SET_U16(0x0010, le_scan_window_suspend),
-		TLV_SET_U16(0x0011, le_scan_int_discovery),
-		TLV_SET_U16(0x0012, le_scan_window_discovery),
-		TLV_SET_U16(0x0013, le_scan_int_adv_monitor),
-		TLV_SET_U16(0x0014, le_scan_window_adv_monitor),
-		TLV_SET_U16(0x0015, le_scan_int_connect),
-		TLV_SET_U16(0x0016, le_scan_window_connect),
-		TLV_SET_U16(0x0017, le_conn_min_interval),
-		TLV_SET_U16(0x0018, le_conn_max_interval),
-		TLV_SET_U16(0x0019, le_conn_latency),
-		TLV_SET_U16(0x001a, le_supv_timeout),
-		TLV_SET_U16_JIFFIES_TO_MSECS(0x001b,
-					     def_le_autoconnect_timeout),
-		TLV_SET_U16(0x001d, advmon_allowlist_duration),
-		TLV_SET_U16(0x001e, advmon_no_filter_duration),
-		TLV_SET_U8(0x001f, enable_advmon_interleave_scan),
-	};
+	} __packed rp;
+
+	TLV_SET_ALL();
 
 	bt_dev_dbg(hdev, "sock %p", sk);
 
-- 
2.43.0


             reply	other threads:[~2025-08-31 17:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-31 17:13 Gustavo A. R. Silva [this message]
2025-08-31 17:51 ` [next] Bluetooth: Avoid a couple dozen -Wflex-array-member-not-at-end warnings bluez.test.bot
2025-08-31 18:02 ` [PATCH][next] " Gustavo A. R. Silva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aLSCu8U62Hve7Dau@kspp \
    --to=gustavoars@kernel.org \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).