Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions sound/soc/sof/ipc4-topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -1050,16 +1050,21 @@ static int sof_ipc4_init_audio_fmt(struct snd_sof_dev *sdev,
return -EINVAL;
}

/* copy input format */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@libinyang, the commit subject and message is not too verbose...

memcpy(&base_config->audio_fmt, &available_fmt->input_pin_fmts[i].audio_fmt,
sizeof(struct sof_ipc4_audio_format));

/* set base_cfg ibs/obs */
base_config->ibs = available_fmt->input_pin_fmts[i].buffer_size;
base_config->obs = available_fmt->output_pin_fmts[i].buffer_size;
/* copy input format and set base_cfg ibs*/
if (available_fmt->input_pin_fmts) {
memcpy(&base_config->audio_fmt, &available_fmt->input_pin_fmts[i].audio_fmt,
sizeof(struct sof_ipc4_audio_format));
base_config->ibs = available_fmt->input_pin_fmts[i].buffer_size;

dev_dbg(sdev->dev, "init input audio formats for %s\n", swidget->widget->name);
sof_ipc4_dbg_audio_format(sdev->dev, &available_fmt->input_pin_fmts[i], 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not group all the available_fmt->input_pin_fmts under one if? Along with the dev_dbg() few lines up?

} else {
dev_dbg(sdev->dev, "No init input audio formats for %s\n", swidget->widget->name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is printed when no input pin is defined, sure it means that there is no input format, but...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add this printed info in case some one will check the input audio formats. So he can easily use grep "init input audio formats" to get all input formats (also for this reason, I changed "Init" to "init" to print the same keyword in 2 conditions). Or we don't print anything for no input audio format scenario?

}

dev_dbg(sdev->dev, "Init input audio formats for %s\n", swidget->widget->name);
sof_ipc4_dbg_audio_format(sdev->dev, &available_fmt->input_pin_fmts[i], 1);
/* set base_cfg obs */
if (available_fmt->output_pin_fmts)
base_config->obs = available_fmt->output_pin_fmts[i].buffer_size;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non existent output_pin_fmts does not warrant similar print as the input_pin_fmts?


/* Return the index of the matched format */
return i;
Expand Down Expand Up @@ -1735,8 +1740,9 @@ static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget,
if (ret < 0)
return ret;

memcpy(&process->output_format, &available_fmt->output_pin_fmts[ret].audio_fmt,
sizeof(struct sof_ipc4_audio_format));
if (available_fmt->output_pin_fmts)
memcpy(&process->output_format, &available_fmt->output_pin_fmts[ret].audio_fmt,
sizeof(struct sof_ipc4_audio_format));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's say you got a match with the 2nd input format in sof_ipc4_init_audio_fmt(), that will make ret==1, let's say you have one output pin. available_fmt->output_pin_fmts[1] is out of bound.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's say you got a match with the 2nd input format in sof_ipc4_init_audio_fmt(), that will make ret==1, let's say you have one output pin. available_fmt->output_pin_fmts[1] is out of bound.

Yes, I mentioned a similar question in #4163 (comment). The output is not 1:1 mapping to input. Sometimes input number may be larger than output number. This may cause issue. What I understand is we will limit it in tplg based on @ranj063 's comments?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @ujfalusi raise this issue, I still want to recommend that we can add an index in the format structure. Let say:

 struct sof_ipc4_pin_format {
        u32 pin_index;
+       u32 format_index;
        u32 buffer_size;
        struct sof_ipc4_audio_format audio_fmt;
 };

When there is output format mapped to an input format, they have the same format_index. So we don't use ret as the output fmt idx. This can help us to avoid such out of bound accessing.


/* update pipeline memory usage */
sof_ipc4_update_pipeline_mem_usage(sdev, swidget, &process->base_config);
Expand Down