module_adapter: dp: Improve module adapter creation function#10565
Open
softwarecki wants to merge 3 commits intothesofproject:mainfrom
Open
module_adapter: dp: Improve module adapter creation function#10565softwarecki wants to merge 3 commits intothesofproject:mainfrom
softwarecki wants to merge 3 commits intothesofproject:mainfrom
Conversation
Move mod field initialization in module_adapter_new_ext() before creating the dp thread. Moving the initialization earlier prevents the dp thread from use uninitialized data. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
There was a problem hiding this comment.
Pull request overview
This PR improves error handling and initialization order in the module adapter creation flow for data processing tasks. The changes ensure that task creation failures are properly detected and handled, prevent potential use-after-free issues, and guarantee that module fields are initialized before the DP thread can access them.
Changes:
- Add error checking for DP task initialization to catch creation failures
- Fix task pointer assignment to only occur on successful initialization
- Reorder module field initialization to happen before DP thread creation
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/schedule/zephyr_dp_schedule_thread.c | Modified scheduler_dp_task_init() to defer task pointer assignment until after successful thread creation |
| src/audio/module_adapter/module_adapter.c | Added error handling for DP task creation and moved module field initialization before thread creation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Check the value returned by the pipeline_comp_dp_task_init() call in module_adapter_new_ext(). Update scheduler_dp_task_init() to assign the output task structure pointer only on success. The function allocates task structure and free it on failure. Returning a non-null task on error could lead to a double free in the module adapter or use after free. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Fix use after free in module_adapter_new_ext() by removing the dst access after freeing mod. The dst points to a field inside the previously allocated mod structure. The structure is freed on error so its fields do not need to be cleared beforehand. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
b7ea2ac to
db5625c
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
pipeline_comp_dp_task_init()to ensure the dp thread is created successfully. This prevents execution from continuing with an invalid task.scheduler_dp_task_init()to assign the output task pointer only on success. The function frees the allocated task structure on failure, so returning a non-null task could lead to a double free or use after free.module_adapter_new_ext()to occur before creating the dp thread. This prevents the thread from use uninitialized fields.