From 4316f3c83635b4ae043b9ebc29b8135d49fbbabf Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 20 Nov 2020 10:43:59 +0100 Subject: [PATCH] alloc: simplify align_ptr() Simplify the align_ptr() function by re-using an existing ALIGN() macro. Signed-off-by: Guennadi Liakhovetski --- src/lib/alloc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/alloc.c b/src/lib/alloc.c index af1251598..f99c4d04a 100644 --- a/src/lib/alloc.c +++ b/src/lib/alloc.c @@ -190,17 +190,14 @@ static void *rmalloc_sys(struct mm_heap *heap, uint32_t flags, int caps, size_t static void *align_ptr(struct mm_heap *heap, uint32_t alignment, void *ptr, struct block_hdr *hdr) { - int mod_align = 0; - /* Save unaligned ptr to block hdr */ hdr->unaligned_ptr = ptr; /* If ptr is not already aligned we calculate alignment shift */ - if (alignment && (uintptr_t)ptr % alignment) - mod_align = alignment - ((uintptr_t)ptr % alignment); + if (alignment <= 1) + return ptr; - /* Calculate aligned pointer */ - return (char *)ptr + mod_align; + return (void *)ALIGN((uintptr_t)ptr, alignment); } /* allocate single block */