Skip to content

Commit

Permalink
treewide: Replace zero-length arrays with flexible-array members
Browse files Browse the repository at this point in the history
There is a regular need in the kernel to provide a way to declare
having a dynamically sized set of trailing elements in a structure.
Kernel code should always use “flexible array members”[1] for these
cases. The older style of one-element or zero-length arrays should
no longer be used[2].

This code was transformed with the help of Coccinelle:
(next-20220214$ spatch --jobs $(getconf _NPROCESSORS_ONLN) --sp-file script.cocci --include-headers --dir . > output.patch)

@@
identifier S, member, array;
type T1, T2;
@@

struct S {
  ...
  T1 member;
  T2 array[
- 0
  ];
};

UAPI and wireless changes were intentionally excluded from this patch
and will be sent out separately.

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays

Link: KSPP#78
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
  • Loading branch information
GustavoARSilva authored and intel-lab-lkp committed Feb 15, 2022
1 parent f413f68 commit 423897f
Show file tree
Hide file tree
Showing 69 changed files with 116 additions and 116 deletions.
2 changes: 1 addition & 1 deletion arch/alpha/include/asm/hwrpb.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct memdesc_struct {
unsigned long chksum;
unsigned long optional_pa;
unsigned long numclusters;
struct memclust_struct cluster[0];
struct memclust_struct cluster[];
};

struct dsr_struct {
Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/include/asm/sal.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ typedef struct sal_log_processor_info {
* The rest of this structure consists of variable-length arrays, which can't be
* expressed in C.
*/
sal_log_mod_error_info_t info[0];
sal_log_mod_error_info_t info[];
/*
* This is what the rest looked like if C supported variable-length arrays:
*
Expand Down
2 changes: 1 addition & 1 deletion arch/s390/include/asm/ccwgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct ccwgroup_device {
unsigned int count;
struct device dev;
struct work_struct ungroup_work;
struct ccw_device *cdev[0];
struct ccw_device *cdev[];
};

/**
Expand Down
2 changes: 1 addition & 1 deletion arch/s390/include/asm/chsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct chsc_pnso_area {
struct chsc_header response;
u32:32;
struct chsc_pnso_naihdr naihdr;
struct chsc_pnso_naid_l2 entries[0];
struct chsc_pnso_naid_l2 entries[];
} __packed __aligned(PAGE_SIZE);

#endif /* _ASM_S390_CHSC_H */
2 changes: 1 addition & 1 deletion arch/s390/include/asm/eadm.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct aob {

struct aob_rq_header {
struct scm_device *scmdev;
char data[0];
char data[];
};

struct scm_device {
Expand Down
4 changes: 2 additions & 2 deletions arch/s390/include/asm/fcx.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ struct dcw_intrg_data {
u32 :32;
u64 time;
u64 prog_id;
u8 prog_data[0];
u8 prog_data[];
} __attribute__ ((packed));

#define DCW_FLAGS_CC (1 << (7 - 1))
Expand All @@ -241,7 +241,7 @@ struct dcw {
u32 :8;
u32 cd_count:8;
u32 count;
u8 cd[0];
u8 cd[];
} __attribute__ ((packed));

#define TCCB_FORMAT_DEFAULT 0x7f
Expand Down
2 changes: 1 addition & 1 deletion arch/s390/include/asm/idals.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ clear_normalized_cda(struct ccw1 * ccw)
struct idal_buffer {
size_t size;
size_t page_order;
void *data[0];
void *data[];
};

/*
Expand Down
2 changes: 1 addition & 1 deletion arch/s390/include/asm/sclp.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct zpci_report_error_header {
* (OpenCrypto Successful Diagnostics Execution)
*/
u16 length; /* Length of Subsequent Data (up to 4K – SCLP header */
u8 data[0]; /* Subsequent Data passed verbatim to SCLP ET 24 */
u8 data[]; /* Subsequent Data passed verbatim to SCLP ET 24 */
} __packed;

extern char *sclp_early_sccb;
Expand Down
6 changes: 3 additions & 3 deletions arch/s390/include/asm/sysinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ struct sysinfo_1_2_2 {
unsigned short cpus_configured;
unsigned short cpus_standby;
unsigned short cpus_reserved;
unsigned short adjustment[0];
unsigned short adjustment[];
};

struct sysinfo_1_2_2_extension {
unsigned int alt_capability;
unsigned short alt_adjustment[0];
unsigned short alt_adjustment[];
};

struct sysinfo_2_2_1 {
Expand Down Expand Up @@ -181,7 +181,7 @@ struct sysinfo_15_1_x {
unsigned char reserved1;
unsigned char mnest;
unsigned char reserved2[4];
union topology_entry tle[0];
union topology_entry tle[];
};

int stsi(void *sysinfo, int fc, int sel1, int sel2);
Expand Down
2 changes: 1 addition & 1 deletion arch/sh/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct thread_info {
mm_segment_t addr_limit; /* thread address space */
unsigned long previous_sp; /* sp of previous stack in case
of nested IRQ stacks */
__u8 supervisor_stack[0];
__u8 supervisor_stack[];
};

#endif
Expand Down
10 changes: 5 additions & 5 deletions arch/sparc/include/asm/vio.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct vio_dring_register {
#define VIO_RX_DRING_DATA 0x0004
u16 resv;
u32 num_cookies;
struct ldc_trans_cookie cookies[0];
struct ldc_trans_cookie cookies[];
};

struct vio_dring_unregister {
Expand Down Expand Up @@ -161,7 +161,7 @@ struct vio_disk_desc {
u64 size;
u32 ncookies;
u32 resv2;
struct ldc_trans_cookie cookies[0];
struct ldc_trans_cookie cookies[];
};

#define VIO_DISK_VNAME_LEN 8
Expand Down Expand Up @@ -200,13 +200,13 @@ struct vio_disk_devid {
u16 resv;
u16 type;
u32 len;
char id[0];
char id[];
};

struct vio_disk_efi {
u64 lba;
u64 len;
char data[0];
char data[];
};

/* VIO net specific structures and defines */
Expand Down Expand Up @@ -246,7 +246,7 @@ struct vio_net_desc {
struct vio_dring_hdr hdr;
u32 size;
u32 ncookies;
struct ldc_trans_cookie cookies[0];
struct ldc_trans_cookie cookies[];
};

struct vio_net_dext {
Expand Down
2 changes: 1 addition & 1 deletion arch/um/include/shared/net_kern.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct uml_net_private {

void (*add_address)(unsigned char *, unsigned char *, void *);
void (*delete_address)(unsigned char *, unsigned char *, void *);
char user[0];
char user[];
};

struct net_kern_info {
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/microcode_amd.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct microcode_header_amd {

struct microcode_amd {
struct microcode_header_amd hdr;
unsigned int mpb[0];
unsigned int mpb[];
};

#define PATCH_MAX_SIZE (3 * PAGE_SIZE)
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/include/asm/microcode_intel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct microcode_header_intel {

struct microcode_intel {
struct microcode_header_intel hdr;
unsigned int bits[0];
unsigned int bits[];
};

/* microcode format is extended from prescott processors */
Expand All @@ -33,7 +33,7 @@ struct extended_sigtable {
unsigned int count;
unsigned int cksum;
unsigned int reserved[3];
struct extended_signature sigs[0];
struct extended_signature sigs[];
};

#define DEFAULT_UCODE_DATASIZE (2000)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct pci_setup_rom {
unsigned long bus;
unsigned long device;
unsigned long function;
uint8_t romdata[0];
uint8_t romdata[];
};

#endif /* _ASM_X86_PCI_H */
2 changes: 1 addition & 1 deletion arch/x86/include/asm/pci_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct irq_routing_table {
u32 miniport_data; /* Crap */
u8 rfu[11];
u8 checksum; /* Modulo 256 checksum must give 0 */
struct irq_info slots[0];
struct irq_info slots[];
} __attribute__((packed));

extern unsigned int pcibios_irq_mask;
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/include/asm/bootparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
typedef struct bp_tag {
unsigned short id; /* tag id */
unsigned short size; /* size of this record excluding the structure*/
unsigned long data[0]; /* data */
unsigned long data[]; /* data */
} bp_tag_t;

struct bp_meminfo {
Expand Down
2 changes: 1 addition & 1 deletion drivers/crypto/caam/pdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct ipsec_encap_pdb {
};
u32 spi;
u32 ip_hdr_len;
u32 ip_hdr[0];
u32 ip_hdr[];
};

/**
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct __guc_ads_blob {
struct guc_gt_system_info system_info;
struct guc_engine_usage engine_usage;
/* From here on, location is dynamic! Refer to above diagram. */
struct guc_mmio_reg regset[0];
struct guc_mmio_reg regset[];
} __packed;

static u32 guc_ads_regset_size(struct intel_guc *guc)
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/nouveau/include/nvfw/hs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct nvfw_hs_load_header {
u32 data_dma_base;
u32 data_size;
u32 num_apps;
u32 apps[0];
u32 apps[];
};

const struct nvfw_hs_load_header *
Expand Down
2 changes: 1 addition & 1 deletion drivers/hwtracing/coresight/coresight-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ struct cscfg_config_csdev {
bool enabled;
struct list_head node;
int nr_feat;
struct cscfg_feature_csdev *feats_csdev[0];
struct cscfg_feature_csdev *feats_csdev[];
};

/**
Expand Down
2 changes: 1 addition & 1 deletion drivers/misc/bcm-vk/bcm_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ struct bcm_vk_peer_log {
u32 wr_idx;
u32 buf_size;
u32 mask;
char data[0];
char data[];
};

/* max buf size allowed */
Expand Down
6 changes: 3 additions & 3 deletions drivers/misc/habanalabs/include/common/cpucp_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,19 +540,19 @@ struct cpucp_packet {
struct cpucp_unmask_irq_arr_packet {
struct cpucp_packet cpucp_pkt;
__le32 length;
__le32 irqs[0];
__le32 irqs[];
};

struct cpucp_nic_status_packet {
struct cpucp_packet cpucp_pkt;
__le32 length;
__le32 data[0];
__le32 data[];
};

struct cpucp_array_data_packet {
struct cpucp_packet cpucp_pkt;
__le32 length;
__le32 data[0];
__le32 data[];
};

enum cpucp_packet_rc {
Expand Down
4 changes: 2 additions & 2 deletions drivers/misc/habanalabs/include/gaudi/gaudi_packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct gaudi_packet {
/* The rest of the packet data follows. Use the corresponding
* packet_XXX struct to deference the data, based on packet type
*/
u8 contents[0];
u8 contents[];
};

struct packet_nop {
Expand All @@ -75,7 +75,7 @@ struct packet_wreg32 {
struct packet_wreg_bulk {
__le32 size64;
__le32 ctl;
__le64 values[0]; /* data starts here */
__le64 values[]; /* data starts here */
};

#define GAUDI_PKT_LONG_CTL_OP_SHIFT 20
Expand Down
4 changes: 2 additions & 2 deletions drivers/misc/habanalabs/include/goya/goya_packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct goya_packet {
/* The rest of the packet data follows. Use the corresponding
* packet_XXX struct to deference the data, based on packet type
*/
u8 contents[0];
u8 contents[];
};

struct packet_nop {
Expand All @@ -86,7 +86,7 @@ struct packet_wreg32 {
struct packet_wreg_bulk {
__le32 size64;
__le32 ctl;
__le64 values[0]; /* data starts here */
__le64 values[]; /* data starts here */
};

struct packet_msg_long {
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/freescale/enetc/enetc_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ struct sgcl_data {
u32 bth;
u32 ct;
u32 cte;
struct sgce sgcl[0];
struct sgce sgcl[];
};

#define ENETC_CBDR_FMI_MR BIT(0)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/i825xx/sun3_82586.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ struct mcsetup_cmd_struct
unsigned short cmd_cmd;
unsigned short cmd_link;
unsigned short mc_cnt; /* number of bytes in the MC-List */
unsigned char mc_list[0][6]; /* pointer to 6 bytes entries */
unsigned char mc_list[][6]; /* pointer to 6 bytes entries */
};

/*
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/ethernet/marvell/octeontx2/af/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ struct npc_coalesced_kpu_prfl {
u8 name[NPC_NAME_LEN]; /* KPU Profile name */
u64 version; /* KPU firmware/profile version */
u8 num_prfl; /* No of NPC profiles. */
u16 prfl_sz[0];
u16 prfl_sz[];
};

struct npc_mcam_kex {
Expand All @@ -482,7 +482,7 @@ struct npc_kpu_fwdata {
* struct npc_kpu_profile_cam[entries];
* struct npc_kpu_profile_action[entries];
*/
u8 data[0];
u8 data[];
} __packed;

struct npc_lt_def {
Expand Down Expand Up @@ -572,7 +572,7 @@ struct npc_kpu_profile_fwdata {
* Custom KPU CAM and ACTION configuration entries.
* struct npc_kpu_fwdata kpu[kpus];
*/
u8 data[0];
u8 data[];
} __packed;

struct rvu_npc_mcam_rule {
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/qlogic/qed/qed_mfw_hsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,6 @@ struct nvm_meta_bin_t {
u32 version;
#define NVM_META_BIN_VERSION 1
u32 num_options;
u32 options[0];
u32 options[];
};
#endif
2 changes: 1 addition & 1 deletion drivers/net/ethernet/ti/davinci_mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct davinci_mdio_regs {
#define USERACCESS_DATA (0xffff)

u32 physel;
} user[0];
} user[];
};

static const struct mdio_platform_data default_pdata = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/dpt/dpti_i2o.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct i2o_sys_tbl
u32 change_ind;
u32 reserved2;
u32 reserved3;
struct i2o_sys_tbl_entry iops[0];
struct i2o_sys_tbl_entry iops[];
};

/*
Expand Down
Loading

0 comments on commit 423897f

Please sign in to comment.