From b4734d539732a7f807ffd542a73e9952941a711f Mon Sep 17 00:00:00 2001 From: Jay Shoen Date: Wed, 28 Sep 2022 17:59:45 -0600 Subject: [PATCH] kernel: kheap: fix k_heap_aligned_alloc handling of K_FOREVER k_heap_aligned_alloc was not handling K_FOREVER timeout correctly due to unsigned return value. Added explicit K_FOREVER handling of end time. Fixes #50611. Signed-off-by: Jay Shoen --- kernel/kheap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/kheap.c b/kernel/kheap.c index 12641a38933..9a044deebfb 100644 --- a/kernel/kheap.c +++ b/kernel/kheap.c @@ -66,6 +66,9 @@ void *k_heap_aligned_alloc(struct k_heap *h, size_t align, size_t bytes, { int64_t now, end = sys_clock_timeout_end_calc(timeout); void *ret = NULL; + + end = K_TIMEOUT_EQ(timeout, K_FOREVER) ? INT64_MAX : end; + k_spinlock_key_t key = k_spin_lock(&h->lock); SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_heap, aligned_alloc, h, timeout);