Skip to content

Commit 2470b16

Browse files
softwareckikv2019i
authored andcommitted
zephyr: alloc: Use generic is_heap_pointer for shared heap
Replace the is_shared_buffer_heap_pointer function with the generic is_heap_pointer for shared heap. This change simplifies the memory handling path by relying on a common utility instead of a specialized function. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent d64406b commit 2470b16

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

zephyr/lib/alloc.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,6 @@ static bool is_heap_pointer(const struct k_heap *heap, void *ptr)
177177
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
178178
static struct k_heap shared_buffer_heap;
179179

180-
static bool is_shared_buffer_heap_pointer(void *ptr)
181-
{
182-
uintptr_t shd_heap_start = POINTER_TO_UINT(shared_heapmem);
183-
uintptr_t shd_heap_end = POINTER_TO_UINT(shared_heapmem + SHARED_BUFFER_HEAP_MEM_SIZE);
184-
185-
if (sys_cache_is_ptr_cached(ptr))
186-
ptr = sys_cache_uncached_ptr_get((__sparse_force void __sparse_cache *)ptr);
187-
188-
return (POINTER_TO_UINT(ptr) >= shd_heap_start) && (POINTER_TO_UINT(ptr) < shd_heap_end);
189-
}
190-
191180
/**
192181
* Returns the start of HPSRAM Shared memory heap.
193182
* @return Pointer to the HPSRAM Shared memory location which can be used
@@ -634,7 +623,7 @@ void rfree(void *ptr)
634623
#endif
635624

636625
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
637-
if (is_shared_buffer_heap_pointer(ptr)) {
626+
if (is_heap_pointer(&shared_buffer_heap, ptr)) {
638627
heap_free(&shared_buffer_heap, ptr);
639628
return;
640629
}
@@ -676,6 +665,8 @@ static int heap_init(void)
676665
sys_heap_init(&sof_heap.heap, heapmem, HEAPMEM_SIZE - SHARED_BUFFER_HEAP_MEM_SIZE);
677666

678667
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
668+
shared_buffer_heap.heap.init_mem = shared_heapmem;
669+
shared_buffer_heap.heap.init_bytes = SHARED_BUFFER_HEAP_MEM_SIZE;
679670
sys_heap_init(&shared_buffer_heap.heap, shared_heapmem, SHARED_BUFFER_HEAP_MEM_SIZE);
680671
#endif
681672

0 commit comments

Comments
 (0)