Merge tag 'flexible-array-member-5.7-rc2' of git://git.kernel.org/pub/scm/linux/kerne...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 19 Apr 2020 17:34:30 +0000 (10:34 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 19 Apr 2020 17:34:30 +0000 (10:34 -0700)
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] commit 76497732932f ("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
  ...

28 files changed:
include/linux/bio.h
include/linux/blk-mq.h
include/linux/blk_types.h
include/linux/can/dev/peak_canfd.h
include/linux/cpu_rmap.h
include/linux/digsig.h
include/linux/dirent.h
include/linux/enclosure.h
include/linux/energy_model.h
include/linux/ethtool.h
include/linux/genalloc.h
include/linux/igmp.h
include/linux/ihex.h
include/linux/irq.h
include/linux/list_lru.h
include/linux/memcontrol.h
include/linux/platform_data/wilco-ec.h
include/linux/posix_acl.h
include/linux/rio.h
include/linux/rslib.h
include/linux/sched/topology.h
include/linux/skbuff.h
include/linux/swap.h
include/linux/ti_wilink_st.h
include/linux/tpm_eventlog.h
include/linux/xattr.h
include/uapi/linux/dlm_device.h
include/uapi/linux/fiemap.h

index c1c0f9e..a0ee494 100644 (file)
@@ -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)
index f389d7c..b45148b 100644 (file)
@@ -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[];
 };
 
 /**
index 70254ae..31eb928 100644 (file)
@@ -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)
index 511a373..5fd627e 100644 (file)
@@ -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 */
index 02edeaf..be8aea0 100644 (file)
@@ -28,7 +28,7 @@ struct cpu_rmap {
        struct {
                u16     index;
                u16     dist;
-       }               near[0];
+       }               near[];
 };
 #define CPU_RMAP_DIST_INF 0xffff
 
index 594fc66..2ace69e 100644 (file)
@@ -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)
index fc61f3c..9900222 100644 (file)
@@ -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
index 564e96f..1c630e2 100644 (file)
@@ -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 *
index d249b88..ade6486 100644 (file)
@@ -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
index c1d379b..a23b26e 100644 (file)
@@ -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 {
index 5b14a0f..0bd5810 100644 (file)
@@ -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 */
 };
 
 /*
index 463047d..faa6586 100644 (file)
@@ -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) + \
index 98cb5ce..b824877 100644 (file)
@@ -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)
index 9315fbb..fa8ad93 100644 (file)
@@ -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 */
index d5ceb28..9dcaa3e 100644 (file)
@@ -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 {
index 1b4150f..d275c72 100644 (file)
@@ -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 {
index 25f46a9..3e268e6 100644 (file)
@@ -83,7 +83,7 @@ struct wilco_ec_response {
        u16 result;
        u16 data_size;
        u8 reserved[2];
-       u8 data[0];
+       u8 data[];
 } __packed;
 
 /**
index 540595a..90797f1 100644 (file)
@@ -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) \
index 317bace..2cd6372 100644 (file)
@@ -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)
index 5974ced..238bb85 100644 (file)
@@ -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  */
index af9319e..95253ad 100644 (file)
@@ -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)
index 3a2ac70..3000c52 100644 (file)
@@ -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);
index b835d8d..e1bbf7a 100644 (file)
@@ -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
index eb6cbdf..44a7f91 100644 (file)
@@ -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 {
index 131ea1b..c253461 100644 (file)
@@ -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 {
index 4cf6e11..47eaa34 100644 (file)
@@ -73,7 +73,7 @@ struct simple_xattr {
        struct list_head list;
        char *name;
        size_t size;
-       char value[0];
+       char value[];
 };
 
 /*
index f880d28..e83954c 100644 (file)
@@ -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 {
index 8c0bc24..7a900b2 100644 (file)
@@ -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)