From 79a591fb3879a663208e5e3fb29886e0fe735f7e Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Tue, 13 May 2014 13:47:32 -0700 Subject: libpayload: Fix pointer related casts Fix pointer related casts since this can create a problem for 64-bit systems. BUG=None BRANCH=None TEST=Compiled successfully for link, nyan using emerge-* libpayload Original-Change-Id: I4cbd2d9f1efaaac87c3eba69204337fd6893ed66 Original-Reviewed-on: https://chromium-review.googlesource.com/199564 Original-Reviewed-by: Furquan Shaikh Original-Commit-Queue: Furquan Shaikh Original-Tested-by: Furquan Shaikh (cherry picked from commit 914b118a64b0691aeca463dff24252db9c24109e) Signed-off-by: Marc Jones Change-Id: I11f070ed5d3eddd8b9be30c428cb24c8439e617b Reviewed-on: http://review.coreboot.org/7905 Reviewed-by: Edward O'Callaghan Tested-by: build bot (Jenkins) --- payloads/libpayload/libc/malloc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'payloads/libpayload/libc') diff --git a/payloads/libpayload/libc/malloc.c b/payloads/libpayload/libc/malloc.c index 0f2845d4ea..1d99a9c4b6 100644 --- a/payloads/libpayload/libc/malloc.c +++ b/payloads/libpayload/libc/malloc.c @@ -41,6 +41,7 @@ #define IN_MALLOC_C #include +#include struct memory_type { void *start; @@ -158,7 +159,7 @@ static void *alloc(int len, struct memory_type *type) if (header & FLAG_FREE) { if (len <= size) { - hdrtype_t volatile *nptr = (hdrtype_t volatile *)((int)ptr + HDRSIZE + len); + hdrtype_t volatile *nptr = (hdrtype_t volatile *)((uintptr_t)ptr + HDRSIZE + len); int nsize = size - (HDRSIZE + len); /* If there is still room in this block, @@ -177,11 +178,11 @@ static void *alloc(int len, struct memory_type *type) *ptr = USED_BLOCK(size); } - return (void *)((int)ptr + HDRSIZE); + return (void *)((uintptr_t)ptr + HDRSIZE); } } - ptr = (hdrtype_t volatile *)((int)ptr + HDRSIZE + size); + ptr = (hdrtype_t volatile *)((uintptr_t)ptr + HDRSIZE + size); } while (ptr < (hdrtype_t *) type->end); @@ -353,7 +354,7 @@ static struct align_region_t *allocate_region(int alignment, int num_elements, s free(new_region); return NULL; } - new_region->start_data = (void*)((u32)(new_region->start + num_elements + alignment - 1) & (~(alignment-1))); + new_region->start_data = (void*)((uintptr_t)(new_region->start + num_elements + alignment - 1) & (~(alignment-1))); new_region->size = num_elements * alignment; new_region->free = num_elements; new_region->next = type->align_regions; -- cgit v1.2.3