public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Marcel Holtmann <marcel@holtmann.org>,
	Johan Hedberg <johan.hedberg@gmail.com>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>
Cc: linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] Bluetooth: hci.h: Avoid a couple -Wflex-array-member-not-at-end warnings
Date: Tue, 7 Apr 2026 13:57:00 -0600	[thread overview]
Message-ID: <d04e11af-5c1b-44a2-aebc-a0ee4fb79802@embeddedor.com> (raw)
In-Reply-To: <aZ1FrL8qvvKuktBF@kspp>

Hi all,

Friendly ping: who can take this, please?

Thanks
-Gustavo

On 2/24/26 00:31, Gustavo A. R. Silva wrote:
> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
> getting ready to enable it, globally.
> 
> struct hci_std_codecs and struct hci_std_codecs_v2 are flexible
> structures, this is structures that contain a flexible-array member
> (__u8 codec[]; and struct hci_std_codec_v2 codec[];, correspondingly.)
> 
> Since struct hci_rp_read_local_supported_codecs and struct
> hci_rp_read_local_supported_codecs_v2 are defined by hardware, we
> create the new struct hci_std_codecs_hdr and struct hci_std_codecs_v2_hdr
> types, and use them to replace the object types causing trouble in
> struct hci_rp_read_local_supported_codecs and struct
> hci_rp_read_local_supported_codecs_v2, namely struct hci_std_codecs
> std_codecs; and struct hci_std_codecs_v2_hdr std_codecs;.
> 
> Also, once -fms-extensions is enabled, we can use transparent struct
> members in both struct hci_std_codecs and struct hci_std_codecs_v2_hdr.
> 
> Notice that the newly created types does not contain the flex-array
> member `codec`, which is the object causing the -Wfamnae warnings.
> 
> After these changes, the size of struct hci_rp_read_local_supported_codecs
> and struct hci_rp_read_local_supported_codecs_v2, along with their
> member's offsets remain the same, hence the memory layouts don't
> change:
> 
> Before changes:
> struct hci_rp_read_local_supported_codecs {
>          __u8                       status;               /*     0     1 */
>          struct hci_std_codecs      std_codecs;           /*     1     1 */
>          struct hci_vnd_codecs      vnd_codecs;           /*     2     1 */
> 
>          /* size: 3, cachelines: 1, members: 3 */
>          /* last cacheline: 3 bytes */
> } __attribute__((__packed__));
> 
> struct hci_rp_read_local_supported_codecs_v2 {
>          __u8                       status;               /*     0     1 */
>          struct hci_std_codecs_v2   std_codecs;           /*     1     1 */
>          struct hci_vnd_codecs_v2   vendor_codecs;        /*     2     1 */
> 
>          /* size: 3, cachelines: 1, members: 3 */
>          /* last cacheline: 3 bytes */
> } __attribute__((__packed__));
> 
> After changes:
> struct hci_rp_read_local_supported_codecs {
> 	__u8                       status;               /*     0     1 */
> 	struct hci_std_codecs_hdr  std_codecs;           /*     1     1 */
> 	struct hci_vnd_codecs      vnd_codecs;           /*     2     1 */
> 
> 	/* size: 3, cachelines: 1, members: 3 */
> 	/* last cacheline: 3 bytes */
> } __attribute__((__packed__));
> 
> struct hci_rp_read_local_supported_codecs_v2 {
> 	__u8                       status;               /*     0     1 */
> 	struct hci_std_codecs_v2_hdr std_codecs;         /*     1     1 */
> 	struct hci_vnd_codecs_v2   vendor_codecs;        /*     2     1 */
> 
> 	/* size: 3, cachelines: 1, members: 3 */
> 	/* last cacheline: 3 bytes */
> } __attribute__((__packed__));
> 
> With these changes fix the following warnings:
> 
> include/net/bluetooth/hci.h:1490:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> include/net/bluetooth/hci.h:1525:34: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>   include/net/bluetooth/hci.h | 16 ++++++++++++----
>   1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> index 89ad9470fa71..572b1c620c5d 100644
> --- a/include/net/bluetooth/hci.h
> +++ b/include/net/bluetooth/hci.h
> @@ -1468,8 +1468,12 @@ struct hci_rp_read_data_block_size {
>   } __packed;
>   
>   #define HCI_OP_READ_LOCAL_CODECS	0x100b
> -struct hci_std_codecs {
> +struct hci_std_codecs_hdr {
>   	__u8	num;
> +} __packed;
> +
> +struct hci_std_codecs {
> +	struct hci_std_codecs_hdr;
>   	__u8	codec[];
>   } __packed;
>   
> @@ -1487,7 +1491,7 @@ struct hci_vnd_codecs {
>   
>   struct hci_rp_read_local_supported_codecs {
>   	__u8	status;
> -	struct hci_std_codecs std_codecs;
> +	struct hci_std_codecs_hdr std_codecs;
>   	struct hci_vnd_codecs vnd_codecs;
>   } __packed;
>   
> @@ -1504,8 +1508,12 @@ struct hci_std_codec_v2 {
>   	__u8	transport;
>   } __packed;
>   
> -struct hci_std_codecs_v2 {
> +struct hci_std_codecs_v2_hdr {
>   	__u8	num;
> +} __packed;
> +
> +struct hci_std_codecs_v2 {
> +	struct hci_std_codecs_v2_hdr;
>   	struct hci_std_codec_v2 codec[];
>   } __packed;
>   
> @@ -1522,7 +1530,7 @@ struct hci_vnd_codecs_v2 {
>   
>   struct hci_rp_read_local_supported_codecs_v2 {
>   	__u8	status;
> -	struct hci_std_codecs_v2 std_codecs;
> +	struct hci_std_codecs_v2_hdr std_codecs;
>   	struct hci_vnd_codecs_v2 vendor_codecs;
>   } __packed;
>   


  reply	other threads:[~2026-04-07 19:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-24  6:31 [PATCH][next] Bluetooth: hci.h: Avoid a couple -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2026-04-07 19:57 ` Gustavo A. R. Silva [this message]
2026-04-07 20:06   ` Luiz Augusto von Dentz

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=d04e11af-5c1b-44a2-aebc-a0ee4fb79802@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gustavoars@kernel.org \
    --cc=horms@kernel.org \
    --cc=johan.hedberg@gmail.com \
    --cc=kuba@kernel.org \
    --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 \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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