clean up zero-length arrays
Subsystems (4)
cover clean up zero-length arrays
This patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned ones
app/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 +-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 +-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 +++---- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 +-- drivers/crypto/virtio/virtio_ring.h | 4 +-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/mlx5/mlx5_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 +-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 +-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 +-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 +-- lib/table/rte_table_hash_key16.c | 4 +-- lib/table/rte_table_hash_key32.c | 4 +-- lib/table/rte_table_hash_key8.c | 4 +-- lib/vhost/rte_vhost.h | 4 +-- 40 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci create mode 100644 lib/count_comments.py
--
2.34.1
PATCH 1/4 cocci: add script for zero-length arrays in structs
Add script to replace [0] with [] when used at the end of a struct. The script also includes an additional struct member to match against so as to avoid issues with arrays with only a single zero-length element.
--- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 devtools/cocci/zero_length_array.cocci
devtools/cocci/zero_length_array.cocci new file +21 -0
@@ -0,0 +1,21 @@ +// Replace zero-length array members with [] +@@ +identifier st, member, arr; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +}; +@@ +identifier st, member, arr, id; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +} id;
Signature · 1 line
2.34.1
PATCH 2/4 drivers: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- drivers/bus/dpaa/include/netcfg.h | 4 ++-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 +++++----- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 ++-- drivers/crypto/virtio/virtio_ring.h | 4 ++-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/mlx5/mlx5_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 ++-- 23 files changed, 33 insertions(+), 33 deletions(-)
drivers/bus/dpaa/include/netcfg.h +2 -2
@@ -23,7 +23,7 @@ struct fm_eth_port_cfg {struct netcfg_info {uint8_t num_ethports;/**< Number of ports */ -struct fm_eth_port_cfg port_cfg[0 ]; +struct fm_eth_port_cfg port_cfg[];/**< Variable structure array of size num_ethports */ };
@@ -38,7 +38,7 @@ struct interface_info {struct netcfg_interface {uint8_t numof_netcfg_interface;uint8_t numof_fman_enabled_macless; -struct interface_info interface_info[0 ]; +struct interface_info interface_info[]; };/* pcd_file: FMC netpcd XML ("policy") file, that contains PCD information.
drivers/bus/vmbus/rte_vmbus_reg.h +2 -2
@@ -107,7 +107,7 @@ struct vmbus_bufring {* Ring data starts here + RingDataStartOffset * !!! DO NOT place any fields below this !!! */ -uint8_t data[0 ]; +uint8_t data[]; } __rte_packed;/*
@@ -140,7 +140,7 @@ vmbus_chanpkt_getlen(uint16_t pktlen)struct vmbus_gpa_range {uint32_t len;uint32_t ofs; -uint64_t page[0 ]; +uint64_t page[]; } __rte_packed;/* This is actually vmbus_gpa_range.gpa_page[1] */
drivers/common/cnxk/roc_se.h +1 -1
@@ -246,7 +246,7 @@ struct roc_se_buf_ptr {/* IOV Pointer */ struct roc_se_iov_ptr {int buf_cnt; -struct roc_se_buf_ptr bufs[0 ]; +struct roc_se_buf_ptr bufs[]; };struct roc_se_fc_params {
drivers/common/dpaax/caamflib/desc/ipsec.h +1 -1
@@ -350,7 +350,7 @@ struct ipsec_encap_pdb { };uint32_t spi;uint32_t ip_hdr_len; -uint8_t ip_hdr[0 ]; +uint8_t ip_hdr[]; }; static inline unsigned int
drivers/common/dpaax/dpaax_iova_table.h +1 -1
@@ -32,7 +32,7 @@ struct dpaax_iovat_element {struct dpaax_iova_table {unsigned int count;/**< No. of blocks of contiguous physical pages */ -struct dpaax_iovat_element entries[0 ]; +struct dpaax_iovat_element entries[]; };/* Pointer to the table, which is common for DPAA/DPAA2 and only a single
drivers/common/mlx5/mlx5_prm.h +5 -5
@@ -560,7 +560,7 @@ struct mlx5_umr_wqe {struct mlx5_rdma_write_wqe {struct mlx5_wqe_cseg ctr;struct mlx5_wqe_rseg rseg; -struct mlx5_wqe_dseg dseg[0 ]; +struct mlx5_wqe_dseg dseg[]; } __rte_packed;#ifdef PEDANTIC
@@ -3478,7 +3478,7 @@ struct mlx5_ifc_qpc_pas_list_bits {#endif struct mlx5_ifc_qpc_extension_and_pas_list_bits {struct mlx5_ifc_qpc_extension_bits qpc_data_extension; -u8 pas[0 ][0x40 ]; + u8[0x40] pas[]; };
@@ -3702,7 +3702,7 @@ struct mlx5_ifc_query_qp_out_bits {u8 reserved_at_a0[0x20 ];struct mlx5_ifc_qpc_bits qpc;u8 reserved_at_800[0x80 ]; -u8 pas[0 ][0x40 ]; + u8[0x40] pas[]; };#ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic"
@@ -3742,7 +3742,7 @@ struct mlx5_ifc_access_register_out_bits {u8 reserved_at_8[0x18 ];u8 syndrome[0x20 ];u8 reserved_at_40[0x40 ]; -u8 register_data[0 ][0x20 ]; + u8[0x20] register_data[]; };struct mlx5_ifc_access_register_in_bits {
@@ -3753,7 +3753,7 @@ struct mlx5_ifc_access_register_in_bits {u8 reserved_at_40[0x10 ];u8 register_id[0x10 ];u8 argument[0x20 ]; -u8 register_data[0 ][0x20 ]; + u8[0x20] register_data[]; };#ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic"
drivers/crypto/ipsec_mb/ipsec_mb_private.h +2 -2
@@ -120,7 +120,7 @@ struct ipsec_mb_dev_private {/**< PMD type */ uint32_t max_nb_queue_pairs;/**< Max number of queue pairs supported by device */ - __extension__uint8_t priv[0 ]; + __extension__uint8_t priv[]; };/** IPSEC Multi buffer queue pair common queue pair data for all PMDs */
@@ -147,7 +147,7 @@ struct ipsec_mb_qp {/* Multi buffer manager */ const struct rte_memzone *mb_mgr_mz;/* Shared memzone for storing mb_mgr */ - __extension__uint8_t additional_data[0 ]; + __extension__uint8_t additional_data[];/**< Storing PMD specific additional data */ };
drivers/crypto/virtio/virtio_ring.h +2 -2
@@ -40,7 +40,7 @@ struct vring_desc {struct vring_avail {uint16_t flags;uint16_t idx; -uint16_t ring[0 ]; +uint16_t ring[]; };/* id is a 16bit index. uint32_t is used here for ids for padding reasons. */
@@ -54,7 +54,7 @@ struct vring_used_elem {struct vring_used {uint16_t flags;volatile uint16_t idx; -struct vring_used_elem ring[0 ]; +struct vring_used_elem ring[]; };struct vring {
drivers/crypto/virtio/virtqueue.h +1 -1
@@ -88,7 +88,7 @@ struct virtqueue {uint16_t *notify_addr; -struct vq_desc_extra vq_descx[0 ]; +struct vq_desc_extra vq_descx[]; };/**
drivers/net/atlantic/hw_atl/hw_atl_utils.h +1 -1
@@ -334,7 +334,7 @@ struct offload_info {struct offload_port_info ports;struct offload_ka_info kas;struct offload_rr_info rrs; -u8 buf[0 ]; +u8 buf[]; } __rte_packed;struct smbus_request {
drivers/net/cxgbe/clip_tbl.h +1 -1
@@ -20,7 +20,7 @@ struct clip_tbl {unsigned int clipt_start;/* start index of CLIP table */ unsigned int clipt_size;/* size of CLIP table */ rte_rwlock_t lock;/* table rw lock */ -struct clip_entry cl_list[0 ];/* MUST BE LAST */ +struct clip_entry cl_list[];/* MUST BE LAST */ }; struct clip_tbl *t4_init_clip_tbl(unsigned int clipt_start,
drivers/net/cxgbe/l2t.h +1 -1
@@ -37,7 +37,7 @@ struct l2t_data {unsigned int l2t_start;/* start index of our piece of the L2T */ unsigned int l2t_size;/* number of entries in l2tab */ rte_rwlock_t lock;/* table rw lock */ -struct l2t_entry l2tab[0 ];/* MUST BE LAST */ +struct l2t_entry l2tab[];/* MUST BE LAST */ };#define L2T_LPBK true
drivers/net/cxgbe/mps_tcam.h +1 -1
@@ -41,7 +41,7 @@ struct mpstcam_table {* free_idx cannot alone determine * if the table is full */ -struct mps_tcam_entry entry[0 ]; +struct mps_tcam_entry entry[]; };struct mpstcam_table *t4_init_mpstcam (struct adapter *adap);
drivers/net/cxgbe/smt.h +1 -1
@@ -31,7 +31,7 @@ struct smt_data {unsigned int smt_size;unsigned int smt_start;rte_rwlock_t lock; -struct smt_entry smtab[0 ]; +struct smt_entry smtab[]; };struct smt_data *t4_init_smt (u32 smt_start_idx,u32 smt_size);
drivers/net/enic/base/vnic_devcmd.h +1 -1
@@ -997,7 +997,7 @@ enum {struct filter_tlv {uint32_t type;uint32_t length; -uint32_t val[0 ]; +uint32_t val[]; };/* Data for CMD_ADD_FILTER is 2 TLV and filter + action structs */
drivers/net/hinic/hinic_pmd_tx.h +1 -1
@@ -81,7 +81,7 @@ struct hinic_sq_wqe {struct hinic_sq_task task;/* sq sge section start address, 1~127 sges */ -struct hinic_sq_bufdesc buf_descs[0 ]; +struct hinic_sq_bufdesc buf_descs[]; };struct hinic_txq_stats {
drivers/net/mlx5/mlx5_tx.h +1 -1
@@ -166,7 +166,7 @@ struct mlx5_txq_data {struct mlx5_txq_stats stats;/* TX queue counters. */ struct mlx5_txq_stats stats_reset;/* stats on last reset. */ struct mlx5_uar_data uar_data; -struct rte_mbuf *elts[0 ]; +struct rte_mbuf *elts[];/* Storage for queued packets, must be the last field. */ } __rte_cache_aligned;
drivers/net/nfp/nfpcore/nfp_nsp.h +1 -1
@@ -224,7 +224,7 @@ struct nfp_eth_table {int is_split;unsigned int fec_modes_supported; - } ports[0 ]; + } ports[]; };struct nfp_eth_table *nfp_eth_read_ports (struct nfp_cpp *cpp);
drivers/net/virtio/virtio_ring.h +2 -2
@@ -46,7 +46,7 @@ struct vring_desc {struct vring_avail {uint16_t flags;uint16_t idx; -uint16_t ring[0 ]; +uint16_t ring[]; };/* id is a 16bit index. uint32_t is used here for ids for padding reasons. */
@@ -60,7 +60,7 @@ struct vring_used_elem {struct vring_used {uint16_t flags;uint16_t idx; -struct vring_used_elem ring[0 ]; +struct vring_used_elem ring[]; };/* For support of packed virtqueues in Virtio 1.1 the format of descriptors
drivers/net/virtio/virtio_user/vhost_kernel.c +1 -1
@@ -22,7 +22,7 @@ struct vhost_kernel_data {struct vhost_memory_kernel {uint32_t nregions;uint32_t padding; -struct vhost_memory_region regions[0 ]; +struct vhost_memory_region regions[]; };/* vhost kernel ioctls */
drivers/net/virtio/virtio_user/vhost_vdpa.c +1 -1
@@ -70,7 +70,7 @@ struct vhost_iotlb_msg {struct vhost_vdpa_config {uint32_t off;uint32_t len; -uint8_t buf[0 ]; +uint8_t buf[]; };struct vhost_msg {
drivers/net/virtio/virtqueue.h +1 -1
@@ -309,7 +309,7 @@ struct virtqueue {uint16_t *notify_addr;struct rte_mbuf **sw_ring;/**< RX software ring. */ -struct vq_desc_extra vq_descx[0 ]; +struct vq_desc_extra vq_descx[]; };/* If multiqueue is provided by host, then we support it. */
drivers/regex/mlx5/mlx5_rxp.h +2 -2
@@ -64,7 +64,7 @@ struct mlx5_rxp_match_tuple {struct mlx5_rxp_response {struct mlx5_rxp_response_desc header; -struct mlx5_rxp_match_tuple matches[0 ]; +struct mlx5_rxp_match_tuple matches[]; };#define MLX5_RXP_MAX_MATCHES 254
@@ -114,7 +114,7 @@ struct mlx5_rxp_rof {struct mlx5_rxp_ctl_rules_pgm {struct mlx5_rxp_ctl_hdr hdr;uint32_t count; -struct mlx5_rxp_rof_entry rules[0 ]; +struct mlx5_rxp_rof_entry rules[]; } __rte_packed;/* RXP programming mode setting. */
Signature · 1 line
2.34.1
PATCH 3/4 lib: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_hash_key16.c | 4 ++-- lib/table/rte_table_hash_key32.c | 4 ++-- lib/table/rte_table_hash_key8.c | 4 ++-- lib/vhost/rte_vhost.h | 4 ++-- 13 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 lib/count_comments.py
lib/cryptodev/cryptodev_pmd.h +1 -1
@@ -637,7 +637,7 @@ RTE_STD_C11 struct rte_cryptodev_asym_session {uint16_t user_data_sz;/**< Session user data will be placed after sess_data */ uint8_t padding[3 ]; -uint8_t sess_private_data[0 ]; +uint8_t sess_private_data[]; };#ifdef __cplusplus
lib/cryptodev/rte_cryptodev.h +1 -1
@@ -912,7 +912,7 @@ struct rte_cryptodev_sym_session { __extension__struct {void *data;uint16_t refcnt; - } sess_data[0 ]; + } sess_data[];/**< Driver specific session material, variable size */ };
lib/eventdev/rte_event_timer_adapter.h +1 -1
@@ -486,7 +486,7 @@ struct rte_event_timer {*/ enum rte_event_timer_state state;/**< State of the event timer. */ -uint8_t user_meta[0 ]; +uint8_t user_meta[];/**< Memory to store user specific metadata. * The event timer adapter implementation should not modify this area. */
lib/ip_frag/ip_reassembly.h +1 -1
@@ -83,7 +83,7 @@ struct rte_ip_frag_tbl {struct ip_frag_pkt *last;/* last used entry. */ struct ip_pkt_list lru;/* LRU list for table entries. */ struct ip_frag_tbl_stat stat;/* statistics counters. */ - __extension__ struct ip_frag_pkt pkt[0]; /* hash table. */ + __extension__ struct ip_frag_pkt pkt[]; /* hash table. */ };#endif /* _IP_REASSEMBLY_H_ */
lib/ipsec/sa.h +1 -1
@@ -59,7 +59,7 @@ union sym_op_data {struct replay_sqn {rte_rwlock_t rwl;uint64_t sqn; - __extension__uint64_t window[0 ]; + __extension__uint64_t window[]; };/*IPSEC SA supported algorithms */
lib/rib/rte_rib.c +1 -1
@@ -35,7 +35,7 @@ struct rte_rib_node {uint8_t depth;uint8_t flag;uint64_t nh; - __extension__uint64_t ext[0 ]; + __extension__uint64_t ext[]; };struct rte_rib {
lib/rib/rte_rib6.c +1 -1
@@ -34,7 +34,7 @@ struct rte_rib6_node {uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE ];uint8_t depth;uint8_t flag; - __extension__uint64_t ext[0 ]; + __extension__uint64_t ext[]; };struct rte_rib6 {
lib/table/rte_swx_table_learner.c +2 -2
@@ -252,7 +252,7 @@ struct table_bucket {uint32_t sig[TABLE_KEYS_PER_BUCKET ];uint8_t key_timeout_id[TABLE_KEYS_PER_BUCKET ];uint8_t pad[TABLE_BUCKET_PAD_SIZE ]; -uint8_t key[0 ]; +uint8_t key[]; };struct table_params {
@@ -317,7 +317,7 @@ struct table {uint8_t key_mask0[RTE_CACHE_LINE_SIZE ];/* Table buckets. */ -uint8_t buckets[0 ]; +uint8_t buckets[]; } __rte_cache_aligned;/* The timeout (in cycles) is stored in the table as a 32-bit value by truncating its least
lib/table/rte_table_hash_key16.c +2 -2
@@ -43,7 +43,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_16 {
@@ -58,7 +58,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/table/rte_table_hash_key32.c +2 -2
@@ -43,7 +43,7 @@ struct rte_bucket_4_32 {uint64_t key[4 ][4 ];/* Cache line 3 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_32 {
@@ -58,7 +58,7 @@ struct rte_bucket_4_32 {uint64_t key[4 ][4 ];/* Cache line 3 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/table/rte_table_hash_key8.c +2 -2
@@ -40,7 +40,7 @@ struct rte_bucket_4_8 {uint64_t key[4 ];/* Cache line 1 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_8 {
@@ -54,7 +54,7 @@ struct rte_bucket_4_8 {uint64_t key[4 ];/* Cache line 1 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/vhost/rte_vhost.h +2 -2
@@ -154,7 +154,7 @@ struct rte_vhost_inflight_info_split {uint16_t desc_num;uint16_t last_inflight_io;uint16_t used_idx; -struct rte_vhost_inflight_desc_split desc[0 ]; +struct rte_vhost_inflight_desc_split desc[]; };struct rte_vhost_inflight_desc_packed {
@@ -181,7 +181,7 @@ struct rte_vhost_inflight_info_packed {uint8_t used_wrap_counter;uint8_t old_used_wrap_counter;uint8_t padding[7 ]; -struct rte_vhost_inflight_desc_packed desc[0 ]; +struct rte_vhost_inflight_desc_packed desc[]; };struct rte_vhost_resubmit_desc {
--
2.34.1
PATCH 4/4 app: examples: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- app/test/test_table_tables.c | 2 +- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
app/test/test_table_tables.c +1 -1
@@ -53,7 +53,7 @@ struct rte_bucket_4_8 {uint64_t next_valid;uint64_t key[4 ];/* Cache line 1 */ -uint8_t data[0 ]; +uint8_t data[]; };#if RTE_TABLE_HASH_LRU_STRATEGY ==3
examples/ip_reassembly/main.c +1 -1
@@ -126,7 +126,7 @@ struct mbuf_table {uint32_t len;uint32_t head;uint32_t tail; -struct rte_mbuf *m_table[0 ]; +struct rte_mbuf *m_table[]; };struct rx_queue {
examples/ptpclient/ptpclient.c +2 -2
@@ -90,7 +90,7 @@ struct sync_msg {struct follow_up_msg {struct ptp_header hdr;struct tstamp precise_origin_tstamp; -uint8_t suffix[0 ]; +uint8_t suffix[]; } __rte_packed;struct delay_req_msg {
@@ -102,7 +102,7 @@ struct delay_resp_msg {struct ptp_header hdr;struct tstamp rx_tstamp;struct port_id req_port_id; -uint8_t suffix[0 ]; +uint8_t suffix[]; } __rte_packed;struct ptp_message {
Signature · 1 line
2.34.1
Quoted 56 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Thursday, 2 June 2022 17.09This patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned onesapp/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 +-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 +-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 +++---- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 +-- drivers/crypto/virtio/virtio_ring.h | 4 +-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/mlx5/mlx5_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 +-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 +-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 +-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 +-- lib/table/rte_table_hash_key16.c | 4 +-- lib/table/rte_table_hash_key32.c | 4 +-- lib/table/rte_table_hash_key8.c | 4 +-- lib/vhost/rte_vhost.h | 4 +-- 40 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci create mode 100644 lib/count_comments.py
Quoted 3 lines
--
2.34.1
Quoted 53 lines · On Thu, 2 Jun 2022 16:08:30 +0100 Bruce Richardson…
This patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned onesapp/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 +-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 +-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 +++---- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 +-- drivers/crypto/virtio/virtio_ring.h | 4 +-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/mlx5/mlx5_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 +-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 +-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 +-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 +-- lib/table/rte_table_hash_key16.c | 4 +-- lib/table/rte_table_hash_key32.c | 4 +-- lib/table/rte_table_hash_key8.c | 4 +-- lib/vhost/rte_vhost.h | 4 +-- 40 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci create mode 100644 lib/count_comments.py
Quoted 3 lines
--
2.34.1
Would it be possible to add check for zero length arrays in checkpatch? So that new drivers don't bring the problem back.
v2 cover clean up zero-length arrays
In reply to Bruce RichardsonThis patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
V2: rebased to fix apply conflict
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned ones
app/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 ++-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 ++++----- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 ++-- drivers/crypto/virtio/virtio_ring.h | 4 ++-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/mlx5/mlx5_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 ++-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 ++-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_hash_key16.c | 4 ++-- lib/table/rte_table_hash_key32.c | 4 ++-- lib/table/rte_table_hash_key8.c | 4 ++-- lib/vhost/rte_vhost.h | 4 ++-- 39 files changed, 75 insertions(+), 54 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci
--
2.34.1
PATCH v2 1/4 cocci: add script for zero-length arrays in structs
Add script to replace [0] with [] when used at the end of a struct. The script also includes an additional struct member to match against so as to avoid issues with arrays with only a single zero-length element.
--- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 devtools/cocci/zero_length_array.cocci
devtools/cocci/zero_length_array.cocci new file +21 -0
@@ -0,0 +1,21 @@ +// Replace zero-length array members with [] +@@ +identifier st, member, arr; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +}; +@@ +identifier st, member, arr, id; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +} id;
Signature · 1 line
2.34.1
PATCH v2 2/4 drivers: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- drivers/bus/dpaa/include/netcfg.h | 4 ++-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 +++++----- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 ++-- drivers/crypto/virtio/virtio_ring.h | 4 ++-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/mlx5/mlx5_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 ++-- 23 files changed, 33 insertions(+), 33 deletions(-)
drivers/bus/dpaa/include/netcfg.h +2 -2
@@ -23,7 +23,7 @@ struct fm_eth_port_cfg {struct netcfg_info {uint8_t num_ethports;/**< Number of ports */ -struct fm_eth_port_cfg port_cfg[0 ]; +struct fm_eth_port_cfg port_cfg[];/**< Variable structure array of size num_ethports */ };
@@ -38,7 +38,7 @@ struct interface_info {struct netcfg_interface {uint8_t numof_netcfg_interface;uint8_t numof_fman_enabled_macless; -struct interface_info interface_info[0 ]; +struct interface_info interface_info[]; };/* pcd_file: FMC netpcd XML ("policy") file, that contains PCD information.
drivers/bus/vmbus/rte_vmbus_reg.h +2 -2
@@ -107,7 +107,7 @@ struct vmbus_bufring {* Ring data starts here + RingDataStartOffset * !!! DO NOT place any fields below this !!! */ -uint8_t data[0 ]; +uint8_t data[]; } __rte_packed;/*
@@ -140,7 +140,7 @@ vmbus_chanpkt_getlen(uint16_t pktlen)struct vmbus_gpa_range {uint32_t len;uint32_t ofs; -uint64_t page[0 ]; +uint64_t page[]; } __rte_packed;/* This is actually vmbus_gpa_range.gpa_page[1] */
drivers/common/cnxk/roc_se.h +1 -1
@@ -246,7 +246,7 @@ struct roc_se_buf_ptr {/* IOV Pointer */ struct roc_se_iov_ptr {int buf_cnt; -struct roc_se_buf_ptr bufs[0 ]; +struct roc_se_buf_ptr bufs[]; };struct roc_se_fc_params {
drivers/common/dpaax/caamflib/desc/ipsec.h +1 -1
@@ -350,7 +350,7 @@ struct ipsec_encap_pdb { };uint32_t spi;uint32_t ip_hdr_len; -uint8_t ip_hdr[0 ]; +uint8_t ip_hdr[]; }; static inline unsigned int
drivers/common/dpaax/dpaax_iova_table.h +1 -1
@@ -32,7 +32,7 @@ struct dpaax_iovat_element {struct dpaax_iova_table {unsigned int count;/**< No. of blocks of contiguous physical pages */ -struct dpaax_iovat_element entries[0 ]; +struct dpaax_iovat_element entries[]; };/* Pointer to the table, which is common for DPAA/DPAA2 and only a single
drivers/common/mlx5/mlx5_prm.h +5 -5
@@ -560,7 +560,7 @@ struct mlx5_umr_wqe {struct mlx5_rdma_write_wqe {struct mlx5_wqe_cseg ctr;struct mlx5_wqe_rseg rseg; -struct mlx5_wqe_dseg dseg[0 ]; +struct mlx5_wqe_dseg dseg[]; } __rte_packed;#ifdef PEDANTIC
@@ -3479,7 +3479,7 @@ struct mlx5_ifc_qpc_pas_list_bits {#endif struct mlx5_ifc_qpc_extension_and_pas_list_bits {struct mlx5_ifc_qpc_extension_bits qpc_data_extension; -u8 pas[0 ][0x40 ]; + u8[0x40] pas[]; };
@@ -3703,7 +3703,7 @@ struct mlx5_ifc_query_qp_out_bits {u8 reserved_at_a0[0x20 ];struct mlx5_ifc_qpc_bits qpc;u8 reserved_at_800[0x80 ]; -u8 pas[0 ][0x40 ]; + u8[0x40] pas[]; };#ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic"
@@ -3743,7 +3743,7 @@ struct mlx5_ifc_access_register_out_bits {u8 reserved_at_8[0x18 ];u8 syndrome[0x20 ];u8 reserved_at_40[0x40 ]; -u8 register_data[0 ][0x20 ]; + u8[0x20] register_data[]; };struct mlx5_ifc_access_register_in_bits {
@@ -3754,7 +3754,7 @@ struct mlx5_ifc_access_register_in_bits {u8 reserved_at_40[0x10 ];u8 register_id[0x10 ];u8 argument[0x20 ]; -u8 register_data[0 ][0x20 ]; + u8[0x20] register_data[]; };#ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic"
drivers/crypto/ipsec_mb/ipsec_mb_private.h +2 -2
@@ -120,7 +120,7 @@ struct ipsec_mb_dev_private {/**< PMD type */ uint32_t max_nb_queue_pairs;/**< Max number of queue pairs supported by device */ - __extension__uint8_t priv[0 ]; + __extension__uint8_t priv[]; };/** IPSEC Multi buffer queue pair common queue pair data for all PMDs */
@@ -147,7 +147,7 @@ struct ipsec_mb_qp {/* Multi buffer manager */ const struct rte_memzone *mb_mgr_mz;/* Shared memzone for storing mb_mgr */ - __extension__uint8_t additional_data[0 ]; + __extension__uint8_t additional_data[];/**< Storing PMD specific additional data */ };
drivers/crypto/virtio/virtio_ring.h +2 -2
@@ -40,7 +40,7 @@ struct vring_desc {struct vring_avail {uint16_t flags;uint16_t idx; -uint16_t ring[0 ]; +uint16_t ring[]; };/* id is a 16bit index. uint32_t is used here for ids for padding reasons. */
@@ -54,7 +54,7 @@ struct vring_used_elem {struct vring_used {uint16_t flags;volatile uint16_t idx; -struct vring_used_elem ring[0 ]; +struct vring_used_elem ring[]; };struct vring {
drivers/crypto/virtio/virtqueue.h +1 -1
@@ -88,7 +88,7 @@ struct virtqueue {uint16_t *notify_addr; -struct vq_desc_extra vq_descx[0 ]; +struct vq_desc_extra vq_descx[]; };/**
drivers/net/atlantic/hw_atl/hw_atl_utils.h +1 -1
@@ -334,7 +334,7 @@ struct offload_info {struct offload_port_info ports;struct offload_ka_info kas;struct offload_rr_info rrs; -u8 buf[0 ]; +u8 buf[]; } __rte_packed;struct smbus_request {
drivers/net/cxgbe/clip_tbl.h +1 -1
@@ -20,7 +20,7 @@ struct clip_tbl {unsigned int clipt_start;/* start index of CLIP table */ unsigned int clipt_size;/* size of CLIP table */ rte_rwlock_t lock;/* table rw lock */ -struct clip_entry cl_list[0 ];/* MUST BE LAST */ +struct clip_entry cl_list[];/* MUST BE LAST */ }; struct clip_tbl *t4_init_clip_tbl(unsigned int clipt_start,
drivers/net/cxgbe/l2t.h +1 -1
@@ -37,7 +37,7 @@ struct l2t_data {unsigned int l2t_start;/* start index of our piece of the L2T */ unsigned int l2t_size;/* number of entries in l2tab */ rte_rwlock_t lock;/* table rw lock */ -struct l2t_entry l2tab[0 ];/* MUST BE LAST */ +struct l2t_entry l2tab[];/* MUST BE LAST */ };#define L2T_LPBK true
drivers/net/cxgbe/mps_tcam.h +1 -1
@@ -41,7 +41,7 @@ struct mpstcam_table {* free_idx cannot alone determine * if the table is full */ -struct mps_tcam_entry entry[0 ]; +struct mps_tcam_entry entry[]; };struct mpstcam_table *t4_init_mpstcam (struct adapter *adap);
drivers/net/cxgbe/smt.h +1 -1
@@ -31,7 +31,7 @@ struct smt_data {unsigned int smt_size;unsigned int smt_start;rte_rwlock_t lock; -struct smt_entry smtab[0 ]; +struct smt_entry smtab[]; };struct smt_data *t4_init_smt (u32 smt_start_idx,u32 smt_size);
drivers/net/enic/base/vnic_devcmd.h +1 -1
@@ -997,7 +997,7 @@ enum {struct filter_tlv {uint32_t type;uint32_t length; -uint32_t val[0 ]; +uint32_t val[]; };/* Data for CMD_ADD_FILTER is 2 TLV and filter + action structs */
drivers/net/hinic/hinic_pmd_tx.h +1 -1
@@ -81,7 +81,7 @@ struct hinic_sq_wqe {struct hinic_sq_task task;/* sq sge section start address, 1~127 sges */ -struct hinic_sq_bufdesc buf_descs[0 ]; +struct hinic_sq_bufdesc buf_descs[]; };struct hinic_txq_stats {
drivers/net/mlx5/mlx5_tx.h +1 -1
@@ -166,7 +166,7 @@ struct mlx5_txq_data {struct mlx5_txq_stats stats;/* TX queue counters. */ struct mlx5_txq_stats stats_reset;/* stats on last reset. */ struct mlx5_uar_data uar_data; -struct rte_mbuf *elts[0 ]; +struct rte_mbuf *elts[];/* Storage for queued packets, must be the last field. */ } __rte_cache_aligned;
drivers/net/nfp/nfpcore/nfp_nsp.h +1 -1
@@ -224,7 +224,7 @@ struct nfp_eth_table {int is_split;unsigned int fec_modes_supported; - } ports[0 ]; + } ports[]; };struct nfp_eth_table *nfp_eth_read_ports (struct nfp_cpp *cpp);
drivers/net/virtio/virtio_ring.h +2 -2
@@ -46,7 +46,7 @@ struct vring_desc {struct vring_avail {uint16_t flags;uint16_t idx; -uint16_t ring[0 ]; +uint16_t ring[]; };/* id is a 16bit index. uint32_t is used here for ids for padding reasons. */
@@ -60,7 +60,7 @@ struct vring_used_elem {struct vring_used {uint16_t flags;uint16_t idx; -struct vring_used_elem ring[0 ]; +struct vring_used_elem ring[]; };/* For support of packed virtqueues in Virtio 1.1 the format of descriptors
drivers/net/virtio/virtio_user/vhost_kernel.c +1 -1
@@ -22,7 +22,7 @@ struct vhost_kernel_data {struct vhost_memory_kernel {uint32_t nregions;uint32_t padding; -struct vhost_memory_region regions[0 ]; +struct vhost_memory_region regions[]; };/* vhost kernel ioctls */
drivers/net/virtio/virtio_user/vhost_vdpa.c +1 -1
@@ -70,7 +70,7 @@ struct vhost_iotlb_msg {struct vhost_vdpa_config {uint32_t off;uint32_t len; -uint8_t buf[0 ]; +uint8_t buf[]; };struct vhost_msg {
drivers/net/virtio/virtqueue.h +1 -1
@@ -309,7 +309,7 @@ struct virtqueue {uint16_t *notify_addr;struct rte_mbuf **sw_ring;/**< RX software ring. */ -struct vq_desc_extra vq_descx[0 ]; +struct vq_desc_extra vq_descx[]; };/* If multiqueue is provided by host, then we support it. */
drivers/regex/mlx5/mlx5_rxp.h +2 -2
@@ -64,7 +64,7 @@ struct mlx5_rxp_match_tuple {struct mlx5_rxp_response {struct mlx5_rxp_response_desc header; -struct mlx5_rxp_match_tuple matches[0 ]; +struct mlx5_rxp_match_tuple matches[]; };#define MLX5_RXP_MAX_MATCHES 254
@@ -114,7 +114,7 @@ struct mlx5_rxp_rof {struct mlx5_rxp_ctl_rules_pgm {struct mlx5_rxp_ctl_hdr hdr;uint32_t count; -struct mlx5_rxp_rof_entry rules[0 ]; +struct mlx5_rxp_rof_entry rules[]; } __rte_packed;/* RXP programming mode setting. */
Signature · 1 line
2.34.1
Re: [PATCH v2 2/4] drivers: replace zero-length arrays with undimensioned ones
Hello Bruce,
Quoted 14 lines · Bruce Richardson
drivers/common/mlx5/mlx5_prm.h +1
-1@@ -560,7 +560,7 @@ struct mlx5_umr_wqe {struct mlx5_rdma_write_wqe {struct mlx5_wqe_cseg ctr;struct mlx5_wqe_rseg rseg; -struct mlx5_wqe_dseg dseg[0 ]; +struct mlx5_wqe_dseg dseg[]; } __rte_packed;#ifdef PEDANTIC
drivers/common/mlx5/mlx5_prm.h struct mlx5_ifc_qpc_pas_list_bits { · line 3482
Quoted 5 lines
drivers/common/mlx5/mlx5_prm.h +1
-1@@ -3479,7 +3479,7 @@ struct mlx5_ifc_qpc_pas_list_bits {#endif struct mlx5_ifc_qpc_extension_and_pas_list_bits {struct mlx5_ifc_qpc_extension_bits qpc_data_extension; -u8 pas[0 ][0x40 ]; + u8[0x40] pas[];
Gcc and clang seem to agree they disagree with coccinelle. clang suggests using u8 pas[][0x40].
Signature · 1 line
David Marchand
Re: [PATCH v2 2/4] drivers: replace zero-length arrays with undimensioned ones
Quoted 16 lines · David Marchand
Hello Bruce,
Quoted 12 lines · Bruce Richardson
drivers/common/mlx5/mlx5_prm.h +1
-1@@ -560,7 +560,7 @@ struct mlx5_umr_wqe {struct mlx5_rdma_write_wqe {struct mlx5_wqe_cseg ctr;struct mlx5_wqe_rseg rseg; -struct mlx5_wqe_dseg dseg[0 ]; +struct mlx5_wqe_dseg dseg[]; } __rte_packed;
Quoted 11 lines
drivers/common/mlx5/mlx5_prm.h struct mlx5_ifc_qpc_pas_list_bits { · line 3482
Quoted 7 lines
drivers/common/mlx5/mlx5_prm.h +1
-1#ifdef PEDANTIC @@ -3479,7 +3479,7 @@ struct mlx5_ifc_qpc_pas_list_bits {#endif struct mlx5_ifc_qpc_extension_and_pas_list_bits {struct mlx5_ifc_qpc_extension_bits qpc_data_extension; -u8 pas[0 ][0x40 ]; + u8[0x40] pas[];Gcc and clang seem to agree they disagree with coccinelle. clang suggests using u8 pas[][0x40].
Will fix in v3.
Quoted 4 lines
Signature · 2 lines
-- David Marchand
Re: [PATCH v2 2/4] drivers: replace zero-length arrays with undimensioned ones
In reply to David MarchandQuoted 16 lines · David Marchand
Hello Bruce,
Quoted 12 lines · Bruce Richardson
drivers/common/mlx5/mlx5_prm.h +1
-1@@ -560,7 +560,7 @@ struct mlx5_umr_wqe {struct mlx5_rdma_write_wqe {struct mlx5_wqe_cseg ctr;struct mlx5_wqe_rseg rseg; -struct mlx5_wqe_dseg dseg[0 ]; +struct mlx5_wqe_dseg dseg[]; } __rte_packed;
Quoted 11 lines
drivers/common/mlx5/mlx5_prm.h struct mlx5_ifc_qpc_pas_list_bits { · line 3482
Quoted 7 lines
drivers/common/mlx5/mlx5_prm.h +1
-1#ifdef PEDANTIC @@ -3479,7 +3479,7 @@ struct mlx5_ifc_qpc_pas_list_bits {#endif struct mlx5_ifc_qpc_extension_and_pas_list_bits {struct mlx5_ifc_qpc_extension_bits qpc_data_extension; -u8 pas[0 ][0x40 ]; + u8[0x40] pas[];Gcc and clang seem to agree they disagree with coccinelle. clang suggests using u8 pas[][0x40].
Changing this as suggested gives further errors in builds (now that I have the correct dependencies for the mlx5 driver installed on my system!)
In file included from ../../drivers/net/mlx5/mlx5_tx_empw.c:6:../../drivers/net/mlx5/mlx5_tx.h:187:30: error: invalid use of structure with flexible array member [-Werror=pedantic]
187 | struct mlx5_txq_data txq; /* Data path structure. */
| ^~~
cc1: all warnings being treated as errors
Therefore, I'll just drop the cleanup of these structures from V3.
/Bruce
PATCH v2 3/4 lib: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_hash_key16.c | 4 ++-- lib/table/rte_table_hash_key32.c | 4 ++-- lib/table/rte_table_hash_key8.c | 4 ++-- lib/vhost/rte_vhost.h | 4 ++-- 12 files changed, 17 insertions(+), 17 deletions(-)
lib/cryptodev/cryptodev_pmd.h +1 -1
@@ -673,7 +673,7 @@ RTE_STD_C11 struct rte_cryptodev_asym_session {uint8_t padding[3 ];void *event_mdata;/**< Event metadata (aka *union rte_event_crypto_metadata*) */ -uint8_t sess_private_data[0 ]; +uint8_t sess_private_data[]; };#ifdef __cplusplus
lib/cryptodev/rte_cryptodev.h +1 -1
@@ -918,7 +918,7 @@ struct rte_cryptodev_sym_session { __extension__struct {void *data;uint16_t refcnt; - } sess_data[0 ]; + } sess_data[];/**< Driver specific session material, variable size */ };
lib/eventdev/rte_event_timer_adapter.h +1 -1
@@ -486,7 +486,7 @@ struct rte_event_timer {*/ enum rte_event_timer_state state;/**< State of the event timer. */ -uint8_t user_meta[0 ]; +uint8_t user_meta[];/**< Memory to store user specific metadata. * The event timer adapter implementation should not modify this area. */
lib/ip_frag/ip_reassembly.h +1 -1
@@ -83,7 +83,7 @@ struct rte_ip_frag_tbl {struct ip_frag_pkt *last;/* last used entry. */ struct ip_pkt_list lru;/* LRU list for table entries. */ struct ip_frag_tbl_stat stat;/* statistics counters. */ - __extension__ struct ip_frag_pkt pkt[0]; /* hash table. */ + __extension__ struct ip_frag_pkt pkt[]; /* hash table. */ };#endif /* _IP_REASSEMBLY_H_ */
lib/ipsec/sa.h +1 -1
@@ -59,7 +59,7 @@ union sym_op_data {struct replay_sqn {rte_rwlock_t rwl;uint64_t sqn; - __extension__uint64_t window[0 ]; + __extension__uint64_t window[]; };/*IPSEC SA supported algorithms */
lib/rib/rte_rib.c +1 -1
@@ -35,7 +35,7 @@ struct rte_rib_node {uint8_t depth;uint8_t flag;uint64_t nh; - __extension__uint64_t ext[0 ]; + __extension__uint64_t ext[]; };struct rte_rib {
lib/rib/rte_rib6.c +1 -1
@@ -34,7 +34,7 @@ struct rte_rib6_node {uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE ];uint8_t depth;uint8_t flag; - __extension__uint64_t ext[0 ]; + __extension__uint64_t ext[]; };struct rte_rib6 {
lib/table/rte_swx_table_learner.c +2 -2
@@ -252,7 +252,7 @@ struct table_bucket {uint32_t sig[TABLE_KEYS_PER_BUCKET ];uint8_t key_timeout_id[TABLE_KEYS_PER_BUCKET ];uint8_t pad[TABLE_BUCKET_PAD_SIZE ]; -uint8_t key[0 ]; +uint8_t key[]; };struct table_params {
@@ -317,7 +317,7 @@ struct table {uint8_t key_mask0[RTE_CACHE_LINE_SIZE ];/* Table buckets. */ -uint8_t buckets[0 ]; +uint8_t buckets[]; } __rte_cache_aligned;/* The timeout (in cycles) is stored in the table as a 32-bit value by truncating its least
lib/table/rte_table_hash_key16.c +2 -2
@@ -43,7 +43,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_16 {
@@ -58,7 +58,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/table/rte_table_hash_key32.c +2 -2
@@ -43,7 +43,7 @@ struct rte_bucket_4_32 {uint64_t key[4 ][4 ];/* Cache line 3 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_32 {
@@ -58,7 +58,7 @@ struct rte_bucket_4_32 {uint64_t key[4 ][4 ];/* Cache line 3 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/table/rte_table_hash_key8.c +2 -2
@@ -40,7 +40,7 @@ struct rte_bucket_4_8 {uint64_t key[4 ];/* Cache line 1 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_8 {
@@ -54,7 +54,7 @@ struct rte_bucket_4_8 {uint64_t key[4 ];/* Cache line 1 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/vhost/rte_vhost.h +2 -2
@@ -154,7 +154,7 @@ struct rte_vhost_inflight_info_split {uint16_t desc_num;uint16_t last_inflight_io;uint16_t used_idx; -struct rte_vhost_inflight_desc_split desc[0 ]; +struct rte_vhost_inflight_desc_split desc[]; };struct rte_vhost_inflight_desc_packed {
@@ -181,7 +181,7 @@ struct rte_vhost_inflight_info_packed {uint8_t used_wrap_counter;uint8_t old_used_wrap_counter;uint8_t padding[7 ]; -struct rte_vhost_inflight_desc_packed desc[0 ]; +struct rte_vhost_inflight_desc_packed desc[]; };struct rte_vhost_resubmit_desc {
Signature · 1 line
2.34.1
PATCH v2 4/4 app: examples: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- app/test/test_table_tables.c | 2 +- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
app/test/test_table_tables.c +1 -1
@@ -53,7 +53,7 @@ struct rte_bucket_4_8 {uint64_t next_valid;uint64_t key[4 ];/* Cache line 1 */ -uint8_t data[0 ]; +uint8_t data[]; };#if RTE_TABLE_HASH_LRU_STRATEGY ==3
examples/ip_reassembly/main.c +1 -1
@@ -126,7 +126,7 @@ struct mbuf_table {uint32_t len;uint32_t head;uint32_t tail; -struct rte_mbuf *m_table[0 ]; +struct rte_mbuf *m_table[]; };struct rx_queue {
examples/ptpclient/ptpclient.c +2 -2
@@ -90,7 +90,7 @@ struct sync_msg {struct follow_up_msg {struct ptp_header hdr;struct tstamp precise_origin_tstamp; -uint8_t suffix[0 ]; +uint8_t suffix[]; } __rte_packed;struct delay_req_msg {
@@ -102,7 +102,7 @@ struct delay_resp_msg {struct ptp_header hdr;struct tstamp rx_tstamp;struct port_id req_port_id; -uint8_t suffix[0 ]; +uint8_t suffix[]; } __rte_packed;struct ptp_message {
Signature · 1 line
2.34.1
Series-
Quoted 57 lines · Bruce Richardson
This patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
V2: rebased to fix apply conflict
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned onesapp/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 ++-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 ++++----- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 ++-- drivers/crypto/virtio/virtio_ring.h | 4 ++-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/mlx5/mlx5_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 ++-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 ++-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_hash_key16.c | 4 ++-- lib/table/rte_table_hash_key32.c | 4 ++-- lib/table/rte_table_hash_key8.c | 4 ++-- lib/vhost/rte_vhost.h | 4 ++-- 39 files changed, 75 insertions(+), 54 deletions(-)create mode 100644
devtools/cocci/zero_length_array.cocci--
2.34.1
v3 cover clean up zero-length arrays
In reply to Bruce RichardsonThis patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
V3: Fixed issues in mlx5 drivers:
* fixed incorrect coccinelle replacement of 2-D zero-length arrays
* undid removal of "0" in tx elts[] which caused issues with Werror-pedantic
V2: rebased to fix apply conflict
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned ones
app/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 ++-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 ++++----- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 ++-- drivers/crypto/virtio/virtio_ring.h | 4 ++-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 ++-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 ++-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_hash_key16.c | 4 ++-- lib/table/rte_table_hash_key32.c | 4 ++-- lib/table/rte_table_hash_key8.c | 4 ++-- lib/vhost/rte_vhost.h | 4 ++-- 38 files changed, 74 insertions(+), 53 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci
--
2.34.1
PATCH v3 1/4 cocci: add script for zero-length arrays in structs
Add script to replace [0] with [] when used at the end of a struct. The script also includes an additional struct member to match against so as to avoid issues with arrays with only a single zero-length element.
--- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 devtools/cocci/zero_length_array.cocci
devtools/cocci/zero_length_array.cocci new file +21 -0
@@ -0,0 +1,21 @@ +// Replace zero-length array members with [] +@@ +identifier st, member, arr; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +}; +@@ +identifier st, member, arr, id; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +} id;
Signature · 1 line
2.34.1
RE: [PATCH v3 1/4] cocci: add script for zero-length arrays in structs
Quoted 46 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 3 June 2022 12.13Add script to replace [0] with [] when used at the end of a struct. The script also includes an additional struct member to match against so
as to avoid issues with arrays with only a single zero-length element.Signed-off-by Bruce Richardson <[email protected]>Acked-by Morten Brørup <[email protected]>Acked-by Hemant Agrawal <[email protected]>--- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 devtools/cocci/zero_length_array.coccidevtools/cocci/zero_length_array.cocci new file +21
-1@@ -0,0 +1,21 @@ +// Replace zero-length array members with [] +@@ +identifier st, member, arr; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +}; +@@ +identifier st, member, arr, id; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +} id; --
Quoted 2 lines
2.34.1
Formally, arr[0] could be the only field in the structure, i.e. with no preceding fields. It would be silly, but consider checking for that too.
PS: No worries about the name. Scandinavian letters can cause all sorts of problems.
Re: [PATCH v3 1/4] cocci: add script for zero-length arrays in structs
Quoted 42 lines · Morten Brørup
Quoted 42 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 3 June 2022 12.13Add script to replace [0] with [] when used at the end of a struct. The script also includes an additional struct member to match against so
as to avoid issues with arrays with only a single zero-length element.Signed-off-by Bruce Richardson <[email protected]>Acked-by Morten Brørup <[email protected]>Acked-by Hemant Agrawal <[email protected]>--- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 devtools/cocci/zero_length_array.coccidevtools/cocci/zero_length_array.cocci new file +18
-0@@ -0,0 +1,21 @@ +// Replace zero-length array members with [] +@@ +identifier st, member, arr; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +}; +@@ +identifier st, member, arr, id; +type T1, T2; +@@ +struct st { + ... + T1 member;
Quoted 9 lines
Quoted 6 lines
devtools/cocci/zero_length_array.cocci new file +3
-1+- T2 arr[0]; ++ T2 arr[]; +} id; --2.34.1
Formally, arr[0] could be the only field in the structure, i.e. with no preceding fields. It would be silly, but consider checking for that too.
I actually had that originally, but the compiler will complain on structures where there is only an unsized element. Therefore, I made the script only do replacements on structs which had at least one other element.
PATCH v3 2/4 drivers: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
---
V3: Fixed issues in mlx5 drivers:
* fixed incorrect coccinelle replacement of 2-D zero-length arrays
* undid removal of "0" in tx elts[] which caused issues with Werror-pedantic
drivers/bus/dpaa/include/netcfg.h | 4 ++-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 +++++----- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 ++-- drivers/crypto/virtio/virtio_ring.h | 4 ++-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 ++-- 22 files changed, 32 insertions(+), 32 deletions(-)
drivers/bus/dpaa/include/netcfg.h +2 -2
@@ -23,7 +23,7 @@ struct fm_eth_port_cfg {struct netcfg_info {uint8_t num_ethports;/**< Number of ports */ -struct fm_eth_port_cfg port_cfg[0 ]; +struct fm_eth_port_cfg port_cfg[];/**< Variable structure array of size num_ethports */ };
@@ -38,7 +38,7 @@ struct interface_info {struct netcfg_interface {uint8_t numof_netcfg_interface;uint8_t numof_fman_enabled_macless; -struct interface_info interface_info[0 ]; +struct interface_info interface_info[]; };/* pcd_file: FMC netpcd XML ("policy") file, that contains PCD information.
drivers/bus/vmbus/rte_vmbus_reg.h +2 -2
@@ -107,7 +107,7 @@ struct vmbus_bufring {* Ring data starts here + RingDataStartOffset * !!! DO NOT place any fields below this !!! */ -uint8_t data[0 ]; +uint8_t data[]; } __rte_packed;/*
@@ -140,7 +140,7 @@ vmbus_chanpkt_getlen(uint16_t pktlen)struct vmbus_gpa_range {uint32_t len;uint32_t ofs; -uint64_t page[0 ]; +uint64_t page[]; } __rte_packed;/* This is actually vmbus_gpa_range.gpa_page[1] */
drivers/common/cnxk/roc_se.h +1 -1
@@ -246,7 +246,7 @@ struct roc_se_buf_ptr {/* IOV Pointer */ struct roc_se_iov_ptr {int buf_cnt; -struct roc_se_buf_ptr bufs[0 ]; +struct roc_se_buf_ptr bufs[]; };struct roc_se_fc_params {
drivers/common/dpaax/caamflib/desc/ipsec.h +1 -1
@@ -350,7 +350,7 @@ struct ipsec_encap_pdb { };uint32_t spi;uint32_t ip_hdr_len; -uint8_t ip_hdr[0 ]; +uint8_t ip_hdr[]; }; static inline unsigned int
drivers/common/dpaax/dpaax_iova_table.h +1 -1
@@ -32,7 +32,7 @@ struct dpaax_iovat_element {struct dpaax_iova_table {unsigned int count;/**< No. of blocks of contiguous physical pages */ -struct dpaax_iovat_element entries[0 ]; +struct dpaax_iovat_element entries[]; };/* Pointer to the table, which is common for DPAA/DPAA2 and only a single
drivers/common/mlx5/mlx5_prm.h +5 -5
@@ -560,7 +560,7 @@ struct mlx5_umr_wqe {struct mlx5_rdma_write_wqe {struct mlx5_wqe_cseg ctr;struct mlx5_wqe_rseg rseg; -struct mlx5_wqe_dseg dseg[0 ]; +struct mlx5_wqe_dseg dseg[]; } __rte_packed;#ifdef PEDANTIC
@@ -3479,7 +3479,7 @@ struct mlx5_ifc_qpc_pas_list_bits {#endif struct mlx5_ifc_qpc_extension_and_pas_list_bits {struct mlx5_ifc_qpc_extension_bits qpc_data_extension; -u8 pas[0 ][0x40 ]; +u8 pas[][0x40 ]; };
@@ -3703,7 +3703,7 @@ struct mlx5_ifc_query_qp_out_bits {u8 reserved_at_a0[0x20 ];struct mlx5_ifc_qpc_bits qpc;u8 reserved_at_800[0x80 ]; -u8 pas[0 ][0x40 ]; +u8 pas[][0x40 ]; };#ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic"
@@ -3743,7 +3743,7 @@ struct mlx5_ifc_access_register_out_bits {u8 reserved_at_8[0x18 ];u8 syndrome[0x20 ];u8 reserved_at_40[0x40 ]; -u8 register_data[0 ][0x20 ]; +u8 register_data[][0x20 ]; };struct mlx5_ifc_access_register_in_bits {
@@ -3754,7 +3754,7 @@ struct mlx5_ifc_access_register_in_bits {u8 reserved_at_40[0x10 ];u8 register_id[0x10 ];u8 argument[0x20 ]; -u8 register_data[0 ][0x20 ]; +u8 register_data[][0x20 ]; };#ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic"
drivers/crypto/ipsec_mb/ipsec_mb_private.h +2 -2
@@ -120,7 +120,7 @@ struct ipsec_mb_dev_private {/**< PMD type */ uint32_t max_nb_queue_pairs;/**< Max number of queue pairs supported by device */ - __extension__uint8_t priv[0 ]; + __extension__uint8_t priv[]; };/** IPSEC Multi buffer queue pair common queue pair data for all PMDs */
@@ -147,7 +147,7 @@ struct ipsec_mb_qp {/* Multi buffer manager */ const struct rte_memzone *mb_mgr_mz;/* Shared memzone for storing mb_mgr */ - __extension__uint8_t additional_data[0 ]; + __extension__uint8_t additional_data[];/**< Storing PMD specific additional data */ };
drivers/crypto/virtio/virtio_ring.h +2 -2
@@ -40,7 +40,7 @@ struct vring_desc {struct vring_avail {uint16_t flags;uint16_t idx; -uint16_t ring[0 ]; +uint16_t ring[]; };/* id is a 16bit index. uint32_t is used here for ids for padding reasons. */
@@ -54,7 +54,7 @@ struct vring_used_elem {struct vring_used {uint16_t flags;volatile uint16_t idx; -struct vring_used_elem ring[0 ]; +struct vring_used_elem ring[]; };struct vring {
drivers/crypto/virtio/virtqueue.h +1 -1
@@ -88,7 +88,7 @@ struct virtqueue {uint16_t *notify_addr; -struct vq_desc_extra vq_descx[0 ]; +struct vq_desc_extra vq_descx[]; };/**
drivers/net/atlantic/hw_atl/hw_atl_utils.h +1 -1
@@ -334,7 +334,7 @@ struct offload_info {struct offload_port_info ports;struct offload_ka_info kas;struct offload_rr_info rrs; -u8 buf[0 ]; +u8 buf[]; } __rte_packed;struct smbus_request {
drivers/net/cxgbe/clip_tbl.h +1 -1
@@ -20,7 +20,7 @@ struct clip_tbl {unsigned int clipt_start;/* start index of CLIP table */ unsigned int clipt_size;/* size of CLIP table */ rte_rwlock_t lock;/* table rw lock */ -struct clip_entry cl_list[0 ];/* MUST BE LAST */ +struct clip_entry cl_list[];/* MUST BE LAST */ }; struct clip_tbl *t4_init_clip_tbl(unsigned int clipt_start,
drivers/net/cxgbe/l2t.h +1 -1
@@ -37,7 +37,7 @@ struct l2t_data {unsigned int l2t_start;/* start index of our piece of the L2T */ unsigned int l2t_size;/* number of entries in l2tab */ rte_rwlock_t lock;/* table rw lock */ -struct l2t_entry l2tab[0 ];/* MUST BE LAST */ +struct l2t_entry l2tab[];/* MUST BE LAST */ };#define L2T_LPBK true
drivers/net/cxgbe/mps_tcam.h +1 -1
@@ -41,7 +41,7 @@ struct mpstcam_table {* free_idx cannot alone determine * if the table is full */ -struct mps_tcam_entry entry[0 ]; +struct mps_tcam_entry entry[]; };struct mpstcam_table *t4_init_mpstcam (struct adapter *adap);
drivers/net/cxgbe/smt.h +1 -1
@@ -31,7 +31,7 @@ struct smt_data {unsigned int smt_size;unsigned int smt_start;rte_rwlock_t lock; -struct smt_entry smtab[0 ]; +struct smt_entry smtab[]; };struct smt_data *t4_init_smt (u32 smt_start_idx,u32 smt_size);
drivers/net/enic/base/vnic_devcmd.h +1 -1
@@ -997,7 +997,7 @@ enum {struct filter_tlv {uint32_t type;uint32_t length; -uint32_t val[0 ]; +uint32_t val[]; };/* Data for CMD_ADD_FILTER is 2 TLV and filter + action structs */
drivers/net/hinic/hinic_pmd_tx.h +1 -1
@@ -81,7 +81,7 @@ struct hinic_sq_wqe {struct hinic_sq_task task;/* sq sge section start address, 1~127 sges */ -struct hinic_sq_bufdesc buf_descs[0 ]; +struct hinic_sq_bufdesc buf_descs[]; };struct hinic_txq_stats {
drivers/net/nfp/nfpcore/nfp_nsp.h +1 -1
@@ -224,7 +224,7 @@ struct nfp_eth_table {int is_split;unsigned int fec_modes_supported; - } ports[0 ]; + } ports[]; };struct nfp_eth_table *nfp_eth_read_ports (struct nfp_cpp *cpp);
drivers/net/virtio/virtio_ring.h +2 -2
@@ -46,7 +46,7 @@ struct vring_desc {struct vring_avail {uint16_t flags;uint16_t idx; -uint16_t ring[0 ]; +uint16_t ring[]; };/* id is a 16bit index. uint32_t is used here for ids for padding reasons. */
@@ -60,7 +60,7 @@ struct vring_used_elem {struct vring_used {uint16_t flags;uint16_t idx; -struct vring_used_elem ring[0 ]; +struct vring_used_elem ring[]; };/* For support of packed virtqueues in Virtio 1.1 the format of descriptors
drivers/net/virtio/virtio_user/vhost_kernel.c +1 -1
@@ -22,7 +22,7 @@ struct vhost_kernel_data {struct vhost_memory_kernel {uint32_t nregions;uint32_t padding; -struct vhost_memory_region regions[0 ]; +struct vhost_memory_region regions[]; };/* vhost kernel ioctls */
drivers/net/virtio/virtio_user/vhost_vdpa.c +1 -1
@@ -70,7 +70,7 @@ struct vhost_iotlb_msg {struct vhost_vdpa_config {uint32_t off;uint32_t len; -uint8_t buf[0 ]; +uint8_t buf[]; };struct vhost_msg {
drivers/net/virtio/virtqueue.h +1 -1
@@ -309,7 +309,7 @@ struct virtqueue {uint16_t *notify_addr;struct rte_mbuf **sw_ring;/**< RX software ring. */ -struct vq_desc_extra vq_descx[0 ]; +struct vq_desc_extra vq_descx[]; };/* If multiqueue is provided by host, then we support it. */
drivers/regex/mlx5/mlx5_rxp.h +2 -2
@@ -64,7 +64,7 @@ struct mlx5_rxp_match_tuple {struct mlx5_rxp_response {struct mlx5_rxp_response_desc header; -struct mlx5_rxp_match_tuple matches[0 ]; +struct mlx5_rxp_match_tuple matches[]; };#define MLX5_RXP_MAX_MATCHES 254
@@ -114,7 +114,7 @@ struct mlx5_rxp_rof {struct mlx5_rxp_ctl_rules_pgm {struct mlx5_rxp_ctl_hdr hdr;uint32_t count; -struct mlx5_rxp_rof_entry rules[0 ]; +struct mlx5_rxp_rof_entry rules[]; } __rte_packed;/* RXP programming mode setting. */
--
2.34.1
PATCH v3 3/4 lib: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_hash_key16.c | 4 ++-- lib/table/rte_table_hash_key32.c | 4 ++-- lib/table/rte_table_hash_key8.c | 4 ++-- lib/vhost/rte_vhost.h | 4 ++-- 12 files changed, 17 insertions(+), 17 deletions(-)
lib/cryptodev/cryptodev_pmd.h +1 -1
@@ -673,7 +673,7 @@ RTE_STD_C11 struct rte_cryptodev_asym_session {uint8_t padding[3 ];void *event_mdata;/**< Event metadata (aka *union rte_event_crypto_metadata*) */ -uint8_t sess_private_data[0 ]; +uint8_t sess_private_data[]; };#ifdef __cplusplus
lib/cryptodev/rte_cryptodev.h +1 -1
@@ -918,7 +918,7 @@ struct rte_cryptodev_sym_session { __extension__struct {void *data;uint16_t refcnt; - } sess_data[0 ]; + } sess_data[];/**< Driver specific session material, variable size */ };
lib/eventdev/rte_event_timer_adapter.h +1 -1
@@ -486,7 +486,7 @@ struct rte_event_timer {*/ enum rte_event_timer_state state;/**< State of the event timer. */ -uint8_t user_meta[0 ]; +uint8_t user_meta[];/**< Memory to store user specific metadata. * The event timer adapter implementation should not modify this area. */
lib/ip_frag/ip_reassembly.h +1 -1
@@ -83,7 +83,7 @@ struct rte_ip_frag_tbl {struct ip_frag_pkt *last;/* last used entry. */ struct ip_pkt_list lru;/* LRU list for table entries. */ struct ip_frag_tbl_stat stat;/* statistics counters. */ - __extension__ struct ip_frag_pkt pkt[0]; /* hash table. */ + __extension__ struct ip_frag_pkt pkt[]; /* hash table. */ };#endif /* _IP_REASSEMBLY_H_ */
lib/ipsec/sa.h +1 -1
@@ -59,7 +59,7 @@ union sym_op_data {struct replay_sqn {rte_rwlock_t rwl;uint64_t sqn; - __extension__uint64_t window[0 ]; + __extension__uint64_t window[]; };/*IPSEC SA supported algorithms */
lib/rib/rte_rib.c +1 -1
@@ -35,7 +35,7 @@ struct rte_rib_node {uint8_t depth;uint8_t flag;uint64_t nh; - __extension__uint64_t ext[0 ]; + __extension__uint64_t ext[]; };struct rte_rib {
lib/rib/rte_rib6.c +1 -1
@@ -34,7 +34,7 @@ struct rte_rib6_node {uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE ];uint8_t depth;uint8_t flag; - __extension__uint64_t ext[0 ]; + __extension__uint64_t ext[]; };struct rte_rib6 {
lib/table/rte_swx_table_learner.c +2 -2
@@ -252,7 +252,7 @@ struct table_bucket {uint32_t sig[TABLE_KEYS_PER_BUCKET ];uint8_t key_timeout_id[TABLE_KEYS_PER_BUCKET ];uint8_t pad[TABLE_BUCKET_PAD_SIZE ]; -uint8_t key[0 ]; +uint8_t key[]; };struct table_params {
@@ -317,7 +317,7 @@ struct table {uint8_t key_mask0[RTE_CACHE_LINE_SIZE ];/* Table buckets. */ -uint8_t buckets[0 ]; +uint8_t buckets[]; } __rte_cache_aligned;/* The timeout (in cycles) is stored in the table as a 32-bit value by truncating its least
lib/table/rte_table_hash_key16.c +2 -2
@@ -43,7 +43,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_16 {
@@ -58,7 +58,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/table/rte_table_hash_key32.c +2 -2
@@ -43,7 +43,7 @@ struct rte_bucket_4_32 {uint64_t key[4 ][4 ];/* Cache line 3 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_32 {
@@ -58,7 +58,7 @@ struct rte_bucket_4_32 {uint64_t key[4 ][4 ];/* Cache line 3 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/table/rte_table_hash_key8.c +2 -2
@@ -40,7 +40,7 @@ struct rte_bucket_4_8 {uint64_t key[4 ];/* Cache line 1 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_8 {
@@ -54,7 +54,7 @@ struct rte_bucket_4_8 {uint64_t key[4 ];/* Cache line 1 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/vhost/rte_vhost.h +2 -2
@@ -154,7 +154,7 @@ struct rte_vhost_inflight_info_split {uint16_t desc_num;uint16_t last_inflight_io;uint16_t used_idx; -struct rte_vhost_inflight_desc_split desc[0 ]; +struct rte_vhost_inflight_desc_split desc[]; };struct rte_vhost_inflight_desc_packed {
@@ -181,7 +181,7 @@ struct rte_vhost_inflight_info_packed {uint8_t used_wrap_counter;uint8_t old_used_wrap_counter;uint8_t padding[7 ]; -struct rte_vhost_inflight_desc_packed desc[0 ]; +struct rte_vhost_inflight_desc_packed desc[]; };struct rte_vhost_resubmit_desc {
Signature · 1 line
2.34.1
PATCH v3 4/4 app: examples: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- app/test/test_table_tables.c | 2 +- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
app/test/test_table_tables.c +1 -1
@@ -53,7 +53,7 @@ struct rte_bucket_4_8 {uint64_t next_valid;uint64_t key[4 ];/* Cache line 1 */ -uint8_t data[0 ]; +uint8_t data[]; };#if RTE_TABLE_HASH_LRU_STRATEGY ==3
examples/ip_reassembly/main.c +1 -1
@@ -126,7 +126,7 @@ struct mbuf_table {uint32_t len;uint32_t head;uint32_t tail; -struct rte_mbuf *m_table[0 ]; +struct rte_mbuf *m_table[]; };struct rx_queue {
examples/ptpclient/ptpclient.c +2 -2
@@ -90,7 +90,7 @@ struct sync_msg {struct follow_up_msg {struct ptp_header hdr;struct tstamp precise_origin_tstamp; -uint8_t suffix[0 ]; +uint8_t suffix[]; } __rte_packed;struct delay_req_msg {
@@ -102,7 +102,7 @@ struct delay_resp_msg {struct ptp_header hdr;struct tstamp rx_tstamp;struct port_id req_port_id; -uint8_t suffix[0 ]; +uint8_t suffix[]; } __rte_packed;struct ptp_message {
Signature · 1 line
2.34.1
Quoted 10 lines · Bruce Richardson
This patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
V3: Fixed issues in mlx5 drivers:
* fixed incorrect coccinelle replacement of 2-D zero-length arrays
* undid removal of "0" in tx elts[] which caused issues with Werror-pedanticV2: rebased to fix apply conflict
Still more build errors with these changes reported, V4 to follow...
v4 cover clean up zero-length arrays
In reply to Bruce RichardsonThis patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
V4: removed change from struct ipsec_encap_pdb in common/dpaax, which
caused build errors
V3: Fixed issues in mlx5 drivers:
* fixed incorrect coccinelle replacement of 2-D zero-length arrays
* undid removal of "0" in tx elts[] which caused issues with Werror-pedantic
V2: rebased to fix apply conflict
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned ones
app/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 ++-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 ++++----- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 ++-- drivers/crypto/virtio/virtio_ring.h | 4 ++-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 ++-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 ++-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_hash_key16.c | 4 ++-- lib/table/rte_table_hash_key32.c | 4 ++-- lib/table/rte_table_hash_key8.c | 4 ++-- lib/vhost/rte_vhost.h | 4 ++-- 37 files changed, 73 insertions(+), 52 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci
--
2.34.1
PATCH v4 1/4 cocci: add script for zero-length arrays in structs
Add script to replace [0] with [] when used at the end of a struct. The script also includes an additional struct member to match against so as to avoid issues with arrays with only a single zero-length element.
--- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 devtools/cocci/zero_length_array.cocci
devtools/cocci/zero_length_array.cocci new file +21 -0
@@ -0,0 +1,21 @@ +// Replace zero-length array members with [] +@@ +identifier st, member, arr; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +}; +@@ +identifier st, member, arr, id; +type T1, T2; +@@ +struct st { + ... + T1 member; +- T2 arr[0]; ++ T2 arr[]; +} id;
Signature · 1 line
2.34.1
PATCH v4 2/4 drivers: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- drivers/bus/dpaa/include/netcfg.h | 4 ++-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 +++++----- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 ++-- drivers/crypto/virtio/virtio_ring.h | 4 ++-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 ++-- 21 files changed, 31 insertions(+), 31 deletions(-)
drivers/bus/dpaa/include/netcfg.h +2 -2
@@ -23,7 +23,7 @@ struct fm_eth_port_cfg {struct netcfg_info {uint8_t num_ethports;/**< Number of ports */ -struct fm_eth_port_cfg port_cfg[0 ]; +struct fm_eth_port_cfg port_cfg[];/**< Variable structure array of size num_ethports */ };
@@ -38,7 +38,7 @@ struct interface_info {struct netcfg_interface {uint8_t numof_netcfg_interface;uint8_t numof_fman_enabled_macless; -struct interface_info interface_info[0 ]; +struct interface_info interface_info[]; };/* pcd_file: FMC netpcd XML ("policy") file, that contains PCD information.
drivers/bus/vmbus/rte_vmbus_reg.h +2 -2
@@ -107,7 +107,7 @@ struct vmbus_bufring {* Ring data starts here + RingDataStartOffset * !!! DO NOT place any fields below this !!! */ -uint8_t data[0 ]; +uint8_t data[]; } __rte_packed;/*
@@ -140,7 +140,7 @@ vmbus_chanpkt_getlen(uint16_t pktlen)struct vmbus_gpa_range {uint32_t len;uint32_t ofs; -uint64_t page[0 ]; +uint64_t page[]; } __rte_packed;/* This is actually vmbus_gpa_range.gpa_page[1] */
drivers/common/cnxk/roc_se.h +1 -1
@@ -246,7 +246,7 @@ struct roc_se_buf_ptr {/* IOV Pointer */ struct roc_se_iov_ptr {int buf_cnt; -struct roc_se_buf_ptr bufs[0 ]; +struct roc_se_buf_ptr bufs[]; };struct roc_se_fc_params {
drivers/common/dpaax/dpaax_iova_table.h +1 -1
@@ -32,7 +32,7 @@ struct dpaax_iovat_element {struct dpaax_iova_table {unsigned int count;/**< No. of blocks of contiguous physical pages */ -struct dpaax_iovat_element entries[0 ]; +struct dpaax_iovat_element entries[]; };/* Pointer to the table, which is common for DPAA/DPAA2 and only a single
drivers/common/mlx5/mlx5_prm.h +5 -5
@@ -560,7 +560,7 @@ struct mlx5_umr_wqe {struct mlx5_rdma_write_wqe {struct mlx5_wqe_cseg ctr;struct mlx5_wqe_rseg rseg; -struct mlx5_wqe_dseg dseg[0 ]; +struct mlx5_wqe_dseg dseg[]; } __rte_packed;#ifdef PEDANTIC
@@ -3479,7 +3479,7 @@ struct mlx5_ifc_qpc_pas_list_bits {#endif struct mlx5_ifc_qpc_extension_and_pas_list_bits {struct mlx5_ifc_qpc_extension_bits qpc_data_extension; -u8 pas[0 ][0x40 ]; +u8 pas[][0x40 ]; };
@@ -3703,7 +3703,7 @@ struct mlx5_ifc_query_qp_out_bits {u8 reserved_at_a0[0x20 ];struct mlx5_ifc_qpc_bits qpc;u8 reserved_at_800[0x80 ]; -u8 pas[0 ][0x40 ]; +u8 pas[][0x40 ]; };#ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic"
@@ -3743,7 +3743,7 @@ struct mlx5_ifc_access_register_out_bits {u8 reserved_at_8[0x18 ];u8 syndrome[0x20 ];u8 reserved_at_40[0x40 ]; -u8 register_data[0 ][0x20 ]; +u8 register_data[][0x20 ]; };struct mlx5_ifc_access_register_in_bits {
@@ -3754,7 +3754,7 @@ struct mlx5_ifc_access_register_in_bits {u8 reserved_at_40[0x10 ];u8 register_id[0x10 ];u8 argument[0x20 ]; -u8 register_data[0 ][0x20 ]; +u8 register_data[][0x20 ]; };#ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic"
drivers/crypto/ipsec_mb/ipsec_mb_private.h +2 -2
@@ -120,7 +120,7 @@ struct ipsec_mb_dev_private {/**< PMD type */ uint32_t max_nb_queue_pairs;/**< Max number of queue pairs supported by device */ - __extension__uint8_t priv[0 ]; + __extension__uint8_t priv[]; };/** IPSEC Multi buffer queue pair common queue pair data for all PMDs */
@@ -147,7 +147,7 @@ struct ipsec_mb_qp {/* Multi buffer manager */ const struct rte_memzone *mb_mgr_mz;/* Shared memzone for storing mb_mgr */ - __extension__uint8_t additional_data[0 ]; + __extension__uint8_t additional_data[];/**< Storing PMD specific additional data */ };
drivers/crypto/virtio/virtio_ring.h +2 -2
@@ -40,7 +40,7 @@ struct vring_desc {struct vring_avail {uint16_t flags;uint16_t idx; -uint16_t ring[0 ]; +uint16_t ring[]; };/* id is a 16bit index. uint32_t is used here for ids for padding reasons. */
@@ -54,7 +54,7 @@ struct vring_used_elem {struct vring_used {uint16_t flags;volatile uint16_t idx; -struct vring_used_elem ring[0 ]; +struct vring_used_elem ring[]; };struct vring {
drivers/crypto/virtio/virtqueue.h +1 -1
@@ -88,7 +88,7 @@ struct virtqueue {uint16_t *notify_addr; -struct vq_desc_extra vq_descx[0 ]; +struct vq_desc_extra vq_descx[]; };/**
drivers/net/atlantic/hw_atl/hw_atl_utils.h +1 -1
@@ -334,7 +334,7 @@ struct offload_info {struct offload_port_info ports;struct offload_ka_info kas;struct offload_rr_info rrs; -u8 buf[0 ]; +u8 buf[]; } __rte_packed;struct smbus_request {
drivers/net/cxgbe/clip_tbl.h +1 -1
@@ -20,7 +20,7 @@ struct clip_tbl {unsigned int clipt_start;/* start index of CLIP table */ unsigned int clipt_size;/* size of CLIP table */ rte_rwlock_t lock;/* table rw lock */ -struct clip_entry cl_list[0 ];/* MUST BE LAST */ +struct clip_entry cl_list[];/* MUST BE LAST */ }; struct clip_tbl *t4_init_clip_tbl(unsigned int clipt_start,
drivers/net/cxgbe/l2t.h +1 -1
@@ -37,7 +37,7 @@ struct l2t_data {unsigned int l2t_start;/* start index of our piece of the L2T */ unsigned int l2t_size;/* number of entries in l2tab */ rte_rwlock_t lock;/* table rw lock */ -struct l2t_entry l2tab[0 ];/* MUST BE LAST */ +struct l2t_entry l2tab[];/* MUST BE LAST */ };#define L2T_LPBK true
drivers/net/cxgbe/mps_tcam.h +1 -1
@@ -41,7 +41,7 @@ struct mpstcam_table {* free_idx cannot alone determine * if the table is full */ -struct mps_tcam_entry entry[0 ]; +struct mps_tcam_entry entry[]; };struct mpstcam_table *t4_init_mpstcam (struct adapter *adap);
drivers/net/cxgbe/smt.h +1 -1
@@ -31,7 +31,7 @@ struct smt_data {unsigned int smt_size;unsigned int smt_start;rte_rwlock_t lock; -struct smt_entry smtab[0 ]; +struct smt_entry smtab[]; };struct smt_data *t4_init_smt (u32 smt_start_idx,u32 smt_size);
drivers/net/enic/base/vnic_devcmd.h +1 -1
@@ -997,7 +997,7 @@ enum {struct filter_tlv {uint32_t type;uint32_t length; -uint32_t val[0 ]; +uint32_t val[]; };/* Data for CMD_ADD_FILTER is 2 TLV and filter + action structs */
drivers/net/hinic/hinic_pmd_tx.h +1 -1
@@ -81,7 +81,7 @@ struct hinic_sq_wqe {struct hinic_sq_task task;/* sq sge section start address, 1~127 sges */ -struct hinic_sq_bufdesc buf_descs[0 ]; +struct hinic_sq_bufdesc buf_descs[]; };struct hinic_txq_stats {
drivers/net/nfp/nfpcore/nfp_nsp.h +1 -1
@@ -224,7 +224,7 @@ struct nfp_eth_table {int is_split;unsigned int fec_modes_supported; - } ports[0 ]; + } ports[]; };struct nfp_eth_table *nfp_eth_read_ports (struct nfp_cpp *cpp);
drivers/net/virtio/virtio_ring.h +2 -2
@@ -46,7 +46,7 @@ struct vring_desc {struct vring_avail {uint16_t flags;uint16_t idx; -uint16_t ring[0 ]; +uint16_t ring[]; };/* id is a 16bit index. uint32_t is used here for ids for padding reasons. */
@@ -60,7 +60,7 @@ struct vring_used_elem {struct vring_used {uint16_t flags;uint16_t idx; -struct vring_used_elem ring[0 ]; +struct vring_used_elem ring[]; };/* For support of packed virtqueues in Virtio 1.1 the format of descriptors
drivers/net/virtio/virtio_user/vhost_kernel.c +1 -1
@@ -22,7 +22,7 @@ struct vhost_kernel_data {struct vhost_memory_kernel {uint32_t nregions;uint32_t padding; -struct vhost_memory_region regions[0 ]; +struct vhost_memory_region regions[]; };/* vhost kernel ioctls */
drivers/net/virtio/virtio_user/vhost_vdpa.c +1 -1
@@ -70,7 +70,7 @@ struct vhost_iotlb_msg {struct vhost_vdpa_config {uint32_t off;uint32_t len; -uint8_t buf[0 ]; +uint8_t buf[]; };struct vhost_msg {
drivers/net/virtio/virtqueue.h +1 -1
@@ -309,7 +309,7 @@ struct virtqueue {uint16_t *notify_addr;struct rte_mbuf **sw_ring;/**< RX software ring. */ -struct vq_desc_extra vq_descx[0 ]; +struct vq_desc_extra vq_descx[]; };/* If multiqueue is provided by host, then we support it. */
drivers/regex/mlx5/mlx5_rxp.h +2 -2
@@ -64,7 +64,7 @@ struct mlx5_rxp_match_tuple {struct mlx5_rxp_response {struct mlx5_rxp_response_desc header; -struct mlx5_rxp_match_tuple matches[0 ]; +struct mlx5_rxp_match_tuple matches[]; };#define MLX5_RXP_MAX_MATCHES 254
@@ -114,7 +114,7 @@ struct mlx5_rxp_rof {struct mlx5_rxp_ctl_rules_pgm {struct mlx5_rxp_ctl_hdr hdr;uint32_t count; -struct mlx5_rxp_rof_entry rules[0 ]; +struct mlx5_rxp_rof_entry rules[]; } __rte_packed;/* RXP programming mode setting. */
Signature · 1 line
2.34.1
PATCH v4 3/4 lib: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_hash_key16.c | 4 ++-- lib/table/rte_table_hash_key32.c | 4 ++-- lib/table/rte_table_hash_key8.c | 4 ++-- lib/vhost/rte_vhost.h | 4 ++-- 12 files changed, 17 insertions(+), 17 deletions(-)
lib/cryptodev/cryptodev_pmd.h +1 -1
@@ -673,7 +673,7 @@ RTE_STD_C11 struct rte_cryptodev_asym_session {uint8_t padding[3 ];void *event_mdata;/**< Event metadata (aka *union rte_event_crypto_metadata*) */ -uint8_t sess_private_data[0 ]; +uint8_t sess_private_data[]; };#ifdef __cplusplus
lib/cryptodev/rte_cryptodev.h +1 -1
@@ -918,7 +918,7 @@ struct rte_cryptodev_sym_session { __extension__struct {void *data;uint16_t refcnt; - } sess_data[0 ]; + } sess_data[];/**< Driver specific session material, variable size */ };
lib/eventdev/rte_event_timer_adapter.h +1 -1
@@ -486,7 +486,7 @@ struct rte_event_timer {*/ enum rte_event_timer_state state;/**< State of the event timer. */ -uint8_t user_meta[0 ]; +uint8_t user_meta[];/**< Memory to store user specific metadata. * The event timer adapter implementation should not modify this area. */
lib/ip_frag/ip_reassembly.h +1 -1
@@ -83,7 +83,7 @@ struct rte_ip_frag_tbl {struct ip_frag_pkt *last;/* last used entry. */ struct ip_pkt_list lru;/* LRU list for table entries. */ struct ip_frag_tbl_stat stat;/* statistics counters. */ - __extension__ struct ip_frag_pkt pkt[0]; /* hash table. */ + __extension__ struct ip_frag_pkt pkt[]; /* hash table. */ };#endif /* _IP_REASSEMBLY_H_ */
lib/ipsec/sa.h +1 -1
@@ -59,7 +59,7 @@ union sym_op_data {struct replay_sqn {rte_rwlock_t rwl;uint64_t sqn; - __extension__uint64_t window[0 ]; + __extension__uint64_t window[]; };/*IPSEC SA supported algorithms */
lib/rib/rte_rib.c +1 -1
@@ -35,7 +35,7 @@ struct rte_rib_node {uint8_t depth;uint8_t flag;uint64_t nh; - __extension__uint64_t ext[0 ]; + __extension__uint64_t ext[]; };struct rte_rib {
lib/rib/rte_rib6.c +1 -1
@@ -34,7 +34,7 @@ struct rte_rib6_node {uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE ];uint8_t depth;uint8_t flag; - __extension__uint64_t ext[0 ]; + __extension__uint64_t ext[]; };struct rte_rib6 {
lib/table/rte_swx_table_learner.c +2 -2
@@ -252,7 +252,7 @@ struct table_bucket {uint32_t sig[TABLE_KEYS_PER_BUCKET ];uint8_t key_timeout_id[TABLE_KEYS_PER_BUCKET ];uint8_t pad[TABLE_BUCKET_PAD_SIZE ]; -uint8_t key[0 ]; +uint8_t key[]; };struct table_params {
@@ -317,7 +317,7 @@ struct table {uint8_t key_mask0[RTE_CACHE_LINE_SIZE ];/* Table buckets. */ -uint8_t buckets[0 ]; +uint8_t buckets[]; } __rte_cache_aligned;/* The timeout (in cycles) is stored in the table as a 32-bit value by truncating its least
lib/table/rte_table_hash_key16.c +2 -2
@@ -43,7 +43,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_16 {
@@ -58,7 +58,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/table/rte_table_hash_key32.c +2 -2
@@ -43,7 +43,7 @@ struct rte_bucket_4_32 {uint64_t key[4 ][4 ];/* Cache line 3 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_32 {
@@ -58,7 +58,7 @@ struct rte_bucket_4_32 {uint64_t key[4 ][4 ];/* Cache line 3 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/table/rte_table_hash_key8.c +2 -2
@@ -40,7 +40,7 @@ struct rte_bucket_4_8 {uint64_t key[4 ];/* Cache line 1 */ -uint8_t data[0 ]; +uint8_t data[]; };#else struct rte_bucket_4_8 {
@@ -54,7 +54,7 @@ struct rte_bucket_4_8 {uint64_t key[4 ];/* Cache line 1 */ - uint8_t data[0]; + uint8_t data[]; };#endif
lib/vhost/rte_vhost.h +2 -2
@@ -154,7 +154,7 @@ struct rte_vhost_inflight_info_split {uint16_t desc_num;uint16_t last_inflight_io;uint16_t used_idx; -struct rte_vhost_inflight_desc_split desc[0 ]; +struct rte_vhost_inflight_desc_split desc[]; };struct rte_vhost_inflight_desc_packed {
@@ -181,7 +181,7 @@ struct rte_vhost_inflight_info_packed {uint8_t used_wrap_counter;uint8_t old_used_wrap_counter;uint8_t padding[7 ]; -struct rte_vhost_inflight_desc_packed desc[0 ]; +struct rte_vhost_inflight_desc_packed desc[]; };struct rte_vhost_resubmit_desc {
Signature · 1 line
2.34.1
PATCH v4 4/4 app: examples: replace zero-length arrays with undimensioned ones
In reply to Bruce RichardsonThis patch replaces instances of zero-sized arrays i.e. those at the end of structures with "[0]" with the more standard syntax of "[]". Replacement was done using coccinelle script, with some cleanup of whitespace afterwards.
--- app/test/test_table_tables.c | 2 +- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
app/test/test_table_tables.c +1 -1
@@ -53,7 +53,7 @@ struct rte_bucket_4_8 {uint64_t next_valid;uint64_t key[4 ];/* Cache line 1 */ -uint8_t data[0 ]; +uint8_t data[]; };#if RTE_TABLE_HASH_LRU_STRATEGY ==3
examples/ip_reassembly/main.c +1 -1
@@ -126,7 +126,7 @@ struct mbuf_table {uint32_t len;uint32_t head;uint32_t tail; -struct rte_mbuf *m_table[0 ]; +struct rte_mbuf *m_table[]; };struct rx_queue {
examples/ptpclient/ptpclient.c +2 -2
@@ -90,7 +90,7 @@ struct sync_msg {struct follow_up_msg {struct ptp_header hdr;struct tstamp precise_origin_tstamp; -uint8_t suffix[0 ]; +uint8_t suffix[]; } __rte_packed;struct delay_req_msg {
@@ -102,7 +102,7 @@ struct delay_resp_msg {struct ptp_header hdr;struct tstamp rx_tstamp;struct port_id req_port_id; -uint8_t suffix[0 ]; +uint8_t suffix[]; } __rte_packed;struct ptp_message {
Signature · 1 line
2.34.1
Quoted 43 lines · Bruce Richardson
This patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned onesapp/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 ++-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 ++++----- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 ++-- drivers/crypto/virtio/virtio_ring.h | 4 ++-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 ++-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 ++-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +-
Quoted 8 lines
lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_hash_key16.c | 4 ++-- lib/table/rte_table_hash_key32.c | 4 ++-- lib/table/rte_table_hash_key8.c | 4 ++-- lib/vhost/rte_vhost.h | 4 ++-- 37 files changed, 73 insertions(+), 52 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci
Series applied, thanks for the cleanup.
Signature · 1 line
David Marchand
does this mean we now *require* a C99 compiler?
(which i have no problem with)
Quoted 61 lines · Bruce Richardson
This patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
V4: removed change from struct
ipsec_encap_pdbin common/dpaax, which
caused build errorsV3: Fixed issues in mlx5 drivers:
* fixed incorrect coccinelle replacement of 2-D zero-length arrays
* undid removal of "0" in tx elts[] which caused issues with Werror-pedanticV2: rebased to fix apply conflict
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned onesapp/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 ++-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 ++-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 ++++----- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 ++-- drivers/crypto/virtio/virtio_ring.h | 4 ++-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 ++-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 ++-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_hash_key16.c | 4 ++-- lib/table/rte_table_hash_key32.c | 4 ++-- lib/table/rte_table_hash_key8.c | 4 ++-- lib/vhost/rte_vhost.h | 4 ++-- 37 files changed, 73 insertions(+), 52 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci--
2.34.1
Quoted 53 lines · On Thu, 2 Jun 2022 16:08:30 +0100 Bruce Richardson…
This patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned onesapp/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 +-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 +-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 +++---- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 +-- drivers/crypto/virtio/virtio_ring.h | 4 +-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/mlx5/mlx5_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 +-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 +-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 +-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 +-- lib/table/rte_table_hash_key16.c | 4 +-- lib/table/rte_table_hash_key32.c | 4 +-- lib/table/rte_table_hash_key8.c | 4 +-- lib/vhost/rte_vhost.h | 4 +-- 40 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci create mode 100644 lib/count_comments.py
Quoted 3 lines
--
2.34.1
Bruce, looking at this commit, it looks like the underlying cause of the problem with iavf was it is using array size of one when flex array should be used:
commit b5b3ea803e4741ad6a46a38d8227c78226d9054d
Author: Kevin Traynor <[email protected]> Date: Fri Apr 17 16:43:35 2020 +0100
eal/x86: ignore gcc 10 stringop-overflow warnings
stringop-overflow warns when it sees a possible overflow in a string operation.
In the rte_memcpy functions different branches are taken depending on the size. stringop-overflow is raised for the branches in the function where it sees the static size of the src could be overflowed.
However, in reality a correct size argument and in some cases dynamic allocation would ensure that this does not happen.
For example, in the case below for key, the correct path will be chosen in rte_memcpy_generic at runtime based on the size argument but as some paths in the function could lead to a cast to 32 bytes a warning is raised.
In function ‘_mm256_storeu_si256’,
inlined from ‘rte_memcpy_generic’
at ../lib/librte_eal/common/include/arch/x86/rte_memcpy.h:315:2, inlined from ‘iavf_configure_rss_key’
at ../lib/librte_eal/common/include/arch/x86/rte_memcpy.h:869:10:
/usr/lib/gcc/x86_64-redhat-linux/10/include/avxintrin.h:928:8:
warning: writing 32 bytes into a region of size 1 [-Wstringop-overflow=]
928 | *__P = __A;
| ~~~~~^~~~~
In file included
from ../drivers/net/iavf/../../common/iavf/iavf_prototype.h:10, from ../drivers/net/iavf/iavf.h:9,
from ../drivers/net/iavf/iavf_vchnl.c:22:
../drivers/net/iavf/iavf_vchnl.c:
In function ‘iavf_configure_rss_key’:
../drivers/net/iavf/../../common/iavf/virtchnl.h:508:5:
note: at offset 0 to object ‘key’ with size 1 declared here
508 | u8 key[1]; /* RSS hash key, packed bytes */
| ^~~
Ignore the stringop-overflow warnings for rte_memcpy.h functions.
Bugzilla ID: 394
Bugzilla ID: 421
Cc: [email protected]
Quoted 101 lines · Stephen Hemminger
Quoted 53 lines · On Thu, 2 Jun 2022 16:08:30 +0100 Bruce Richardson…
This patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned onesapp/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 +-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 +-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 +++---- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 +-- drivers/crypto/virtio/virtio_ring.h | 4 +-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/mlx5/mlx5_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 +-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 +-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 +-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 +-- lib/table/rte_table_hash_key16.c | 4 +-- lib/table/rte_table_hash_key32.c | 4 +-- lib/table/rte_table_hash_key8.c | 4 +-- lib/vhost/rte_vhost.h | 4 +-- 40 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci create mode 100644 lib/count_comments.pyQuoted 3 lines
--
2.34.1Bruce, looking at this commit, it looks like the underlying cause of the problem with iavf was it is using array size of one when flex array should be used:
commit
b5b3ea803e4741ad6a46a38d8227c78226d9054dAuthor: Kevin Traynor <[email protected]> Date: Fri Apr 17 16:43:35 2020 +0100eal/x86: ignore gcc 10 stringop-overflow warnings
stringop-overflow warns when it sees a possible overflow in a string operation.
In the
rte_memcpyfunctions different branches are taken depending on the size. stringop-overflow is raised for the branches in the function where it sees the static size of the src could be overflowed.However, in reality a correct size argument and in some cases dynamic allocation would ensure that this does not happen.
For example, in the case below for key, the correct path will be chosen in
rte_memcpy_genericat runtime based on the size argument but as some paths in the function could lead to a cast to 32 bytes a warning is raised.In function ‘_mm256_storeu_si256’,
inlined from ‘rte_memcpy_generic’
at../lib/librte_eal/common/include/arch/x86/rte_memcpy.h:315:2, inlined from ‘iavf_configure_rss_key’
at../lib/librte_eal/common/include/arch/x86/rte_memcpy.h:869:10:
/usr/lib/gcc/x86_64-redhat-linux/10/include/avxintrin.h:928:8:
warning: writing 32 bytes into a region of size 1 [-Wstringop-overflow=]
928 |*__P=__A;
| ~~~~~^~~~~
In file included
from../drivers/net/iavf/../../common/iavf/iavf_prototype.h:10, from../drivers/net/iavf/iavf.h:9,
from../drivers/net/iavf/iavf_vchnl.c:22:
Quoted 8 lines
../drivers/net/iavf/iavf_vchnl.c:
In function ‘iavf_configure_rss_key’:
../drivers/net/iavf/../../common/iavf/virtchnl.h:508:5:
note: at offset 0 to object ‘key’ with size 1 declared here
508 | u8 key[1]; /* RSS hash key, packed bytes */
| ^~~
I would tend to agree with your assessment. It looks like the "u8 key[1]" value should probably be "u8 key[]", and also in the following structure in the file, "u8 lut[1]" should probably be "u8 lut[]".
Adding maintainers for driver on CC
Beilei, Jingjing,
in "common/iavf/virtchnl.h", there are quite a number of values at the end of structs which are defined as arrays of size 1. We suspect that many of these are placeholder arrays which should be given as unsigned arrays. Is this assessment correct?
/Bruce
Quoted 115 lines · Bruce Richardson
Quoted 101 lines · Stephen Hemminger
Quoted 53 lines · On Thu, 2 Jun 2022 16:08:30 +0100 Bruce Richardson…
This patchset adds a coccinelle script to clean-up zero-length arrays in structures. The final patches are the result of running that script on the DPDK repository.
Bruce Richardson (4):
cocci: add script for zero-length arrays in structs
drivers: replace zero-length arrays with undimensioned ones
lib: replace zero-length arrays with undimensioned ones
app: examples: replace zero-length arrays with undimensioned onesapp/test/test_table_tables.c | 2 +- devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++ drivers/bus/dpaa/include/netcfg.h | 4 +-- drivers/bus/vmbus/rte_vmbus_reg.h | 4 +-- drivers/common/cnxk/roc_se.h | 2 +- drivers/common/dpaax/caamflib/desc/ipsec.h | 2 +- drivers/common/dpaax/dpaax_iova_table.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 10 +++---- drivers/crypto/ipsec_mb/ipsec_mb_private.h | 4 +-- drivers/crypto/virtio/virtio_ring.h | 4 +-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/atlantic/hw_atl/hw_atl_utils.h | 2 +- drivers/net/cxgbe/clip_tbl.h | 2 +- drivers/net/cxgbe/l2t.h | 2 +- drivers/net/cxgbe/mps_tcam.h | 2 +- drivers/net/cxgbe/smt.h | 2 +- drivers/net/enic/base/vnic_devcmd.h | 2 +- drivers/net/hinic/hinic_pmd_tx.h | 2 +- drivers/net/mlx5/mlx5_tx.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 2 +- drivers/net/virtio/virtio_ring.h | 4 +-- drivers/net/virtio/virtio_user/vhost_kernel.c | 2 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 2 +- drivers/net/virtio/virtqueue.h | 2 +- drivers/regex/mlx5/mlx5_rxp.h | 4 +-- examples/ip_reassembly/main.c | 2 +- examples/ptpclient/ptpclient.c | 4 +-- lib/cryptodev/cryptodev_pmd.h | 2 +- lib/cryptodev/rte_cryptodev.h | 2 +- lib/eventdev/rte_event_timer_adapter.h | 2 +- lib/ip_frag/ip_reassembly.h | 2 +- lib/ipsec/sa.h | 2 +- lib/rib/rte_rib.c | 2 +- lib/rib/rte_rib6.c | 2 +- lib/table/rte_swx_table_learner.c | 4 +-- lib/table/rte_table_hash_key16.c | 4 +-- lib/table/rte_table_hash_key32.c | 4 +-- lib/table/rte_table_hash_key8.c | 4 +-- lib/vhost/rte_vhost.h | 4 +-- 40 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 devtools/cocci/zero_length_array.cocci create mode 100644 lib/count_comments.pyQuoted 3 lines
--
2.34.1Bruce, looking at this commit, it looks like the underlying cause of the problem with iavf was it is using array size of one when flex array should be used:
commit
b5b3ea803e4741ad6a46a38d8227c78226d9054dAuthor: Kevin Traynor <[email protected]> Date: Fri Apr 17 16:43:35 2020 +0100eal/x86: ignore gcc 10 stringop-overflow warnings
stringop-overflow warns when it sees a possible overflow in a string operation.
In the
rte_memcpyfunctions different branches are taken depending on the size. stringop-overflow is raised for the branches in the function where it sees the static size of the src could be overflowed.However, in reality a correct size argument and in some cases dynamic allocation would ensure that this does not happen.
For example, in the case below for key, the correct path will be chosen in
rte_memcpy_genericat runtime based on the size argument but as some paths in the function could lead to a cast to 32 bytes a warning is raised.In function ‘_mm256_storeu_si256’,
inlined from ‘rte_memcpy_generic’
at../lib/librte_eal/common/include/arch/x86/rte_memcpy.h:315:2, inlined from ‘iavf_configure_rss_key’
at../lib/librte_eal/common/include/arch/x86/rte_memcpy.h:869:10:
/usr/lib/gcc/x86_64-redhat-linux/10/include/avxintrin.h:928:8:
warning: writing 32 bytes into a region of size 1 [-Wstringop-overflow=]
928 |*__P=__A;
| ~~~~~^~~~~
In file included
from../drivers/net/iavf/../../common/iavf/iavf_prototype.h:10, from../drivers/net/iavf/iavf.h:9,
from../drivers/net/iavf/iavf_vchnl.c:22:Quoted 8 lines
../drivers/net/iavf/iavf_vchnl.c:
In function ‘iavf_configure_rss_key’:
../drivers/net/iavf/../../common/iavf/virtchnl.h:508:5:
note: at offset 0 to object ‘key’ with size 1 declared here
508 | u8 key[1]; /* RSS hash key, packed bytes */
| ^~~I would tend to agree with your assessment. It looks like the "u8 key[1]" value should probably be "u8 key[]", and also in the following structure in the file, "u8 lut[1]" should probably be "u8 lut[]".
Quoted 9 lines
Adding maintainers for driver on CC
Beilei, Jingjing,
in "
common/iavf/virtchnl.h", there are quite a number of values at the end of structs which are defined as arrays of size 1. We suspect that many of these are placeholder arrays which should be given as unsigned arrays. Is this assessment correct?
s/unsigned arrays/flexible array members/
i.e. arrays without a given size "[]"