diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index 65ee07cc566..9e908a38c3a 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -114,6 +114,7 @@ */ #define MM_ALLOC_BIT 0x1 +#define MM_MASK_BIT MM_ALLOC_BIT #ifdef CONFIG_MM_SMALL # define MMSIZE_MAX UINT16_MAX #else diff --git a/mm/mm_heap/mm_foreach.c b/mm/mm_heap/mm_foreach.c index 70cf1579c00..9c86fd2dbb6 100644 --- a/mm/mm_heap/mm_foreach.c +++ b/mm/mm_heap/mm_foreach.c @@ -86,7 +86,7 @@ void mm_foreach(FAR struct mm_heap_s *heap, mmchunk_handler_t handler, handler(node, arg); DEBUGASSERT(prev == NULL || - prev->size == (node->preceding & ~MM_ALLOC_BIT)); + prev->size == (node->preceding & ~MM_MASK_BIT)); prev = node; } diff --git a/mm/mm_heap/mm_free.c b/mm/mm_heap/mm_free.c index dcb89fe05f2..d7d75d574b5 100644 --- a/mm/mm_heap/mm_free.c +++ b/mm/mm_heap/mm_free.c @@ -107,12 +107,12 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) DEBUGASSERT(node->preceding & MM_ALLOC_BIT); - node->preceding &= ~MM_ALLOC_BIT; + node->preceding &= ~MM_MASK_BIT; /* Check if the following node is free and, if so, merge it */ next = (FAR struct mm_freenode_s *)((FAR char *)node + node->size); - DEBUGASSERT((next->preceding & ~MM_ALLOC_BIT) == node->size); + DEBUGASSERT((next->preceding & ~MM_MASK_BIT) == node->size); if ((next->preceding & MM_ALLOC_BIT) == 0) { FAR struct mm_allocnode_s *andbeyond; @@ -140,7 +140,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) node->size += next->size; andbeyond->preceding = node->size | - (andbeyond->preceding & MM_ALLOC_BIT); + (andbeyond->preceding & MM_MASK_BIT); next = (FAR struct mm_freenode_s *)andbeyond; } @@ -149,7 +149,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) */ prev = (FAR struct mm_freenode_s *)((FAR char *)node - node->preceding); - DEBUGASSERT((node->preceding & ~MM_ALLOC_BIT) == prev->size); + DEBUGASSERT((node->preceding & ~MM_MASK_BIT) == prev->size); if ((prev->preceding & MM_ALLOC_BIT) == 0) { /* Remove the node. There must be a predecessor, but there may @@ -166,7 +166,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) /* Then merge the two chunks */ prev->size += node->size; - next->preceding = prev->size | (next->preceding & MM_ALLOC_BIT); + next->preceding = prev->size | (next->preceding & MM_MASK_BIT); node = prev; } diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c index c1d52b23c98..0f1bb578085 100644 --- a/mm/mm_heap/mm_malloc.c +++ b/mm/mm_heap/mm_malloc.c @@ -221,7 +221,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) * the allocated flag. */ - next->preceding = remaining | (next->preceding & MM_ALLOC_BIT); + next->preceding = remaining | (next->preceding & MM_MASK_BIT); /* Add the remainder back into the nodelist */ diff --git a/mm/mm_heap/mm_memalign.c b/mm/mm_heap/mm_memalign.c index 4608aa18c69..8e814fdf912 100644 --- a/mm/mm_heap/mm_memalign.c +++ b/mm/mm_heap/mm_memalign.c @@ -184,7 +184,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, /* Reduce the size of the original chunk and mark it not allocated, */ node->size = precedingsize; - node->preceding &= ~MM_ALLOC_BIT; + node->preceding &= ~MM_MASK_BIT; /* Fix the preceding size of the next node */ diff --git a/mm/mm_heap/mm_realloc.c b/mm/mm_heap/mm_realloc.c index 11a937a1a21..e45365fd1cd 100644 --- a/mm/mm_heap/mm_realloc.c +++ b/mm/mm_heap/mm_realloc.c @@ -151,7 +151,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, } prev = (FAR struct mm_freenode_s *) - ((FAR char *)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT)); + ((FAR char *)oldnode - (oldnode->preceding & ~MM_MASK_BIT)); if ((prev->preceding & MM_ALLOC_BIT) == 0) { prevsize = prev->size; @@ -253,7 +253,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, newnode->size = oldsize + takeprev; newnode->preceding = prev->size | MM_ALLOC_BIT; next->preceding = newnode->size | - (next->preceding & MM_ALLOC_BIT); + (next->preceding & MM_MASK_BIT); /* Return the previous free node to the nodelist * (with the new size) @@ -268,7 +268,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, newnode->size += oldsize; newnode->preceding |= MM_ALLOC_BIT; next->preceding = newnode->size | - (next->preceding & MM_ALLOC_BIT); + (next->preceding & MM_MASK_BIT); } newmem = (FAR void *)((FAR char *)newnode + SIZEOF_MM_ALLOCNODE); @@ -321,7 +321,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, DEBUGASSERT(newnode->size >= SIZEOF_MM_FREENODE); newnode->preceding = oldnode->size; andbeyond->preceding = newnode->size | - (andbeyond->preceding & MM_ALLOC_BIT); + (andbeyond->preceding & MM_MASK_BIT); /* Add the new free node to the nodelist (with the new size) */ @@ -332,7 +332,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, /* Yes, just update some pointers. */ andbeyond->preceding = oldnode->size | - (andbeyond->preceding & MM_ALLOC_BIT); + (andbeyond->preceding & MM_MASK_BIT); } } diff --git a/mm/mm_heap/mm_shrinkchunk.c b/mm/mm_heap/mm_shrinkchunk.c index 1743e546871..5f57519440a 100644 --- a/mm/mm_heap/mm_shrinkchunk.c +++ b/mm/mm_heap/mm_shrinkchunk.c @@ -95,7 +95,7 @@ void mm_shrinkchunk(FAR struct mm_heap_s *heap, newnode->preceding = size; node->size = size; andbeyond->preceding = newnode->size | - (andbeyond->preceding & MM_ALLOC_BIT); + (andbeyond->preceding & MM_MASK_BIT); /* Add the new node to the freenodelist */ @@ -121,7 +121,8 @@ void mm_shrinkchunk(FAR struct mm_heap_s *heap, newnode->size = node->size - size; newnode->preceding = size; node->size = size; - next->preceding = newnode->size | MM_ALLOC_BIT; + next->preceding = newnode->size | + (next->preceding & MM_MASK_BIT); /* Add the new node to the freenodelist */