CV-Bowen commented on code in PR #5991:
URL: https://github.com/apache/incubator-nuttx/pull/5991#discussion_r844981005


##########
mm/mm_heap/mm_initialize.c:
##########
@@ -93,12 +93,17 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void 
*heapstart,
 
   DEBUGVERIFY(mm_takesemaphore(heap));
 
-  /* Adjust the provided heap start and size so that they are both aligned
-   * with the MM_MIN_CHUNK size.
+  /* Adjust the provided heap start and size.
+   *
+   * Note: (uintptr_t)node + SIZEOF_MM_ALLOCNODE is what's actually
+   * returned to the malloc user, which should have natural alignment.
+   * (that is, in this implementation, MM_MIN_CHUNK-alignment.)
    */
 
-  heapbase = MM_ALIGN_UP((uintptr_t)heapstart);
-  heapend  = MM_ALIGN_DOWN((uintptr_t)heapstart + (uintptr_t)heapsize);
+  heapbase = MM_ALIGN_UP((uintptr_t)heapstart + SIZEOF_MM_ALLOCNODE)
+             - SIZEOF_MM_ALLOCNODE;
+  heapend  = MM_ALIGN_DOWN((uintptr_t)heapstart + (uintptr_t)heapsize)

Review Comment:
   ```suggestion
     heapend  = MM_ALIGN_DOWN((uintptr_t)heapstart + (uintptr_t)heapsize) - 
SIZEOF_MM_ALLOCNODE;
   ```
   This is also a solution to make heapsize align with MM_MIN_CHUNK and it 
seems better.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to