mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 14:53:47 +08:00
mm/mempool: Avoid the allocation number of expend block equals zero
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
225d347306
commit
1d5ca4e809
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user