Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ static struct k_heap *module_adapter_dp_heap_new(const struct comp_ipc_config *c
void *mod_heap_buf = mod_heap_mem + heap_prefix_size;

k_heap_init(mod_heap, mod_heap_buf, heap_size - heap_prefix_size);
mod_heap->heap.init_mem = mod_heap_buf;
mod_heap->heap.init_bytes = heap_size - heap_prefix_size;

return mod_heap;
}
Expand Down
4 changes: 3 additions & 1 deletion src/include/sof/audio/component_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,16 @@ static inline int comp_trigger_local(struct comp_dev *dev, int cmd)
int ret;

ret = dev->drv->ops.trigger(dev, cmd);
if (ret)
return ret;

/* start a thread in case of shared component or DP scheduling */
if (dev->task) {
/* schedule or cancel task */
switch (cmd) {
case COMP_TRIGGER_START:
case COMP_TRIGGER_RELEASE:
schedule_task(dev->task, 0, dev->period);
ret = schedule_task(dev->task, 0, dev->period);
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The return value of schedule_task is captured but never checked or returned. If schedule_task fails after a successful trigger operation, the error is silently ignored. Consider checking ret and handling the error appropriately.

Copilot uses AI. Check for mistakes.
break;
case COMP_TRIGGER_XRUN:
case COMP_TRIGGER_PAUSE:
Expand Down
3 changes: 2 additions & 1 deletion src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ __cold int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
audio_buffer_is_shared(&buffer->audio_buffer),
buf_get_id(buffer));
if (!ring_buffer)
goto free;
goto free_unlocked;

/* data destination module needs to use ring_buffer */
audio_buffer_attach_secondary_buffer(&buffer->audio_buffer, dp_on_source,
Expand Down Expand Up @@ -698,6 +698,7 @@ __cold int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
pipeline_disconnect(source, buffer, PPL_CONN_DIR_COMP_TO_BUFFER);
free:
ll_unblock(cross_core_bind, flags);
free_unlocked:
buffer_free(buffer);
return IPC4_INVALID_RESOURCE_STATE;
}
Expand Down
23 changes: 21 additions & 2 deletions zephyr/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,25 @@ extern char _end[], _heap_sentry[];

static struct k_heap sof_heap;

/**
* Checks whether pointer is from a given heap memory.
* @param heap Pointer to a heap.
* @param ptr Pointer to memory being checked.
* @return True if pointer falls into heap memory region, false otherwise.
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth to spell out in the comments that this API doesn't tell us if memory ptr is currently allocated or free.

*/
static bool is_heap_pointer(const struct k_heap *heap, void *ptr)
{
uintptr_t heap_start =
POINTER_TO_UINT(sys_cache_cached_ptr_get(heap->heap.init_mem));
uintptr_t heap_end = heap_start + heap->heap.init_bytes;

if (!is_cached(ptr))
ptr = (__sparse_force void *)sys_cache_cached_ptr_get(ptr);

return ((POINTER_TO_UINT(ptr) >= heap_start) &&
(POINTER_TO_UINT(ptr) < heap_end));
}

#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
static struct k_heap shared_buffer_heap;

Expand Down Expand Up @@ -628,7 +647,7 @@ EXPORT_SYMBOL(rfree);
void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
size_t alignment)
{
if (flags & SOF_MEM_FLAG_LARGE_BUFFER)
if (flags & (SOF_MEM_FLAG_LARGE_BUFFER | SOF_MEM_FLAG_USER_SHARED_BUFFER))
return rballoc_align(flags, bytes, alignment);

if (!heap)
Expand All @@ -642,7 +661,7 @@ void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,

void sof_heap_free(struct k_heap *heap, void *addr)
{
if (heap && addr)
if (heap && addr && is_heap_pointer(heap, addr))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems a bit complex, but this would indeed seem to be a needed check, also for SOF_MEM_FLAG_LARGE_BUFFER .

heap_free(heap, addr);
else
rfree(addr);
Expand Down
Loading