From 4fb02e8766dfce23cd1a7194724eda978e4cdfbe Mon Sep 17 00:00:00 2001 From: zhaoxingyu1 Date: Fri, 17 Oct 2025 00:46:38 +0800 Subject: [PATCH] fs/inode: change fs_heap to lib_get_tempbuffer/lib_put_tempbuffer Replace the fs_heap_asprintf()/fs_heap_free() based allocation of the path buffer in the inode search with the lib_get_tempbuffer()/ lib_put_tempbuffer() pool. Fixed PATH_MAX sized temporary buffers avoid per-call heap allocation and keep the buffer allocator consistent with the rest of the path-resolution code. Signed-off-by: zhaoxingyu1 --- fs/inode/fs_inodesearch.c | 25 ++++++++++++------------- fs/inode/inode.h | 4 +--- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/fs/inode/fs_inodesearch.c b/fs/inode/fs_inodesearch.c index fd8b147bb6a..fa02871984e 100644 --- a/fs/inode/fs_inodesearch.c +++ b/fs/inode/fs_inodesearch.c @@ -36,7 +36,6 @@ #include #include "inode/inode.h" -#include "fs_heap.h" /**************************************************************************** * Private Function Prototypes @@ -351,19 +350,19 @@ static int _inode_search(FAR struct inode_search_s *desc) { FAR char *buffer = NULL; - ret = fs_heap_asprintf(&buffer, "%s/%s", - desc->relpath, - name); - if (ret > 0) + buffer = lib_get_tempbuffer(PATH_MAX); + if (buffer == NULL) { - fs_heap_free(desc->buffer); - desc->buffer = buffer; - relpath = buffer; - ret = OK; + ret = -ENOMEM; } else { - ret = -ENOMEM; + snprintf(buffer, PATH_MAX, "%s/%s", + desc->relpath, name); + lib_put_tempbuffer(desc->buffer); + desc->buffer = buffer; + relpath = buffer; + ret = OK; } } else @@ -493,13 +492,13 @@ int inode_search(FAR struct inode_search_s *desc) if (*desc->path != '/') { - ret = fs_heap_asprintf(&desc->buffer, "%s/%s", - _inode_getcwd(), desc->path); - if (ret < 0) + desc->buffer = lib_get_tempbuffer(PATH_MAX); + if (desc->buffer == NULL) { return -ENOMEM; } + snprintf(desc->buffer, PATH_MAX, "%s/%s", _inode_getcwd(), desc->path); desc->path = desc->buffer; } diff --git a/fs/inode/inode.h b/fs/inode/inode.h index 08fc7632510..79a241e6dcc 100644 --- a/fs/inode/inode.h +++ b/fs/inode/inode.h @@ -41,8 +41,6 @@ #include #include -#include "fs_heap.h" - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -65,7 +63,7 @@ { \ if ((d)->buffer != NULL) \ { \ - fs_heap_free((d)->buffer); \ + lib_put_tempbuffer((d)->buffer); \ (d)->buffer = NULL; \ } \ } \