You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2023/06/17 22:11:13 UTC
[nuttx] 01/02: mm/mempool: Avoid the allocation number of expend block equals zero
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 1d5ca4e809c31c448a475763f40219e8834b00ba
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun May 28 23:54:01 2023 +0800
mm/mempool: Avoid the allocation number of expend block equals zero
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
mm/mempool/mempool.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c
index 76a00034f8..6a4e2fc330 100644
--- a/mm/mempool/mempool.c
+++ b/mm/mempool/mempool.c
@@ -163,7 +163,7 @@ int mempool_init(FAR struct mempool_s *pool, FAR const char *name)
pool->ibase = NULL;
}
- if (pool->initialsize > sizeof(sq_entry_t))
+ if (pool->initialsize >= blocksize + sizeof(sq_entry_t))
{
size_t ninitial = (pool->initialsize - sizeof(sq_entry_t)) / blocksize;
size_t size = ninitial * blocksize + sizeof(sq_entry_t);
@@ -239,10 +239,11 @@ retry:
}
else
{
+ size_t blocksize = MEMPOOL_REALBLOCKSIZE(pool);
+
spin_unlock_irqrestore(&pool->lock, flags);
- if (pool->expandsize > sizeof(sq_entry_t))
+ if (pool->expandsize >= blocksize + sizeof(sq_entry_t))
{
- size_t blocksize = MEMPOOL_REALBLOCKSIZE(pool);
size_t nexpand = (pool->expandsize - sizeof(sq_entry_t)) /
blocksize;
size_t size = nexpand * blocksize + sizeof(sq_entry_t);
@@ -545,14 +546,14 @@ int mempool_deinit(FAR struct mempool_s *pool)
return -EBUSY;
}
- if (pool->initialsize > sizeof(sq_entry_t))
+ if (pool->initialsize >= blocksize + sizeof(sq_entry_t))
{
count = (pool->initialsize - sizeof(sq_entry_t)) / blocksize;
}
if (count == 0)
{
- if (pool->expandsize > sizeof(sq_entry_t))
+ if (pool->expandsize >= blocksize + sizeof(sq_entry_t))
{
count = (pool->expandsize - sizeof(sq_entry_t)) / blocksize;
}
@@ -566,7 +567,7 @@ int mempool_deinit(FAR struct mempool_s *pool)
{
blk = (FAR sq_entry_t *)((FAR char *)blk - count * blocksize);
pool->free(pool, blk);
- if (pool->expandsize > sizeof(sq_entry_t))
+ if (pool->expandsize >= blocksize + sizeof(sq_entry_t))
{
count = (pool->expandsize - sizeof(sq_entry_t)) / blocksize;
}