summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrewine <[email protected]>2022-06-07 23:57:18 +0800
committerguo <[email protected]>2022-06-22 14:11:43 +0800
commitc13b03604f4b5ac7067b0bc433ccc70b46370106 (patch)
treee0f5e71efa0928a725b4512a070e702b7884a17d
parent2c10d5ad01315275254ff59b881a8f323e2636bb (diff)
[kernel][mem.c] tighten size before check with mem_size_aligned
-rw-r--r--src/mem.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/mem.c b/src/mem.c
index 4261229256..307391cac1 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -299,6 +299,10 @@ void *rt_smem_alloc(rt_smem_t m, rt_size_t size)
/* alignment size */
size = RT_ALIGN(size, RT_ALIGN_SIZE);
+ /* every data block must be at least MIN_SIZE_ALIGNED long */
+ if (size < MIN_SIZE_ALIGNED)
+ size = MIN_SIZE_ALIGNED;
+
if (size > small_mem->mem_size_aligned)
{
RT_DEBUG_LOG(RT_DEBUG_MEM, ("no memory\n"));
@@ -306,10 +310,6 @@ void *rt_smem_alloc(rt_smem_t m, rt_size_t size)
return RT_NULL;
}
- /* every data block must be at least MIN_SIZE_ALIGNED long */
- if (size < MIN_SIZE_ALIGNED)
- size = MIN_SIZE_ALIGNED;
-
for (ptr = (rt_uint8_t *)small_mem->lfree - small_mem->heap_ptr;
ptr <= small_mem->mem_size_aligned - size;
ptr = ((struct rt_small_mem_item *)&small_mem->heap_ptr[ptr])->next)