Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Bluetooth: hci.h: Avoid a couple -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.

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>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

authored by

Gustavo A. R. Silva and committed by
Luiz Augusto von Dentz
a0cff16d 4e10a9eb

+12 -4
+12 -4
include/net/bluetooth/hci.h
··· 1468 1468 } __packed; 1469 1469 1470 1470 #define HCI_OP_READ_LOCAL_CODECS 0x100b 1471 - struct hci_std_codecs { 1471 + struct hci_std_codecs_hdr { 1472 1472 __u8 num; 1473 + } __packed; 1474 + 1475 + struct hci_std_codecs { 1476 + struct hci_std_codecs_hdr; 1473 1477 __u8 codec[]; 1474 1478 } __packed; 1475 1479 ··· 1491 1487 1492 1488 struct hci_rp_read_local_supported_codecs { 1493 1489 __u8 status; 1494 - struct hci_std_codecs std_codecs; 1490 + struct hci_std_codecs_hdr std_codecs; 1495 1491 struct hci_vnd_codecs vnd_codecs; 1496 1492 } __packed; 1497 1493 ··· 1508 1504 __u8 transport; 1509 1505 } __packed; 1510 1506 1511 - struct hci_std_codecs_v2 { 1507 + struct hci_std_codecs_v2_hdr { 1512 1508 __u8 num; 1509 + } __packed; 1510 + 1511 + struct hci_std_codecs_v2 { 1512 + struct hci_std_codecs_v2_hdr; 1513 1513 struct hci_std_codec_v2 codec[]; 1514 1514 } __packed; 1515 1515 ··· 1530 1522 1531 1523 struct hci_rp_read_local_supported_codecs_v2 { 1532 1524 __u8 status; 1533 - struct hci_std_codecs_v2 std_codecs; 1525 + struct hci_std_codecs_v2_hdr std_codecs; 1534 1526 struct hci_vnd_codecs_v2 vendor_codecs; 1535 1527 } __packed; 1536 1528