From 6214f3cde72d30a8b3a3bf37469eb0d97dad09d6 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Fri, 6 Jan 2023 01:28:13 +0800 Subject: [PATCH] mm/heap: Fix the minor style issue Signed-off-by: Xiang Xiao --- mm/mm_heap/mm_extend.c | 8 ++++---- mm/mm_heap/mm_free.c | 2 -- mm/mm_heap/mm_memalign.c | 19 +++++++++---------- mm/mm_heap/mm_shrinkchunk.c | 4 ++-- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/mm/mm_heap/mm_extend.c b/mm/mm_heap/mm_extend.c index 2278ba927d..9ffc7e74cb 100644 --- a/mm/mm_heap/mm_extend.c +++ b/mm/mm_heap/mm_extend.c @@ -61,8 +61,8 @@ void mm_extend(FAR struct mm_heap_s *heap, FAR void *mem, size_t size, DEBUGASSERT(heap && mem); #if CONFIG_MM_REGIONS > 1 - DEBUGASSERT(size >= MIN_EXTEND && - (size_t)region < (size_t)heap->mm_nregions); + DEBUGASSERT(size >= MIN_EXTEND && region >= 0 && + region < heap->mm_nregions); #else DEBUGASSERT(size >= MIN_EXTEND && region == 0); #endif @@ -84,7 +84,7 @@ void mm_extend(FAR struct mm_heap_s *heap, FAR void *mem, size_t size, */ oldnode = heap->mm_heapend[region]; - DEBUGASSERT((uintptr_t)oldnode + SIZEOF_MM_ALLOCNODE == (uintptr_t)mem); + DEBUGASSERT((uintptr_t)oldnode + SIZEOF_MM_ALLOCNODE == blockstart); /* The size of the old node now extends to the new terminal node. * This is the old size (SIZEOF_MM_ALLOCNODE) plus the size of @@ -112,5 +112,5 @@ void mm_extend(FAR struct mm_heap_s *heap, FAR void *mem, size_t size, * located. */ - mm_free(heap, (FAR void *)mem); + mm_free(heap, mem); } diff --git a/mm/mm_heap/mm_free.c b/mm/mm_heap/mm_free.c index 1e226078de..66f3707bda 100644 --- a/mm/mm_heap/mm_free.c +++ b/mm/mm_heap/mm_free.c @@ -72,9 +72,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) FAR struct mm_freenode_s *node; FAR struct mm_freenode_s *prev; FAR struct mm_freenode_s *next; - int ret; - UNUSED(ret); minfo("Freeing %p\n", mem); /* Protect against attempts to free a NULL reference */ diff --git a/mm/mm_heap/mm_memalign.c b/mm/mm_heap/mm_memalign.c index 833d37b779..45b61ee6b6 100644 --- a/mm/mm_heap/mm_memalign.c +++ b/mm/mm_heap/mm_memalign.c @@ -52,9 +52,9 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, size_t size) { FAR struct mm_allocnode_s *node; - size_t rawchunk; - size_t alignedchunk; - size_t mask = (size_t)(alignment - 1); + uintptr_t rawchunk; + uintptr_t alignedchunk; + size_t mask = alignment - 1; size_t allocsize; size_t newsize; @@ -95,11 +95,10 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, * not include SIZEOF_MM_ALLOCNODE. */ - newsize = MM_ALIGN_UP(size); /* Make multiples of our granule size */ - + newsize = MM_ALIGN_UP(size); /* Make multiples of our granule size */ allocsize = newsize + 2 * alignment; /* Add double full alignment size */ - if ((newsize < size) || (allocsize < newsize)) + if (newsize < size || allocsize < newsize) { /* Integer overflow */ @@ -108,7 +107,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, /* Then malloc that size */ - rawchunk = (size_t)mm_malloc(heap, allocsize); + rawchunk = (uintptr_t)mm_malloc(heap, allocsize); if (rawchunk == 0) { return NULL; @@ -158,7 +157,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, * SIZEOF_MM_ALLOCNODE */ - precedingsize = (size_t)newnode - (size_t)node; + precedingsize = (uintptr_t)newnode - (uintptr_t)node; /* If we were unlucky, then the alignedchunk can lie in such a position * that precedingsize < SIZEOF_NODE_FREENODE. We can't let that happen @@ -173,12 +172,12 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, alignedchunk += alignment; newnode = (FAR struct mm_allocnode_s *) (alignedchunk - SIZEOF_MM_ALLOCNODE); - precedingsize = (size_t)newnode - (size_t)node; + precedingsize = (uintptr_t)newnode - (uintptr_t)node; } /* Set up the size of the new node */ - newnode->size = (size_t)next - (size_t)newnode; + newnode->size = (uintptr_t)next - (uintptr_t)newnode; newnode->preceding = precedingsize | MM_ALLOC_BIT; /* Reduce the size of the original chunk and mark it not allocated, */ diff --git a/mm/mm_heap/mm_shrinkchunk.c b/mm/mm_heap/mm_shrinkchunk.c index 5f57519440..42c87e0bad 100644 --- a/mm/mm_heap/mm_shrinkchunk.c +++ b/mm/mm_heap/mm_shrinkchunk.c @@ -49,8 +49,8 @@ * ****************************************************************************/ -void mm_shrinkchunk(FAR struct mm_heap_s *heap, - FAR struct mm_allocnode_s *node, size_t size) +void mm_shrinkchunk(FAR struct mm_heap_s *heap, + FAR struct mm_allocnode_s *node, size_t size) { FAR struct mm_freenode_s *next;