mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 13:50:52 +07:00
flexible-array member convertion patches for 5.7-rc2
Hi Linus, Please, pull the following patches that replace zero-length arrays with flexible-array members. 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] https://github.com/KSPP/linux/issues/21 [3] commit7649773293
("cxgb3/l2t: Fix undefined behaviour") Thanks -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEkmRahXBSurMIg1YvRwW0y0cG2zEFAl6bccgACgkQRwW0y0cG 2zFYvBAAl5tsoZsb6h5o7+XpWetl2BfA8lRelXWg1la9mF+Zqgqz8raubs+EbR8f 65yz1lvoOl3jgeu1pQnx+AaDdG88Yu66BjPpFz/n8WWBjNC0z3M4Xcu+pFUanEzO QqkCPryj6RlqCYL/WlSCifo+ZOAeM7jlw/2kkX1ILVwjYItFPJIw+5IEPrM0ucN2 tFp9H3iKOlA6PDuj4JO2xCnlUkL5aZk101qKqm41yZLLiS8zE8or4+s8Y7c7yDDP ajQ+uCzJpt/VCn6Iyri0oZ5hp+gI6jJ8ox1Vo0UCuWQ2RJ7E2FE5qhhctwB4UYsg +B6c1yckJqUoJ1c7Bbj00gsNMns3A7uLHFDOGBKQTjkRCn5+QV1wVvv5TJx2LJYL EBt07IfS0YAv0EBIbJyxqzmWCt0unKCu3i1KePp/FYqq291dpr39olUMCa1+Qg98 v1VTGUlOvONy3v41tDx+Bfkt/0ebT8pogyenA51cjsD0bUZ3I/BsGxigXf0myLuy 6yFjx7f6ng2I3uBDSZ+H/KUM51H6yhB9UCQuQCSqHDU3iEHvh7dDdumD3A9OJyLw nPC2HQhTOHVkbtg/E0KFh/ak1PoELCH3CR1Kgj/NSOG2Mz5tgtBfoxa+GwJTvJha 9m5JrBQcT7qF7pGtZU0NDQICrhhvUEX/Hwo3QAtYInWPsV3S+5U= =GsIm -----END PGP SIGNATURE----- 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] https://github.com/KSPP/linux/issues/21 [3] commit7649773293
("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 ...
This commit is contained in:
commit
1340283741
@ -319,7 +319,7 @@ struct bio_integrity_payload {
|
||||
struct work_struct bip_work; /* I/O completion */
|
||||
|
||||
struct bio_vec *bip_vec;
|
||||
struct bio_vec bip_inline_vecs[0];/* embedded bvec array */
|
||||
struct bio_vec bip_inline_vecs[];/* embedded bvec array */
|
||||
};
|
||||
|
||||
#if defined(CONFIG_BLK_DEV_INTEGRITY)
|
||||
|
@ -173,7 +173,7 @@ struct blk_mq_hw_ctx {
|
||||
* blocking (BLK_MQ_F_BLOCKING). Must be the last member - see also
|
||||
* blk_mq_hw_ctx_size().
|
||||
*/
|
||||
struct srcu_struct srcu[0];
|
||||
struct srcu_struct srcu[];
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -198,7 +198,7 @@ struct bio {
|
||||
* double allocations for a small number of bio_vecs. This member
|
||||
* MUST obviously be kept at the very end of the bio.
|
||||
*/
|
||||
struct bio_vec bi_inline_vecs[0];
|
||||
struct bio_vec bi_inline_vecs[];
|
||||
};
|
||||
|
||||
#define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs)
|
||||
|
@ -189,7 +189,7 @@ struct __packed pucan_rx_msg {
|
||||
u8 client;
|
||||
__le16 flags;
|
||||
__le32 can_id;
|
||||
u8 d[0];
|
||||
u8 d[];
|
||||
};
|
||||
|
||||
/* uCAN error types */
|
||||
@ -266,7 +266,7 @@ struct __packed pucan_tx_msg {
|
||||
u8 client;
|
||||
__le16 flags;
|
||||
__le32 can_id;
|
||||
u8 d[0];
|
||||
u8 d[];
|
||||
};
|
||||
|
||||
/* build the cmd opcode_channel field with respect to the correct endianness */
|
||||
|
@ -28,7 +28,7 @@ struct cpu_rmap {
|
||||
struct {
|
||||
u16 index;
|
||||
u16 dist;
|
||||
} near[0];
|
||||
} near[];
|
||||
};
|
||||
#define CPU_RMAP_DIST_INF 0xffff
|
||||
|
||||
|
@ -29,7 +29,7 @@ struct pubkey_hdr {
|
||||
uint32_t timestamp; /* key made, always 0 for now */
|
||||
uint8_t algo;
|
||||
uint8_t nmpi;
|
||||
char mpi[0];
|
||||
char mpi[];
|
||||
} __packed;
|
||||
|
||||
struct signature_hdr {
|
||||
@ -39,7 +39,7 @@ struct signature_hdr {
|
||||
uint8_t hash;
|
||||
uint8_t keyid[8];
|
||||
uint8_t nmpi;
|
||||
char mpi[0];
|
||||
char mpi[];
|
||||
} __packed;
|
||||
|
||||
#if defined(CONFIG_SIGNATURE) || defined(CONFIG_SIGNATURE_MODULE)
|
||||
|
@ -7,7 +7,7 @@ struct linux_dirent64 {
|
||||
s64 d_off;
|
||||
unsigned short d_reclen;
|
||||
unsigned char d_type;
|
||||
char d_name[0];
|
||||
char d_name[];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -101,7 +101,7 @@ struct enclosure_device {
|
||||
struct device edev;
|
||||
struct enclosure_component_callbacks *cb;
|
||||
int components;
|
||||
struct enclosure_component component[0];
|
||||
struct enclosure_component component[];
|
||||
};
|
||||
|
||||
static inline struct enclosure_device *
|
||||
|
@ -36,7 +36,7 @@ struct em_cap_state {
|
||||
struct em_perf_domain {
|
||||
struct em_cap_state *table;
|
||||
int nr_cap_states;
|
||||
unsigned long cpus[0];
|
||||
unsigned long cpus[];
|
||||
};
|
||||
|
||||
#ifdef CONFIG_ENERGY_MODEL
|
||||
|
@ -35,7 +35,7 @@ struct compat_ethtool_rxnfc {
|
||||
compat_u64 data;
|
||||
struct compat_ethtool_rx_flow_spec fs;
|
||||
u32 rule_cnt;
|
||||
u32 rule_locs[0];
|
||||
u32 rule_locs[];
|
||||
};
|
||||
|
||||
#endif /* CONFIG_COMPAT */
|
||||
@ -462,7 +462,7 @@ int ethtool_check_ops(const struct ethtool_ops *ops);
|
||||
|
||||
struct ethtool_rx_flow_rule {
|
||||
struct flow_rule *rule;
|
||||
unsigned long priv[0];
|
||||
unsigned long priv[];
|
||||
};
|
||||
|
||||
struct ethtool_rx_flow_spec_input {
|
||||
|
@ -76,7 +76,7 @@ struct gen_pool_chunk {
|
||||
void *owner; /* private data to retrieve at alloc time */
|
||||
unsigned long start_addr; /* start address of memory chunk */
|
||||
unsigned long end_addr; /* end address of memory chunk (inclusive) */
|
||||
unsigned long bits[0]; /* bitmap for allocating memory chunk */
|
||||
unsigned long bits[]; /* bitmap for allocating memory chunk */
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -38,7 +38,7 @@ struct ip_sf_socklist {
|
||||
unsigned int sl_max;
|
||||
unsigned int sl_count;
|
||||
struct rcu_head rcu;
|
||||
__be32 sl_addr[0];
|
||||
__be32 sl_addr[];
|
||||
};
|
||||
|
||||
#define IP_SFLSIZE(count) (sizeof(struct ip_sf_socklist) + \
|
||||
|
@ -18,7 +18,7 @@
|
||||
struct ihex_binrec {
|
||||
__be32 addr;
|
||||
__be16 len;
|
||||
uint8_t data[0];
|
||||
uint8_t data[];
|
||||
} __attribute__((packed));
|
||||
|
||||
static inline uint16_t ihex_binrec_size(const struct ihex_binrec *p)
|
||||
|
@ -1043,7 +1043,7 @@ struct irq_chip_generic {
|
||||
unsigned long unused;
|
||||
struct irq_domain *domain;
|
||||
struct list_head list;
|
||||
struct irq_chip_type chip_types[0];
|
||||
struct irq_chip_type chip_types[];
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1079,7 +1079,7 @@ struct irq_domain_chip_generic {
|
||||
unsigned int irq_flags_to_clear;
|
||||
unsigned int irq_flags_to_set;
|
||||
enum irq_gc_flags gc_flags;
|
||||
struct irq_chip_generic *gc[0];
|
||||
struct irq_chip_generic *gc[];
|
||||
};
|
||||
|
||||
/* Generic chip callback functions */
|
||||
|
@ -34,7 +34,7 @@ struct list_lru_one {
|
||||
struct list_lru_memcg {
|
||||
struct rcu_head rcu;
|
||||
/* array of per cgroup lists, indexed by memcg_cache_id */
|
||||
struct list_lru_one *lru[0];
|
||||
struct list_lru_one *lru[];
|
||||
};
|
||||
|
||||
struct list_lru_node {
|
||||
|
@ -106,7 +106,7 @@ struct lruvec_stat {
|
||||
*/
|
||||
struct memcg_shrinker_map {
|
||||
struct rcu_head rcu;
|
||||
unsigned long map[0];
|
||||
unsigned long map[];
|
||||
};
|
||||
|
||||
/*
|
||||
@ -148,7 +148,7 @@ struct mem_cgroup_threshold_ary {
|
||||
/* Size of entries[] */
|
||||
unsigned int size;
|
||||
/* Array of thresholds */
|
||||
struct mem_cgroup_threshold entries[0];
|
||||
struct mem_cgroup_threshold entries[];
|
||||
};
|
||||
|
||||
struct mem_cgroup_thresholds {
|
||||
|
@ -83,7 +83,7 @@ struct wilco_ec_response {
|
||||
u16 result;
|
||||
u16 data_size;
|
||||
u8 reserved[2];
|
||||
u8 data[0];
|
||||
u8 data[];
|
||||
} __packed;
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@ struct posix_acl {
|
||||
refcount_t a_refcount;
|
||||
struct rcu_head a_rcu;
|
||||
unsigned int a_count;
|
||||
struct posix_acl_entry a_entries[0];
|
||||
struct posix_acl_entry a_entries[];
|
||||
};
|
||||
|
||||
#define FOREACH_ACL_ENTRY(pa, acl, pe) \
|
||||
|
@ -100,7 +100,7 @@ struct rio_switch {
|
||||
u32 port_ok;
|
||||
struct rio_switch_ops *ops;
|
||||
spinlock_t lock;
|
||||
struct rio_dev *nextdev[0];
|
||||
struct rio_dev *nextdev[];
|
||||
};
|
||||
|
||||
/**
|
||||
@ -201,7 +201,7 @@ struct rio_dev {
|
||||
u8 hopcount;
|
||||
struct rio_dev *prev;
|
||||
atomic_t state;
|
||||
struct rio_switch rswitch[0]; /* RIO switch info */
|
||||
struct rio_switch rswitch[]; /* RIO switch info */
|
||||
};
|
||||
|
||||
#define rio_dev_g(n) list_entry(n, struct rio_dev, global_list)
|
||||
|
@ -54,7 +54,7 @@ struct rs_codec {
|
||||
*/
|
||||
struct rs_control {
|
||||
struct rs_codec *codec;
|
||||
uint16_t buffers[0];
|
||||
uint16_t buffers[];
|
||||
};
|
||||
|
||||
/* General purpose RS codec, 8-bit data width, symbol width 1-15 bit */
|
||||
|
@ -142,7 +142,7 @@ struct sched_domain {
|
||||
* by attaching extra space to the end of the structure,
|
||||
* depending on how many CPUs the kernel has booted up with)
|
||||
*/
|
||||
unsigned long span[0];
|
||||
unsigned long span[];
|
||||
};
|
||||
|
||||
static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
|
||||
|
@ -4162,7 +4162,7 @@ struct skb_ext {
|
||||
refcount_t refcnt;
|
||||
u8 offset[SKB_EXT_NUM]; /* in chunks of 8 bytes */
|
||||
u8 chunks; /* same */
|
||||
char data[0] __aligned(8);
|
||||
char data[] __aligned(8);
|
||||
};
|
||||
|
||||
struct skb_ext *__skb_ext_alloc(void);
|
||||
|
@ -275,7 +275,7 @@ struct swap_info_struct {
|
||||
*/
|
||||
struct work_struct discard_work; /* discard worker */
|
||||
struct swap_cluster_list discard_clusters; /* discard clusters list */
|
||||
struct plist_node avail_lists[0]; /*
|
||||
struct plist_node avail_lists[]; /*
|
||||
* entries in swap_avail_heads, one
|
||||
* entry per node.
|
||||
* Must be last as the number of the
|
||||
|
@ -295,7 +295,7 @@ struct bts_header {
|
||||
u32 magic;
|
||||
u32 version;
|
||||
u8 future[24];
|
||||
u8 actions[0];
|
||||
u8 actions[];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/**
|
||||
@ -305,7 +305,7 @@ struct bts_header {
|
||||
struct bts_action {
|
||||
u16 type;
|
||||
u16 size;
|
||||
u8 data[0];
|
||||
u8 data[];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct bts_action_send {
|
||||
@ -315,7 +315,7 @@ struct bts_action_send {
|
||||
struct bts_action_wait {
|
||||
u32 msec;
|
||||
u32 size;
|
||||
u8 data[0];
|
||||
u8 data[];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct bts_action_delay {
|
||||
|
@ -28,7 +28,7 @@ struct tcpa_event {
|
||||
u32 event_type;
|
||||
u8 pcr_value[20]; /* SHA1 */
|
||||
u32 event_size;
|
||||
u8 event_data[0];
|
||||
u8 event_data[];
|
||||
};
|
||||
|
||||
enum tcpa_event_types {
|
||||
@ -55,7 +55,7 @@ enum tcpa_event_types {
|
||||
struct tcpa_pc_event {
|
||||
u32 event_id;
|
||||
u32 event_size;
|
||||
u8 event_data[0];
|
||||
u8 event_data[];
|
||||
};
|
||||
|
||||
enum tcpa_pc_event_ids {
|
||||
@ -102,7 +102,7 @@ struct tcg_pcr_event {
|
||||
|
||||
struct tcg_event_field {
|
||||
u32 event_size;
|
||||
u8 event[0];
|
||||
u8 event[];
|
||||
} __packed;
|
||||
|
||||
struct tcg_pcr_event2_head {
|
||||
|
@ -73,7 +73,7 @@ struct simple_xattr {
|
||||
struct list_head list;
|
||||
char *name;
|
||||
size_t size;
|
||||
char value[0];
|
||||
char value[];
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -45,13 +45,13 @@ struct dlm_lock_params {
|
||||
void __user *bastaddr;
|
||||
struct dlm_lksb __user *lksb;
|
||||
char lvb[DLM_USER_LVB_LEN];
|
||||
char name[0];
|
||||
char name[];
|
||||
};
|
||||
|
||||
struct dlm_lspace_params {
|
||||
__u32 flags;
|
||||
__u32 minor;
|
||||
char name[0];
|
||||
char name[];
|
||||
};
|
||||
|
||||
struct dlm_purge_params {
|
||||
|
@ -34,7 +34,7 @@ struct fiemap {
|
||||
__u32 fm_mapped_extents;/* number of extents that were mapped (out) */
|
||||
__u32 fm_extent_count; /* size of fm_extents array (in) */
|
||||
__u32 fm_reserved;
|
||||
struct fiemap_extent fm_extents[0]; /* array of mapped extents (out) */
|
||||
struct fiemap_extent fm_extents[]; /* array of mapped extents (out) */
|
||||
};
|
||||
|
||||
#define FIEMAP_MAX_OFFSET (~0ULL)
|
||||
|
Loading…
Reference in New Issue
Block a user