Skip to content

audio: component: add comp_free_device() and use it as pair of comp_a…#10551

Open
kv2019i wants to merge 1 commit intothesofproject:mainfrom
kv2019i:202602-comp-free-dev
Open

audio: component: add comp_free_device() and use it as pair of comp_a…#10551
kv2019i wants to merge 1 commit intothesofproject:mainfrom
kv2019i:202602-comp-free-dev

Conversation

@kv2019i
Copy link
Collaborator

@kv2019i kv2019i commented Feb 16, 2026

…lloc()

In commit c49283a ("ptl: mmu: Introduce module driver heap for non-privileged modules"), implementation of comp_alloc() was modified to use module heap alloc functions instead of rzalloc(). The calling functions kept using direct rfree() to free the component device.

In commit e8e5ff0 ("module-adapter: fix wrong memory freeing"), some of the callers were modified to use user heap functions for freeing the component device.

To make this code safer, introduce comp_free_device() that frees the memory using the method used in comp_alloc() and use comp_free_device() in all places where comp_alloc() is used. The naming is a bit awkward as comp_free() is already taken to invoke the "free" method of the component interface.

…lloc()

In commit c49283a ("ptl: mmu: Introduce module driver heap for
non-privileged modules"), implementation of comp_alloc() was modified
to use module heap alloc functions instead of rzalloc(). The calling
functions kept using direct rfree() to free the component device.

In commit e8e5ff0 ("module-adapter: fix wrong memory freeing"),
some of the callers were modified to use user heap functions for freeing
the component device.

To make this code safer, introduce comp_free_device() that frees the
memory using the method used in comp_alloc() and use comp_free_device()
in all places where comp_alloc() is used. The naming is a bit awkward as
comp_free() is already taken to invoke the "free" method of the
component interface.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Copilot AI review requested due to automatic review settings February 16, 2026 13:20
@kv2019i
Copy link
Collaborator Author

kv2019i commented Feb 16, 2026

@softwarecki and @lyakh please check.

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 introduces a new comp_free_device() function to properly pair with comp_alloc() for component device memory management. The change addresses inconsistent memory freeing patterns where comp_alloc() uses module heap allocation but some callers were using direct rfree() or user heap functions to free the memory.

Changes:

  • Added comp_free_device() function in component.h that uses the same heap mechanism as comp_alloc()
  • Replaced all direct rfree(dev) calls with comp_free_device(dev) across multiple audio component files

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/include/sof/audio/component.h Adds new comp_free_device() function definition
src/samples/audio/smart_amp_test_ipc3.c Updates smart amp component to use comp_free_device()
src/samples/audio/detect_test.c Updates keyword detect component to use comp_free_device()
src/audio/tone/tone-ipc3.c Updates tone generator component to use comp_free_device()
src/audio/selector/selector.c Updates selector component to use comp_free_device()
src/audio/kpb.c Updates key phrase buffer component to use comp_free_device()
src/audio/host-zephyr.c Updates Zephyr host component to use comp_free_device()
src/audio/host-legacy.c Updates legacy host component to use comp_free_device()
src/audio/google/google_hotword_detect.c Updates Google hotword detector to use comp_free_device()
src/audio/dai-zephyr.c Updates Zephyr DAI component to use comp_free_device()
src/audio/dai-legacy.c Updates legacy DAI component to use comp_free_device()
src/audio/chain_dma.c Updates chain DMA component to use comp_free_device()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@softwarecki softwarecki left a comment

Choose a reason for hiding this comment

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

Good change! The name is indeed a bit awkward but I don't have a better idea.

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.

2 participants