-
Notifications
You must be signed in to change notification settings - Fork 364
Audio modules fixes #10752
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
base: main
Are you sure you want to change the base?
Audio modules fixes #10752
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -315,15 +315,25 @@ static void asrc_release_buffers(struct processing_module *mod, struct asrc_farr | |
| static int asrc_free(struct processing_module *mod) | ||
| { | ||
| struct comp_data *cd = module_get_private_data(mod); | ||
| struct comp_dev *dev = mod->dev; | ||
|
|
||
| comp_dbg(dev, "entry"); | ||
| comp_dbg(mod->dev, "entry"); | ||
|
|
||
| if (!cd) | ||
| return 0; | ||
|
|
||
| mod_free(mod, cd->buf); | ||
| asrc_release_buffers(mod, cd->asrc_obj); | ||
| asrc_free_polyphase_filter(mod, cd->asrc_obj); | ||
| mod_free(mod, cd->asrc_obj); | ||
| cd->buf = NULL; | ||
|
|
||
| if (cd->asrc_obj) { | ||
|
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. same, can it be
Member
Author
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. Same rationale: reset() frees asrc_obj and sets it NULL, and free() can run afterwards. |
||
| asrc_release_buffers(mod, cd->asrc_obj); | ||
| asrc_free_polyphase_filter(mod, cd->asrc_obj); | ||
| mod_free(mod, cd->asrc_obj); | ||
| cd->asrc_obj = NULL; | ||
| } | ||
|
|
||
| mod_free(mod, cd); | ||
| module_set_private_data(mod, NULL); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
@@ -862,12 +872,17 @@ static int asrc_reset(struct processing_module *mod) | |
| asrc_dai_stop_timestamp(cd); | ||
|
|
||
| /* Free the allocations those were done in prepare() */ | ||
| asrc_release_buffers(mod, cd->asrc_obj); | ||
| asrc_free_polyphase_filter(mod, cd->asrc_obj); | ||
| mod_free(mod, cd->asrc_obj); | ||
| mod_free(mod, cd->buf); | ||
| cd->asrc_obj = NULL; | ||
| cd->buf = NULL; | ||
| if (cd->asrc_obj) { | ||
| asrc_release_buffers(mod, cd->asrc_obj); | ||
| asrc_free_polyphase_filter(mod, cd->asrc_obj); | ||
| mod_free(mod, cd->asrc_obj); | ||
| cd->asrc_obj = NULL; | ||
| } | ||
|
|
||
| if (cd->buf) { | ||
|
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. same for the above 2 added checks
Member
Author
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. Same here — reset() can be followed by free() (or another reset()), so guarding asrc_obj/buf with a non-NULL check and NULLing them after release prevents the second path from re-freeing. Kept deliberately for that reason. |
||
| mod_free(mod, cd->buf); | ||
| cd->buf = NULL; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,15 @@ int mic_privacy_manager_init(void) | |
| if (!mic_priv_dev) | ||
| return -EINVAL; | ||
|
|
||
| if (!device_is_ready(mic_priv_dev)) { | ||
| LOG_ERR("mic_privacy device not ready"); | ||
| /* Clear the handle so later helpers take their !mic_priv_dev | ||
| * path instead of dereferencing a device that is not ready | ||
| */ | ||
| mic_priv_dev = NULL; | ||
| return -ENODEV; | ||
| } | ||
|
Comment on lines
+98
to
+105
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. This is a valid concern. Maybe alternative is to drop mic privacy when running the ztest?
Member
Author
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. probably want to drop it for native_sim, but for qemu ACE its a doable test - the funny thing is copilot is reviewing itself here for this change.
Member
Author
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. Addressed — on the device-not-ready path init now clears mic_priv_dev (sets it NULL) before returning -ENODEV, so the other helpers take their existing |
||
|
|
||
| mic_privacy_api = (struct mic_privacy_api_funcs *)mic_priv_dev->api; | ||
| mic_privacy_policy = mic_privacy_api->get_policy(); | ||
|
|
||
|
|
@@ -109,6 +118,9 @@ int mic_privacy_manager_init(void) | |
|
|
||
| int mic_privacy_manager_get_policy(void) | ||
| { | ||
| if (!mic_priv_dev) | ||
| return MIC_PRIVACY_HW_MANAGED; | ||
|
|
||
| mic_privacy_api = (struct mic_privacy_api_funcs *)mic_priv_dev->api; | ||
|
|
||
| return mic_privacy_api->get_policy(); | ||
|
|
||
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.
can it be called with
cd == NULL? Don't think so,.free()is probably only called when.init()was successfulThere 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.
These guards are the actual double-free fix, not redundant checks. In the ZTest teardown that triggered this, free() runs more than once: the first call frees buf/asrc_obj, sets them NULL, frees cd and calls module_set_private_data(mod, NULL). The
if (!cd)then makes the second free() a clean no-op instead of double-freeing cd. So it cannot be NULL on a normal single free after a successful init, but it can on the repeated-free path this fix targets.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.
so it cannot happen during normal usage? If so, does it make sense to have ztest flows that cannot happen in real situations and to have to modify the sources to support them?