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

xiaoxiang 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 083027b9dc binfmt/loadable: move binary_s to stack to avoid access 
allocator
083027b9dc is described below

commit 083027b9dc4769b5d44a1b28158c4786e54c196f
Author: chao an <[email protected]>
AuthorDate: Wed Dec 11 08:57:54 2024 +0800

    binfmt/loadable: move binary_s to stack to avoid access allocator
    
    Improve performance by reducing allocator accesses
    
    Signed-off-by: chao an <[email protected]>
---
 binfmt/binfmt_exec.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/binfmt/binfmt_exec.c b/binfmt/binfmt_exec.c
index f607dc45b5..6ffc535a3f 100644
--- a/binfmt/binfmt_exec.c
+++ b/binfmt/binfmt_exec.c
@@ -84,16 +84,22 @@ static int exec_internal(FAR const char *filename,
   irqstate_t flags;
   int pid;
   int ret;
+#ifndef CONFIG_BINFMT_LOADABLE
+  struct binary_s sbin;
+
+  bin = &sbin;
+#else
 
   /* Allocate the load information */
 
   bin = kmm_zalloc(sizeof(struct binary_s));
-  if (!bin)
+  if (bin == NULL)
     {
       berr("ERROR: Failed to allocate binary_s\n");
       ret = -ENOMEM;
       goto errout;
     }
+#endif
 
   /* Load the module into memory */
 
@@ -154,15 +160,9 @@ static int exec_internal(FAR const char *filename,
   if (ret < 0)
     {
       berr("ERROR: Failed to schedule unload '%s': %d\n", filename, ret);
+      goto errout_with_lock;
     }
 
-#else
-  /* Free the binary_s structure here */
-
-  kmm_free(bin);
-
-  /* TODO: How does the module get unloaded in this case? */
-
 #endif
 
   sched_unlock();
@@ -174,8 +174,10 @@ errout_with_lock:
   leave_critical_section(flags);
   unload_module(bin);
 errout_with_bin:
+#ifdef CONFIG_BINFMT_LOADABLE
   kmm_free(bin);
 errout:
+#endif
   return ret;
 }
 

Reply via email to