Do not pass array arguments to the ASSUME_ALIGNED() macro

Do not pass array arguments to ASSUME_ALIGNED() macro, pass a pointer
instead.

Then it is possible to make ASSUME_ALIGNED type safe.

When using -g0, gcc outputs are exactly the same before vs after this
commit.

Note it is still not possible to make the `cdata->data->data`
abomination type-safe because it is nesting non-standard zero-length
members. However that is a different issue; not ASSUME_ALIGNED's
problem. ASSUME_ALIGNED is apparently needed for some "normal" C code
too.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
Marc Herbert 2022-01-28 18:30:13 +00:00 committed by Liam Girdwood
parent f30892d966
commit bd54434a2f
9 changed files with 15 additions and 8 deletions

View File

@ -491,7 +491,7 @@ static int crossover_cmd_set_data(struct comp_dev *dev,
comp_info(dev, "crossover_cmd_set_data(), SOF_CTRL_CMD_BINARY");
/* Find size from header */
request = (struct sof_crossover_config *)ASSUME_ALIGNED(cdata->data->data, 4);
request = (struct sof_crossover_config *)ASSUME_ALIGNED(&cdata->data->data, 4);
bs = request->size;
/* Check that there is no work-in-progress previous request */

View File

@ -29,7 +29,7 @@ int iir_init_coef_df2t(struct iir_state_df2t *iir,
{
iir->biquads = config->num_sections;
iir->biquads_in_series = config->num_sections_in_series;
iir->coef = ASSUME_ALIGNED(config->biquads, 4);
iir->coef = ASSUME_ALIGNED(&config->biquads[0], 4);
return 0;
}

View File

@ -284,7 +284,7 @@ static int mux_ctrl_set_cmd(struct comp_dev *dev,
switch (cdata->cmd) {
case SOF_CTRL_CMD_BINARY:
cfg = (struct sof_mux_config *)
ASSUME_ALIGNED(cdata->data->data, 4);
ASSUME_ALIGNED(&cdata->data->data, 4);
ret = mux_set_values(dev, cd, cfg);
break;

View File

@ -247,7 +247,7 @@ static int selector_ctrl_set_data(struct comp_dev *dev,
comp_info(dev, "selector_ctrl_set_data(), SOF_CTRL_CMD_BINARY");
cfg = (struct sof_sel_config *)
ASSUME_ALIGNED(cdata->data->data, 4);
ASSUME_ALIGNED(&cdata->data->data, 4);
/* Just set the configuration */
cd->config.in_channels_count = cfg->in_channels_count;

View File

@ -292,7 +292,7 @@ static int smart_amp_set_config(struct comp_dev *dev,
/* Copy new config, find size from header */
cfg = (struct sof_smart_amp_config *)
ASSUME_ALIGNED(cdata->data->data, sizeof(uint32_t));
ASSUME_ALIGNED(&cdata->data->data, sizeof(uint32_t));
bs = cfg->size;
comp_dbg(dev, "smart_amp_set_config(), actual blob size = %u, expected blob size = %u",

View File

@ -212,7 +212,7 @@ int maxim_dsm_set_param(struct smart_amp_mod_struct_t *hspk,
/* Model database */
int32_t *db = (int32_t *)caldata->data;
/* Payload buffer */
int *wparam = ASSUME_ALIGNED(cdata->data->data, 4);
uint32_t *wparam = (uint32_t *)ASSUME_ALIGNED(&cdata->data->data, 4);
/* number of parameters to read */
int num_param = (cdata->num_elems >> 2);
int idx, id, ch;

View File

@ -541,7 +541,7 @@ static int tone_cmd_set_data(struct comp_dev *dev,
case SOF_CTRL_CMD_ENUM:
comp_info(dev, "tone_cmd_set_data(), SOF_CTRL_CMD_ENUM, cdata->index = %u",
cdata->index);
compv = (struct sof_ipc_ctrl_value_comp *)ASSUME_ALIGNED(cdata->data->data, 4);
compv = (struct sof_ipc_ctrl_value_comp *)ASSUME_ALIGNED(&cdata->data->data, 4);
for (i = 0; i < (int)cdata->num_elems; i++) {
ch = compv[i].index;

View File

@ -136,6 +136,13 @@ struct sof_ipc_ctrl_data {
/* reserved for future use */
uint32_t reserved[6];
/* Flexible array members[] are forbidden in unions but this
* does not seem to bother gcc as long as non-standard
* zero-length arrays[0] are used instead. Nesting flexible
* array member declarations in arrays or structures is
* forbidden too. Cleaning this up would likely require code
* changes to explicitly cast intermediate steps.
*/
/* control data - add new types if needed */
union {
/* channel values can be used by volume type controls */

View File

@ -92,7 +92,7 @@ static int smart_amp_set_config(struct comp_dev *dev,
/* Copy new config, find size from header */
cfg = (struct sof_smart_amp_config *)
ASSUME_ALIGNED(cdata->data->data, sizeof(uint32_t));
ASSUME_ALIGNED(&cdata->data->data, sizeof(uint32_t));
bs = cfg->size;
comp_dbg(dev, "smart_amp_set_config(), actual blob size = %u, expected blob size = %u",