This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit af5e87f5e938be79128064d26e6271d8e769c705 Author: zhanghongyu <[email protected]> AuthorDate: Fri Nov 21 13:07:20 2025 +0800 mm/mempool: add mempool_zallocate interface mempool_zallocate() allocates a block like mempool_allocate() and clears its pool->blocksize bytes, for callers that need a zeroed block. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: zhanghongyu <[email protected]> --- include/nuttx/mm/mempool.h | 23 +++++++++++++++++++++++ mm/mempool/mempool.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/nuttx/mm/mempool.h b/include/nuttx/mm/mempool.h index fb0215dd850..8304980d953 100644 --- a/include/nuttx/mm/mempool.h +++ b/include/nuttx/mm/mempool.h @@ -227,6 +227,29 @@ int mempool_init(FAR struct mempool_s *pool); FAR void *mempool_allocate(FAR struct mempool_s *pool, unsigned int timeout); +/**************************************************************************** + * Name: mempool_zallocate + * + * Description: + * Allocate an block from a specific memory pool and zero the allocated + * block. + * + * If there isn't enough memory blocks, This function will expand memory + * pool if expandsize isn't zero. + * + * Input Parameters: + * pool - Address of the memory pool to be used. + * timeout - The maximum time (ms) to wait for a buffer to become + * available. + * + * Returned Value: + * The pointer to the allocated block on success; NULL on any failure. + * + ****************************************************************************/ + +FAR void *mempool_zallocate(FAR struct mempool_s *pool, + unsigned int timeout); + /**************************************************************************** * Name: mempool_release * diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c index 05ae831e693..273196bd3d7 100644 --- a/mm/mempool/mempool.c +++ b/mm/mempool/mempool.c @@ -554,6 +554,37 @@ retry: return blk; } +/**************************************************************************** + * Name: mempool_zallocate + * + * Description: + * Allocate an block from a specific memory pool and zero the allocated + * block. + * + * If there isn't enough memory blocks, This function will expand memory + * pool if expandsize isn't zero. + * + * Input Parameters: + * pool - Address of the memory pool to be used. + * timeout - The maximum time (ms) to wait for a buffer to become + * available. + * + * Returned Value: + * The pointer to the allocated block on success; NULL on any failure. + * + ****************************************************************************/ + +FAR void *mempool_zallocate(FAR struct mempool_s *pool, unsigned int timeout) +{ + FAR void *blk = mempool_allocate(pool, timeout); + if (blk != NULL) + { + memset(blk, 0, pool->blocksize); + } + + return blk; +} + /**************************************************************************** * Name: mempool_release *
