-
Notifications
You must be signed in to change notification settings - Fork 361
audio: eq_iir: register IPC-time blob validator #10942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
singalsu
wants to merge
2
commits into
thesofproject:main
Choose a base branch
from
singalsu:model_handler_validator_eqiir
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,20 +180,81 @@ void eq_iir_s32_default(struct processing_module *mod, struct input_stream_buffe | |
| } | ||
| #endif /* CONFIG_FORMAT_S32LE */ | ||
|
|
||
| static int eq_iir_blob_words_max(struct comp_dev *dev, | ||
| const struct sof_eq_iir_config *config, | ||
| size_t blob_size, | ||
| uint32_t *coef_words_max) | ||
| { | ||
| size_t payload_bytes; | ||
|
|
||
| /* Compute the size of the coefficient area in int32_t words from the | ||
| * framework-reported blob size. The blob layout is: | ||
| * sizeof(*config) header bytes | ||
| * channels_in_config int32_t assign_response[] | ||
| * coefficient data[] | ||
| * channels_in_config is bounded above, so the multiply fits in size_t. | ||
| * The blob's self-declared config->size is cross-checked against the | ||
| * authoritative blob_size so all later parsing stays within the buffer. | ||
| */ | ||
| if (blob_size < sizeof(*config) || config->size != blob_size) { | ||
| comp_err(dev, "blob size %zu / header size %u mismatch or too small", | ||
| blob_size, config->size); | ||
| return -EINVAL; | ||
| } | ||
| payload_bytes = blob_size - sizeof(*config); | ||
| if (payload_bytes % sizeof(int32_t) || | ||
| payload_bytes < (size_t)config->channels_in_config * sizeof(int32_t)) { | ||
| comp_err(dev, "blob size %zu misaligned or too small", blob_size); | ||
| return -EINVAL; | ||
| } | ||
| *coef_words_max = payload_bytes / sizeof(int32_t) - config->channels_in_config; | ||
| return 0; | ||
| } | ||
|
|
||
| static int eq_iir_init_response(struct comp_dev *dev, int idx, | ||
| int32_t *coef_data, uint32_t coef_words_max, | ||
| uint32_t *j, struct sof_eq_iir_header **eq_out) | ||
| { | ||
| struct sof_eq_iir_header *eq; | ||
| uint32_t header_end = *j + SOF_EQ_IIR_NHEADER; | ||
| uint32_t section_end; | ||
|
|
||
| /* Header must fit before reading num_sections */ | ||
| if (header_end > coef_words_max) { | ||
| comp_err(dev, "response %d header out of bounds", idx); | ||
| return -EINVAL; | ||
| } | ||
| eq = (struct sof_eq_iir_header *)&coef_data[*j]; | ||
| /* Bound num_sections so the multiply cannot overflow and the section | ||
| * data stays within the blob. | ||
| */ | ||
| section_end = header_end + (uint32_t)SOF_EQ_IIR_NBIQUAD * eq->num_sections; | ||
| if (eq->num_sections > SOF_EQ_IIR_BIQUADS_MAX || section_end > coef_words_max) { | ||
| comp_err(dev, "response %d num_sections %u out of bounds", | ||
| idx, eq->num_sections); | ||
| return -EINVAL; | ||
| } | ||
| *eq_out = eq; | ||
| *j = section_end; | ||
| return 0; | ||
| } | ||
|
|
||
| static int eq_iir_init_coef(struct processing_module *mod, int nch) | ||
| { | ||
| struct comp_data *cd = module_get_private_data(mod); | ||
| struct sof_eq_iir_config *config = cd->config; | ||
| struct iir_state_df1 *iir = cd->iir; | ||
| struct sof_eq_iir_header *lookup[SOF_EQ_IIR_MAX_RESPONSES]; | ||
| struct sof_eq_iir_header *eq; | ||
| uint32_t coef_words_max; | ||
| int32_t *assign_response; | ||
| int32_t *coef_data; | ||
| int size_sum = 0; | ||
| int resp = 0; | ||
| int i; | ||
| int j; | ||
| uint32_t j; | ||
| int s; | ||
| int ret; | ||
|
|
||
| comp_info(mod->dev, "%u responses, %u channels, stream %d channels", | ||
| config->number_of_responses, config->channels_in_config, nch); | ||
|
|
@@ -210,17 +271,21 @@ static int eq_iir_init_coef(struct processing_module *mod, int nch) | |
| return -EINVAL; | ||
| } | ||
|
|
||
| ret = eq_iir_blob_words_max(mod->dev, config, cd->config_size, &coef_words_max); | ||
| if (ret < 0) | ||
| return ret; | ||
|
|
||
| /* Collect index of response start positions in all_coefficients[] */ | ||
| j = 0; | ||
| assign_response = ASSUME_ALIGNED(&config->data[0], 4); | ||
| coef_data = ASSUME_ALIGNED(&config->data[config->channels_in_config], | ||
| 4); | ||
| coef_data = ASSUME_ALIGNED(&config->data[config->channels_in_config], 4); | ||
| for (i = 0; i < SOF_EQ_IIR_MAX_RESPONSES; i++) { | ||
| if (i < config->number_of_responses) { | ||
| eq = (struct sof_eq_iir_header *)&coef_data[j]; | ||
| ret = eq_iir_init_response(mod->dev, i, coef_data, | ||
| coef_words_max, &j, &eq); | ||
| if (ret < 0) | ||
| return ret; | ||
| lookup[i] = eq; | ||
| j += SOF_EQ_IIR_NHEADER | ||
| + SOF_EQ_IIR_NBIQUAD * eq->num_sections; | ||
| } else { | ||
| lookup[i] = NULL; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
@@ -318,7 +383,10 @@ int eq_iir_setup(struct processing_module *mod, int nch) | |
| /* Free existing IIR channels data if it was allocated */ | ||
| eq_iir_free_delaylines(mod); | ||
|
|
||
| /* Set coefficients for each channel EQ from coefficient blob */ | ||
| /* Set coefficients for each channel EQ from coefficient blob. | ||
| * eq_iir_init_coef() / eq_iir_blob_words_max() perform all blob size | ||
| * sanity checks, including config->size vs cd->config_size. | ||
| */ | ||
| delay_size = eq_iir_init_coef(mod, nch); | ||
| if (delay_size < 0) | ||
| return delay_size; /* Contains error code */ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you never propagate this function's returned error code and always use it as a condition in
ifclauses. How about making it boolean