summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)