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

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


The following commit(s) were added to refs/heads/master by this push:
     new f231a24ae3a mm: replace mm_heap_config_s.heap with an allocheap flag
f231a24ae3a is described below

commit f231a24ae3a8c3ccb2e3503b1d344b5b201f4137
Author: Bowen Wang <[email protected]>
AuthorDate: Fri Jun 13 15:59:16 2025 +0800

    mm: replace mm_heap_config_s.heap with an allocheap flag
    
    When mm_heap_config_s.heap is set, mm_initialize_heap() allocates the
    struct mm_heap_s from that heap with mm_malloc()/mm_memalign().  With
    CONFIG_MM_UMM_CUSTOMIZE_MANAGER (e.g. sim), the user heap is managed
    by sim_ummheap and is not a struct mm_heap_s, so the caller cannot
    pass a usable heap pointer here.
    
    Replace the heap pointer with a bool allocheap and allocate the heap
    struct with lib_memalign(), which picks kmm_memalign() or memalign()
    depending on the build.  Drop KRN_HEAP, whose only user was rptun.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rptun/rptun.c      | 10 +++++-----
 include/nuttx/mm/mm.h      | 16 +++++++---------
 mm/mm_heap/mm_initialize.c |  7 ++++---
 mm/tlsf/mm_tlsf.c          |  7 ++++---
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c
index 4ef8e01a8aa..6823a8cec4d 100644
--- a/drivers/rptun/rptun.c
+++ b/drivers/rptun/rptun.c
@@ -495,11 +495,11 @@ static int rptun_init_carveout(FAR struct rptun_priv_s 
*priv,
   if (carveout != NULL)
     {
       memset(&config, 0, sizeof(config));
-      config.heap    = KRN_HEAP;
-      config.name    = shmname;
-      config.start   = shmbase;
-      config.size    = shmlen;
-      config.nokasan = true;
+      config.name      = shmname;
+      config.start     = shmbase;
+      config.size      = shmlen;
+      config.nokasan   = true;
+      config.allocheap = true;
 
       carveout->base = shmbase;
       carveout->size = shmlen;
diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h
index 15371798ffe..2c66e55a83b 100644
--- a/include/nuttx/mm/mm.h
+++ b/include/nuttx/mm/mm.h
@@ -142,14 +142,12 @@
  */
 
 #ifdef CONFIG_MM_KERNEL_HEAP
-#  define KRN_HEAP               g_kmmheap
 #  if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
 #    define MM_INTERNAL_HEAP(heap) ((heap) == g_kmmheap)
 #  else
 #    define MM_INTERNAL_HEAP(heap) ((heap) == USR_HEAP || (heap) == g_kmmheap)
 #  endif
 #else
-#  define KRN_HEAP               USR_HEAP
 #  if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
 #    define MM_INTERNAL_HEAP(heap) 0
 #  else
@@ -203,16 +201,16 @@ struct mm_heap_s; /* Forward reference */
 
 struct mm_heap_config_s
 {
-  /* If heap == NULL, means use the heap memory ([start, start + size])
+  /* If allocheap == false, means use the heap memory ([start, start + size])
    * to construct the heap struct.
-   * If heap != NULL, means malloc struct mm_heap_s from this heap.
+   * If allocheap == true, means malloc struct mm_heap_s from this heap.
    */
 
-  FAR struct mm_heap_s *heap;
-  FAR const char       *name;
-  FAR void             *start;
-  size_t                size;
-  bool                  nokasan;
+  FAR const char *name;
+  FAR void       *start;
+  size_t          size;
+  bool            nokasan;
+  bool            allocheap;
 };
 
 struct mempool_init_s
diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c
index 6bb815dcd2e..9d79bd7f81a 100644
--- a/mm/mm_heap/mm_initialize.c
+++ b/mm/mm_heap/mm_initialize.c
@@ -30,6 +30,7 @@
 #include <assert.h>
 #include <nuttx/debug.h>
 
+#include <nuttx/lib/lib.h>
 #include <nuttx/sched_note.h>
 #include <nuttx/mm/mm.h>
 #include <nuttx/mm/kasan.h>
@@ -240,14 +241,14 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void 
*heapstart,
 FAR struct mm_heap_s *
 mm_initialize_heap(FAR const struct mm_heap_config_s *config)
 {
-  FAR struct mm_heap_s *heap = config->heap;
+  FAR struct mm_heap_s *heap;
   FAR const char *name = config->name;
   FAR void *heapstart = config->start;
   size_t heapsize = config->size;
   int i;
 
   minfo("Heap: name=%s, start=%p size=%zu\n", name, heapstart, heapsize);
-  if (heap == NULL)
+  if (!config->allocheap)
     {
       /* First ensure the memory to be used is aligned */
 
@@ -266,7 +267,7 @@ mm_initialize_heap(FAR const struct mm_heap_config_s 
*config)
     }
   else
     {
-      heap = mm_malloc(heap, sizeof(struct mm_heap_s));
+      heap = lib_memalign(MM_ALIGN, sizeof(struct mm_heap_s));
       if (heap == NULL)
         {
           return NULL;
diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c
index cd82f180a97..6b5c5da23d3 100644
--- a/mm/tlsf/mm_tlsf.c
+++ b/mm/tlsf/mm_tlsf.c
@@ -38,6 +38,7 @@
 
 #include <nuttx/arch.h>
 #include <nuttx/fs/procfs.h>
+#include <nuttx/lib/lib.h>
 #include <nuttx/mutex.h>
 #include <nuttx/mm/mm.h>
 #include <nuttx/mm/kasan.h>
@@ -1021,13 +1022,13 @@ bool mm_heapmember(FAR struct mm_heap_s *heap, FAR void 
*mem)
 FAR struct mm_heap_s *
 mm_initialize_heap(FAR const struct mm_heap_config_s *config)
 {
-  FAR struct mm_heap_s *heap = config->heap;
+  FAR struct mm_heap_s *heap;
   FAR const char *name = config->name;
   FAR void *heapstart = config->start;
   size_t heapsize = config->size;
 
   minfo("Heap: name=%s start=%p size=%zu\n", name, heapstart, heapsize);
-  if (heap == NULL)
+  if (!config->allocheap)
     {
       /* Reserve a block space for mm_heap_s context */
 
@@ -1041,7 +1042,7 @@ mm_initialize_heap(FAR const struct mm_heap_config_s 
*config)
     }
   else
     {
-      heap = mm_memalign(heap, MM_ALIGN, sizeof(struct mm_heap_s));
+      heap = lib_memalign(MM_ALIGN, sizeof(struct mm_heap_s));
       if (heap == NULL)
         {
           return NULL;

Reply via email to