Skip to content

Commit 1340283

Browse files
committed
Merge tag 'flexible-array-member-5.7-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux
Pull flexible-array member conversion from Gustavo Silva: "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] sizeof(flexible-array-member) triggers a warning because flexible array members have incomplete type[1]. There are some instances of code in which the sizeof operator is being incorrectly/erroneously applied to zero-length arrays and the result is zero. Such instances may be hiding some bugs. So, this work (flexible-array member convertions) will also help to get completely rid of those sorts of issues. Notice that all of these patches have been baking in linux-next for quite a while now and, 238 more of these patches have already been merged into 5.7-rc1. There are a couple hundred more of these issues waiting to be addressed in the whole codebase" [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] KSPP#21 [3] commit 7649773 ("cxgb3/l2t: Fix undefined behaviour") * tag 'flexible-array-member-5.7-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux: (28 commits) xattr.h: Replace zero-length array with flexible-array member uapi: linux: fiemap.h: Replace zero-length array with flexible-array member uapi: linux: dlm_device.h: Replace zero-length array with flexible-array member tpm_eventlog.h: Replace zero-length array with flexible-array member ti_wilink_st.h: Replace zero-length array with flexible-array member swap.h: Replace zero-length array with flexible-array member skbuff.h: Replace zero-length array with flexible-array member sched: topology.h: Replace zero-length array with flexible-array member rslib.h: Replace zero-length array with flexible-array member rio.h: Replace zero-length array with flexible-array member posix_acl.h: Replace zero-length array with flexible-array member platform_data: wilco-ec.h: Replace zero-length array with flexible-array member memcontrol.h: Replace zero-length array with flexible-array member list_lru.h: Replace zero-length array with flexible-array member lib: cpu_rmap: Replace zero-length array with flexible-array member irq.h: Replace zero-length array with flexible-array member ihex.h: Replace zero-length array with flexible-array member igmp.h: Replace zero-length array with flexible-array member genalloc.h: Replace zero-length array with flexible-array member ethtool.h: Replace zero-length array with flexible-array member ...
2 parents 50cc09c + 4395158 commit 1340283

28 files changed

+39
-39
lines changed

include/linux/bio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ struct bio_integrity_payload {
319319
struct work_struct bip_work; /* I/O completion */
320320

321321
struct bio_vec *bip_vec;
322-
struct bio_vec bip_inline_vecs[0];/* embedded bvec array */
322+
struct bio_vec bip_inline_vecs[];/* embedded bvec array */
323323
};
324324

325325
#if defined(CONFIG_BLK_DEV_INTEGRITY)

include/linux/blk-mq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ struct blk_mq_hw_ctx {
173173
* blocking (BLK_MQ_F_BLOCKING). Must be the last member - see also
174174
* blk_mq_hw_ctx_size().
175175
*/
176-
struct srcu_struct srcu[0];
176+
struct srcu_struct srcu[];
177177
};
178178

179179
/**

include/linux/blk_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ struct bio {
198198
* double allocations for a small number of bio_vecs. This member
199199
* MUST obviously be kept at the very end of the bio.
200200
*/
201-
struct bio_vec bi_inline_vecs[0];
201+
struct bio_vec bi_inline_vecs[];
202202
};
203203

204204
#define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs)

include/linux/can/dev/peak_canfd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ struct __packed pucan_rx_msg {
189189
u8 client;
190190
__le16 flags;
191191
__le32 can_id;
192-
u8 d[0];
192+
u8 d[];
193193
};
194194

195195
/* uCAN error types */
@@ -266,7 +266,7 @@ struct __packed pucan_tx_msg {
266266
u8 client;
267267
__le16 flags;
268268
__le32 can_id;
269-
u8 d[0];
269+
u8 d[];
270270
};
271271

272272
/* build the cmd opcode_channel field with respect to the correct endianness */

include/linux/cpu_rmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct cpu_rmap {
2828
struct {
2929
u16 index;
3030
u16 dist;
31-
} near[0];
31+
} near[];
3232
};
3333
#define CPU_RMAP_DIST_INF 0xffff
3434

include/linux/digsig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct pubkey_hdr {
2929
uint32_t timestamp; /* key made, always 0 for now */
3030
uint8_t algo;
3131
uint8_t nmpi;
32-
char mpi[0];
32+
char mpi[];
3333
} __packed;
3434

3535
struct signature_hdr {
@@ -39,7 +39,7 @@ struct signature_hdr {
3939
uint8_t hash;
4040
uint8_t keyid[8];
4141
uint8_t nmpi;
42-
char mpi[0];
42+
char mpi[];
4343
} __packed;
4444

4545
#if defined(CONFIG_SIGNATURE) || defined(CONFIG_SIGNATURE_MODULE)

include/linux/dirent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct linux_dirent64 {
77
s64 d_off;
88
unsigned short d_reclen;
99
unsigned char d_type;
10-
char d_name[0];
10+
char d_name[];
1111
};
1212

1313
#endif

include/linux/enclosure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct enclosure_device {
101101
struct device edev;
102102
struct enclosure_component_callbacks *cb;
103103
int components;
104-
struct enclosure_component component[0];
104+
struct enclosure_component component[];
105105
};
106106

107107
static inline struct enclosure_device *

include/linux/energy_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct em_cap_state {
3636
struct em_perf_domain {
3737
struct em_cap_state *table;
3838
int nr_cap_states;
39-
unsigned long cpus[0];
39+
unsigned long cpus[];
4040
};
4141

4242
#ifdef CONFIG_ENERGY_MODEL

include/linux/ethtool.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct compat_ethtool_rxnfc {
3535
compat_u64 data;
3636
struct compat_ethtool_rx_flow_spec fs;
3737
u32 rule_cnt;
38-
u32 rule_locs[0];
38+
u32 rule_locs[];
3939
};
4040

4141
#endif /* CONFIG_COMPAT */
@@ -462,7 +462,7 @@ int ethtool_check_ops(const struct ethtool_ops *ops);
462462

463463
struct ethtool_rx_flow_rule {
464464
struct flow_rule *rule;
465-
unsigned long priv[0];
465+
unsigned long priv[];
466466
};
467467

468468
struct ethtool_rx_flow_spec_input {

0 commit comments

Comments
 (0)