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 <zhaoxingyu1@xiaomi.com>
This commit is contained in:
zhaoxingyu1 2025-10-17 00:46:38 +08:00 committed by GUIDINGLI
parent 8c7ca1fb0e
commit 4fb02e8766
2 changed files with 13 additions and 16 deletions

View file

@ -36,7 +36,6 @@
#include <nuttx/fs/fs.h>
#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;
}

View file

@ -41,8 +41,6 @@
#include <nuttx/fs/fs.h>
#include <nuttx/lib/lib.h>
#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; \
} \
} \