Skip to content

Commit 78f0fd5

Browse files
committed
zephyr: alloc: Use generic is_heap_pointer for L3 heap
Replace the is_l3_heap_pointer function with the generic is_heap_pointer for L3 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 39cc10b commit 78f0fd5

1 file changed

Lines changed: 6 additions & 19 deletions

File tree

zephyr/lib/alloc.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,6 @@ void l3_heap_save(void)
244244
get_l3_heap_size());
245245
}
246246

247-
/**
248-
* Checks whether pointer is from L3 heap memory range.
249-
* @param ptr Pointer to memory being checked.
250-
* @return True if pointer falls into L3 heap region, false otherwise.
251-
*/
252-
static bool is_l3_heap_pointer(void *ptr)
253-
{
254-
uintptr_t l3_heap_start = get_l3_heap_start();
255-
uintptr_t l3_heap_end = l3_heap_start + get_l3_heap_size();
256-
257-
if ((POINTER_TO_UINT(ptr) >= l3_heap_start) && (POINTER_TO_UINT(ptr) < l3_heap_end))
258-
return true;
259-
260-
return false;
261-
}
262-
263247
static void *l3_heap_alloc_aligned(struct k_heap *h, size_t min_align, size_t bytes)
264248
{
265249
k_spinlock_key_t key;
@@ -609,7 +593,7 @@ void rfree(void *ptr)
609593
return;
610594

611595
#if CONFIG_L3_HEAP
612-
if (is_l3_heap_pointer(ptr)) {
596+
if (is_heap_pointer(&l3_heap, ptr)) {
613597
l3_heap_free(&l3_heap, ptr);
614598
return;
615599
}
@@ -680,10 +664,13 @@ static int heap_init(void)
680664

681665
arch_mem_map(l3_heap_start, va, l3_heap_size, K_MEM_PERM_RW | K_MEM_CACHE_WB);
682666
#endif
683-
if (l3_heap_copy.heap.heap)
667+
if (l3_heap_copy.heap.heap) {
684668
l3_heap = l3_heap_copy;
685-
else
669+
} else {
670+
l3_heap.heap.init_mem = l3_heap_start;
671+
l3_heap.heap.init_bytes = l3_heap_size;
686672
sys_heap_init(&l3_heap.heap, l3_heap_start, l3_heap_size);
673+
}
687674
}
688675
#endif
689676

0 commit comments

Comments
 (0)