You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2021/07/04 22:39:32 UTC

[incubator-nuttx] branch master updated: mm: Call memalign in malloc if ARCH_ADDRENV and BUILD_KERNEL are defined

This is an automated email from the ASF dual-hosted git repository.

masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 7b20a0d  mm: Call memalign in malloc if ARCH_ADDRENV and BUILD_KERNEL are defined
7b20a0d is described below

commit 7b20a0d789cf275da14795829a2314381615aedc
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jul 4 01:34:13 2021 +0800

    mm: Call memalign in malloc if ARCH_ADDRENV and BUILD_KERNEL are defined
    
    to reuse the sbrk logic inside memalign
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 mm/umm_heap/umm_malloc.c | 37 ++++---------------------------------
 1 file changed, 4 insertions(+), 33 deletions(-)

diff --git a/mm/umm_heap/umm_malloc.c b/mm/umm_heap/umm_malloc.c
index b2a055c..1906eb1 100644
--- a/mm/umm_heap/umm_malloc.c
+++ b/mm/umm_heap/umm_malloc.c
@@ -52,41 +52,12 @@
 FAR void *malloc(size_t size)
 {
 #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
-  FAR void *brkaddr;
-  FAR void *mem;
+  /* Use memalign() because it implements the sbrk() logic */
 
-  if (size < 1)
-    {
-      return NULL;
-    }
-
-  /* Loop until we successfully allocate the memory or until an error
-   * occurs. If we fail to allocate memory on the first pass, then call
-   * sbrk to extend the heap by one page.  This may require several
-   * passes if more the size of the allocation is more than one page.
-   *
-   * An alternative would be to increase the size of the heap by the
-   * full requested allocation in sbrk().  Then the loop should never
-   * execute more than twice (but more memory than we need may be
-   * allocated).
-   */
-
-  do
-    {
-      mem = mm_malloc(USR_HEAP, size);
-      if (!mem)
-        {
-          brkaddr = sbrk(size);
-          if (brkaddr == (FAR void *)-1)
-            {
-              return NULL;
-            }
-        }
-    }
-  while (mem == NULL);
-
-  return mem;
+  return memalign(sizeof(FAR void *), size);
 #else
+  /* Use mm_malloc() because it implements the clear */
+
   return mm_malloc(USR_HEAP, size);
 #endif
 }