Skip to content

Comments

module_adapter: dp: Improve module adapter creation function#10565

Open
softwarecki wants to merge 5 commits intothesofproject:mainfrom
softwarecki:adapter-fix
Open

module_adapter: dp: Improve module adapter creation function#10565
softwarecki wants to merge 5 commits intothesofproject:mainfrom
softwarecki:adapter-fix

Conversation

@softwarecki
Copy link
Collaborator

  • Add checking of the return value from pipeline_comp_dp_task_init() to ensure the dp thread is created successfully. This prevents execution from continuing with an invalid task.
  • Update 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.
  • Move mod field initialization in module_adapter_new_ext() to occur before creating the dp thread. This prevents the thread from use uninitialized fields.

Copilot AI review requested due to automatic review settings February 20, 2026 15:37
@softwarecki softwarecki changed the title module_adapter: dp: Improve adapter creation function module_adapter: dp: Improve module adapter creation function Feb 20, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

list_init(&mod->raw_data_buffers_list);
#if CONFIG_USERSPACE
mod->user_ctx = user_ctx;
#endif /* CONFIG_USERSPACE */
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose this isn't breaking anything and in fact does seem logical, but for the understanding: is this use of uninitialised data really happening? This is called in IPC context. The DP thread suspends immediately when started - I suppose in the "thread" variant too? The thread shouldn't be woken up before this IPC processing completes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the dp thread creation function uses user_ctx. If we don't assign this value first, a kernel dp thread will be created instead of a userspace thread.

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>
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>
Remove the no longer needed user_memory_init_shared(). Add the dp thread to
the memory domain directly in the dp scheduler.

The function originally added the common partition to the memory domain and
added thread to that domain. The userspace proxy now adds the common
partition to memory domain, so the function cannot perform this step.

Grant access to thread only when userspace is used. Kernel threads have
access to all the memory, no need to additionally grant access to them.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Total of 153 commits.

Changes include:
d885cfebaa3 soc: intel_adsp/ace: Fix MMU mapping for shared heap
bb8d441d201 tests: llext: add harvard to scope, build for nsim/nsim_em
ebf1f9d019b tests: llext: fixes for arcmwdt, gcc

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants