mm/mm_checkcorruption: using mm_foreach to do mm_checkcorruption

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-01-24 20:15:20 +08:00 committed by Xiang Xiao
parent eba0323eae
commit b1a51a5b30

View File

@ -34,49 +34,11 @@
#include "mm_heap/mm.h"
/****************************************************************************
* Public Functions
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: mm_checkcorruption
*
* Description:
* mm_checkcorruption is used to check whether memory heap is normal.
*
****************************************************************************/
void mm_checkcorruption(FAR struct mm_heap_s *heap)
{
FAR struct mm_allocnode_s *node;
FAR struct mm_allocnode_s *prev;
#if CONFIG_MM_REGIONS > 1
int region;
#else
# define region 0
#endif
/* Visit each region */
#if CONFIG_MM_REGIONS > 1
for (region = 0; region < heap->mm_nregions; region++)
#endif
{
prev = NULL;
/* Visit each node in the region
* Retake the semaphore for each region to reduce latencies
*/
if (mm_takesemaphore(heap) == false)
{
return;
}
for (node = heap->mm_heapstart[region];
node < heap->mm_heapend[region];
node = (FAR struct mm_allocnode_s *)
((FAR char *)node + node->size))
static void checkcorruption_handler(FAR struct mm_allocnode_s *node,
FAR void *arg)
{
if ((node->preceding & MM_ALLOC_BIT) != 0)
{
@ -95,14 +57,21 @@ void mm_checkcorruption(FAR struct mm_heap_s *heap)
fnode->flink->size == 0 ||
fnode->flink->size >= fnode->size);
}
assert(prev == NULL ||
prev->size == (node->preceding & ~MM_ALLOC_BIT));
prev = node;
}
assert(node == heap->mm_heapend[region]);
/****************************************************************************
* Public Functions
****************************************************************************/
mm_givesemaphore(heap);
}
/****************************************************************************
* Name: mm_checkcorruption
*
* Description:
* mm_checkcorruption is used to check whether memory heap is normal.
*
****************************************************************************/
void mm_checkcorruption(FAR struct mm_heap_s *heap)
{
mm_foreach(heap, checkcorruption_handler, NULL);
}