Skip to content

Commit a7e4545

Browse files
GustavoARSilvaholtmann
authored andcommitted
Bluetooth: Replace zero-length array with flexible-array member
The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] KSPP/linux#21 [3] commit 7649773 ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent eed467b commit a7e4545

8 files changed

Lines changed: 36 additions & 36 deletions

File tree

‎drivers/bluetooth/btqca.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct qca_fw_config {
7979
struct edl_event_hdr {
8080
__u8 cresp;
8181
__u8 rtype;
82-
__u8 data[0];
82+
__u8 data[];
8383
} __packed;
8484

8585
struct qca_btsoc_version {
@@ -112,12 +112,12 @@ struct tlv_type_nvm {
112112
__le16 tag_len;
113113
__le32 reserve1;
114114
__le32 reserve2;
115-
__u8 data[0];
115+
__u8 data[];
116116
} __packed;
117117

118118
struct tlv_type_hdr {
119119
__le32 type_len;
120-
__u8 data[0];
120+
__u8 data[];
121121
} __packed;
122122

123123
enum qca_btsoc_type {

‎drivers/bluetooth/btrtl.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ struct rtl_epatch_header {
3838
struct rtl_vendor_config_entry {
3939
__le16 offset;
4040
__u8 len;
41-
__u8 data[0];
41+
__u8 data[];
4242
} __packed;
4343

4444
struct rtl_vendor_config {
4545
__le32 signature;
4646
__le16 total_len;
47-
struct rtl_vendor_config_entry entry[0];
47+
struct rtl_vendor_config_entry entry[];
4848
} __packed;
4949

5050
#if IS_ENABLED(CONFIG_BT_RTL)

‎include/net/bluetooth/hci.h‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ struct hci_cp_sniff_subrate {
935935
struct hci_cp_set_event_flt {
936936
__u8 flt_type;
937937
__u8 cond_type;
938-
__u8 condition[0];
938+
__u8 condition[];
939939
} __packed;
940940

941941
/* Filter types */
@@ -1335,15 +1335,15 @@ struct hci_rp_read_local_amp_assoc {
13351335
__u8 status;
13361336
__u8 phy_handle;
13371337
__le16 rem_len;
1338-
__u8 frag[0];
1338+
__u8 frag[];
13391339
} __packed;
13401340

13411341
#define HCI_OP_WRITE_REMOTE_AMP_ASSOC 0x140b
13421342
struct hci_cp_write_remote_amp_assoc {
13431343
__u8 phy_handle;
13441344
__le16 len_so_far;
13451345
__le16 rem_len;
1346-
__u8 frag[0];
1346+
__u8 frag[];
13471347
} __packed;
13481348
struct hci_rp_write_remote_amp_assoc {
13491349
__u8 status;
@@ -1613,7 +1613,7 @@ struct hci_cp_le_set_ext_scan_params {
16131613
__u8 own_addr_type;
16141614
__u8 filter_policy;
16151615
__u8 scanning_phys;
1616-
__u8 data[0];
1616+
__u8 data[];
16171617
} __packed;
16181618

16191619
#define LE_SCAN_PHY_1M 0x01
@@ -1641,7 +1641,7 @@ struct hci_cp_le_ext_create_conn {
16411641
__u8 peer_addr_type;
16421642
bdaddr_t peer_addr;
16431643
__u8 phys;
1644-
__u8 data[0];
1644+
__u8 data[];
16451645
} __packed;
16461646

16471647
struct hci_cp_le_ext_conn_param {
@@ -1693,7 +1693,7 @@ struct hci_rp_le_set_ext_adv_params {
16931693
struct hci_cp_le_set_ext_adv_enable {
16941694
__u8 enable;
16951695
__u8 num_of_sets;
1696-
__u8 data[0];
1696+
__u8 data[];
16971697
} __packed;
16981698

16991699
struct hci_cp_ext_adv_set {
@@ -1775,14 +1775,14 @@ struct hci_cp_le_set_cig_params {
17751775
__le16 m_latency;
17761776
__le16 s_latency;
17771777
__u8 num_cis;
1778-
struct hci_cis_params cis[0];
1778+
struct hci_cis_params cis[];
17791779
} __packed;
17801780

17811781
struct hci_rp_le_set_cig_params {
17821782
__u8 status;
17831783
__u8 cig_id;
17841784
__u8 num_handles;
1785-
__le16 handle[0];
1785+
__le16 handle[];
17861786
} __packed;
17871787

17881788
#define HCI_OP_LE_CREATE_CIS 0x2064
@@ -1793,7 +1793,7 @@ struct hci_cis {
17931793

17941794
struct hci_cp_le_create_cis {
17951795
__u8 num_cis;
1796-
struct hci_cis cis[0];
1796+
struct hci_cis cis[];
17971797
} __packed;
17981798

17991799
#define HCI_OP_LE_REMOVE_CIG 0x2065
@@ -1937,7 +1937,7 @@ struct hci_comp_pkts_info {
19371937

19381938
struct hci_ev_num_comp_pkts {
19391939
__u8 num_hndl;
1940-
struct hci_comp_pkts_info handles[0];
1940+
struct hci_comp_pkts_info handles[];
19411941
} __packed;
19421942

19431943
#define HCI_EV_MODE_CHANGE 0x14
@@ -2170,7 +2170,7 @@ struct hci_comp_blocks_info {
21702170
struct hci_ev_num_comp_blocks {
21712171
__le16 num_blocks;
21722172
__u8 num_hndl;
2173-
struct hci_comp_blocks_info handles[0];
2173+
struct hci_comp_blocks_info handles[];
21742174
} __packed;
21752175

21762176
#define HCI_EV_SYNC_TRAIN_COMPLETE 0x4F
@@ -2226,7 +2226,7 @@ struct hci_ev_le_advertising_info {
22262226
__u8 bdaddr_type;
22272227
bdaddr_t bdaddr;
22282228
__u8 length;
2229-
__u8 data[0];
2229+
__u8 data[];
22302230
} __packed;
22312231

22322232
#define HCI_EV_LE_CONN_UPDATE_COMPLETE 0x03
@@ -2302,7 +2302,7 @@ struct hci_ev_le_ext_adv_report {
23022302
__u8 direct_addr_type;
23032303
bdaddr_t direct_addr;
23042304
__u8 length;
2305-
__u8 data[0];
2305+
__u8 data[];
23062306
} __packed;
23072307

23082308
#define HCI_EV_LE_ENHANCED_CONN_COMPLETE 0x0a
@@ -2362,7 +2362,7 @@ struct hci_evt_le_cis_req {
23622362
#define HCI_EV_STACK_INTERNAL 0xfd
23632363
struct hci_ev_stack_internal {
23642364
__u16 type;
2365-
__u8 data[0];
2365+
__u8 data[];
23662366
} __packed;
23672367

23682368
#define HCI_EV_SI_DEVICE 0x01
@@ -2409,7 +2409,7 @@ struct hci_sco_hdr {
24092409
struct hci_iso_hdr {
24102410
__le16 handle;
24112411
__le16 dlen;
2412-
__u8 data[0];
2412+
__u8 data[];
24132413
} __packed;
24142414

24152415
/* ISO data packet status flags */

‎include/net/bluetooth/hci_sock.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,19 @@ struct hci_dev_req {
144144

145145
struct hci_dev_list_req {
146146
__u16 dev_num;
147-
struct hci_dev_req dev_req[0]; /* hci_dev_req structures */
147+
struct hci_dev_req dev_req[]; /* hci_dev_req structures */
148148
};
149149

150150
struct hci_conn_list_req {
151151
__u16 dev_id;
152152
__u16 conn_num;
153-
struct hci_conn_info conn_info[0];
153+
struct hci_conn_info conn_info[];
154154
};
155155

156156
struct hci_conn_info_req {
157157
bdaddr_t bdaddr;
158158
__u8 type;
159-
struct hci_conn_info conn_info[0];
159+
struct hci_conn_info conn_info[];
160160
};
161161

162162
struct hci_auth_info_req {

‎include/net/bluetooth/l2cap.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,14 @@ struct l2cap_conn_rsp {
299299
struct l2cap_conf_req {
300300
__le16 dcid;
301301
__le16 flags;
302-
__u8 data[0];
302+
__u8 data[];
303303
} __packed;
304304

305305
struct l2cap_conf_rsp {
306306
__le16 scid;
307307
__le16 flags;
308308
__le16 result;
309-
__u8 data[0];
309+
__u8 data[];
310310
} __packed;
311311

312312
#define L2CAP_CONF_SUCCESS 0x0000
@@ -322,7 +322,7 @@ struct l2cap_conf_rsp {
322322
struct l2cap_conf_opt {
323323
__u8 type;
324324
__u8 len;
325-
__u8 val[0];
325+
__u8 val[];
326326
} __packed;
327327
#define L2CAP_CONF_OPT_SIZE 2
328328

@@ -392,7 +392,7 @@ struct l2cap_info_req {
392392
struct l2cap_info_rsp {
393393
__le16 type;
394394
__le16 result;
395-
__u8 data[0];
395+
__u8 data[];
396396
} __packed;
397397

398398
struct l2cap_create_chan_req {

‎include/net/bluetooth/rfcomm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ struct rfcomm_dev_info {
355355

356356
struct rfcomm_dev_list_req {
357357
u16 dev_num;
358-
struct rfcomm_dev_info dev_info[0];
358+
struct rfcomm_dev_info dev_info[];
359359
};
360360

361361
int rfcomm_dev_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);

‎net/bluetooth/a2mp.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ struct a2mp_cmd {
3636
__u8 code;
3737
__u8 ident;
3838
__le16 len;
39-
__u8 data[0];
39+
__u8 data[];
4040
} __packed;
4141

4242
/* A2MP command codes */
4343
#define A2MP_COMMAND_REJ 0x01
4444
struct a2mp_cmd_rej {
4545
__le16 reason;
46-
__u8 data[0];
46+
__u8 data[];
4747
} __packed;
4848

4949
#define A2MP_DISCOVER_REQ 0x02
@@ -62,7 +62,7 @@ struct a2mp_cl {
6262
struct a2mp_discov_rsp {
6363
__le16 mtu;
6464
__le16 ext_feat;
65-
struct a2mp_cl cl[0];
65+
struct a2mp_cl cl[];
6666
} __packed;
6767

6868
#define A2MP_CHANGE_NOTIFY 0x04
@@ -93,15 +93,15 @@ struct a2mp_amp_assoc_req {
9393
struct a2mp_amp_assoc_rsp {
9494
__u8 id;
9595
__u8 status;
96-
__u8 amp_assoc[0];
96+
__u8 amp_assoc[];
9797
} __packed;
9898

9999
#define A2MP_CREATEPHYSLINK_REQ 0x0A
100100
#define A2MP_DISCONNPHYSLINK_REQ 0x0C
101101
struct a2mp_physlink_req {
102102
__u8 local_id;
103103
__u8 remote_id;
104-
__u8 amp_assoc[0];
104+
__u8 amp_assoc[];
105105
} __packed;
106106

107107
#define A2MP_CREATEPHYSLINK_RSP 0x0B

‎net/bluetooth/bnep/bnep.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ struct bnep_setup_conn_req {
7474
__u8 type;
7575
__u8 ctrl;
7676
__u8 uuid_size;
77-
__u8 service[0];
77+
__u8 service[];
7878
} __packed;
7979

8080
struct bnep_set_filter_req {
8181
__u8 type;
8282
__u8 ctrl;
8383
__be16 len;
84-
__u8 list[0];
84+
__u8 list[];
8585
} __packed;
8686

8787
struct bnep_control_rsp {
@@ -93,7 +93,7 @@ struct bnep_control_rsp {
9393
struct bnep_ext_hdr {
9494
__u8 type;
9595
__u8 len;
96-
__u8 data[0];
96+
__u8 data[];
9797
} __packed;
9898

9999
/* BNEP ioctl defines */

0 commit comments

Comments
 (0)