Skip to content

Commit

Permalink
compile: use flexible arrays to use compiler checks
Browse files Browse the repository at this point in the history
We use zero-size arrays throughout the code in place of flexible
arrays. There are only two cases where flexible arrays cannot be
used: inside unions and where such an array is the only member of the
structure. In all other cases we can switch to flexible arrays to let
the compiler warn us of any improper use.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
  • Loading branch information
lyakh authored and lgirdwood committed Mar 13, 2023
1 parent b541e41 commit afb1a0d
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/include/ipc/channel_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct sof_ipc_channel_map {
uint32_t ext_id;
uint32_t ch_mask;
uint32_t reserved;
int32_t ch_coeffs[0];
int32_t ch_coeffs[];
} __attribute__((packed, aligned(4)));

/**
Expand All @@ -56,7 +56,7 @@ struct sof_ipc_stream_map {
struct sof_ipc_cmd_hdr hdr;
uint32_t num_ch_map;
uint32_t reserved[3];
struct sof_ipc_channel_map ch_map[0];
struct sof_ipc_channel_map ch_map[];
} __attribute__((packed, aligned(4)));

#endif /* __IPC_CHANNEL_MAP_H__ */
2 changes: 1 addition & 1 deletion src/include/ipc/topology.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ struct sof_ipc_comp_process {
/* reserved for future use */
uint32_t reserved[7];

unsigned char data[0];
unsigned char data[];
} __attribute__((packed, aligned(4)));

/* IPC file component used by testbench only */
Expand Down
2 changes: 1 addition & 1 deletion src/include/ipc4/base_fw.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ enum ipc4_hw_config_params {
struct ipc4_tuple {
uint32_t type;
uint32_t length;
char data[0];
char data[];
} __attribute__((packed, aligned(4)));

enum ipc4_memory_type {
Expand Down
2 changes: 1 addition & 1 deletion src/include/ipc4/gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct ipc4_gateway_config_data {
union ipc4_gateway_attributes gtw_attributes;

/**< Configuration BLOB */
uint32_t config_blob[0];
uint32_t config_blob[];
} __attribute__((packed, aligned(4)));

/**< Configuration for the IPC Gateway */
Expand Down
4 changes: 2 additions & 2 deletions src/include/ipc4/ipcgtw.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct ipc4_ipc_gateway_cmd_data {
/* node_id of the target gateway */
union ipc4_connector_node_id node_id;
/* Payload (actual size is in the header extension.r.data_size) */
uint8_t payload[0];
uint8_t payload[];
};

/* Reply to IPC gateway message */
Expand All @@ -60,7 +60,7 @@ struct ipc4_ipc_gateway_cmd_data_reply {
/* Total reply size is returned in reply header extension.r.data_size.
* This payload size if 4 bytes smaller (size of the union above).
*/
uint8_t payload[0];
uint8_t payload[];
};

int ipcgtw_process_cmd(const struct ipc4_ipcgtw_cmd *cmd,
Expand Down
2 changes: 1 addition & 1 deletion src/include/ipc4/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct ipc4_module_init_ext_data {
struct ipc4_module_init_ext_init extended_init;

/**< Data (actual size set to param_block_size) */
uint32_t param_data[0];
uint32_t param_data[];
} __attribute__((packed, aligned(4)));

struct ipc4_module_init_gna_config {
Expand Down
2 changes: 1 addition & 1 deletion src/include/ipc4/peak_volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ struct ipc4_peak_volume_config {

struct ipc4_peak_volume_module_cfg {
struct ipc4_base_module_cfg base_cfg;
struct ipc4_peak_volume_config config[0];
struct ipc4_peak_volume_config config[];
} __packed __aligned(8);
#endif
2 changes: 1 addition & 1 deletion src/include/ipc4/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ struct ipc4_pipeline_set_state_data {
/**< Number of items in ppl_id[] */
uint32_t pipelines_count;
/**< Pipeline ids */
uint32_t ppl_id[0];
uint32_t ppl_id[];
} __attribute__((packed, aligned(4)));

struct ipc4_pipeline_set_state {
Expand Down
2 changes: 1 addition & 1 deletion src/include/ipc4/ssp.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct ipc4_ssp_configuration_blob {
struct ipc4_ssp_driver_config i2s_driver_config;

/* optional configuration parameters */
union ipc4_ssp_dma_control i2s_dma_control[0];
union ipc4_ssp_dma_control i2s_dma_control[];
} __attribute__((packed, aligned(4)));

#endif
2 changes: 1 addition & 1 deletion src/include/kernel/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct sof_abi_hdr {
/**< The version is valid in scope of the 'magic', */
/**< IPC3 and IPC4 ABI version numbers have no relationship. */
uint32_t reserved[4]; /**< reserved for future use */
uint32_t data[0]; /**< Component data - opaque to core */
uint32_t data[]; /**< Component data - opaque to core */
} __attribute__((packed));

#endif /* __KERNEL_HEADER_H__ */
2 changes: 1 addition & 1 deletion src/include/sof/audio/module_adapter/iadk/system_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef struct _ModuleEventNotification {
uint32_t event_data_size; /*!< Size of event_data array in bytes. May be set to 0
* in case there is no data.
*/
uint32_t event_data[0]; /*< Optional event data (size set to 0 as it is optional
uint32_t event_data[]; /*!< Optional event data (size set to 0 as it is optional
* data)
*/
} ModuleEventNotification;
Expand Down

0 comments on commit afb1a0d

Please sign in to comment.