You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/04/06 12:23:16 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #5991: mm: fix memory alignment

pkarashchenko commented on code in PR #5991:
URL: https://github.com/apache/incubator-nuttx/pull/5991#discussion_r843879267


##########
mm/mm_heap/mm_memalign.c:
##########
@@ -52,6 +52,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
                       size_t size)
 {
   FAR struct mm_allocnode_s *node;
+  FAR void *ptr;

Review Comment:
   ```suggestion
   ```



##########
mm/mm_heap/mm_memalign.c:
##########
@@ -227,5 +230,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
   kasan_unpoison((FAR void *)alignedchunk,
                  mm_malloc_size((FAR void *)alignedchunk));
 
-  return (FAR void *)alignedchunk;
+  ptr = (FAR void *)alignedchunk;
+  DEBUGASSERT(ptr == NULL || ((uintptr_t)ptr) % alignment == 0);
+  return ptr;

Review Comment:
   Maybe just
   ```suggestion
     DEBUGASSERT(alignedchunk % alignment == 0);
     return (FAR void *)alignedchunk;
   ```
   to reduce number of lines in the PR.



##########
mm/mm_heap/mm_memalign.c:
##########
@@ -78,7 +79,9 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
 
   if (alignment <= MM_MIN_CHUNK)
     {
-      return mm_malloc(heap, size);
+      ptr = mm_malloc(heap, size);
+      DEBUGASSERT(ptr == NULL || ((uintptr_t)ptr) % alignment == 0);
+      return ptr;

Review Comment:
   ```suggestion
         alignedchunk = (size_t)mm_malloc(heap, size);
         DEBUGASSERT(alignedchunk % alignment == 0);
         return (FAR void *)alignedchunk;
   ```



##########
mm/mm_heap/mm_malloc.c:
##########
@@ -256,5 +256,6 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
     }
 #endif
 
+  DEBUGASSERT(ret == NULL || ((uintptr_t)ret) % MM_MIN_CHUNK == 0);

Review Comment:
   ```suggestion
     DEBUGASSERT(((uintptr_t)ret) % MM_MIN_CHUNK == 0);
   ```



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org