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
+20 -51
View File
@@ -34,50 +34,12 @@
#include "mm_heap/mm.h" #include "mm_heap/mm.h"
/**************************************************************************** /****************************************************************************
* Public Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/**************************************************************************** static void checkcorruption_handler(FAR struct mm_allocnode_s *node,
* Name: mm_checkcorruption FAR void *arg)
*
* 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))
{
if ((node->preceding & MM_ALLOC_BIT) != 0) if ((node->preceding & MM_ALLOC_BIT) != 0)
{ {
assert(node->size >= SIZEOF_MM_ALLOCNODE); assert(node->size >= SIZEOF_MM_ALLOCNODE);
@@ -95,14 +57,21 @@ void mm_checkcorruption(FAR struct mm_heap_s *heap)
fnode->flink->size == 0 || fnode->flink->size == 0 ||
fnode->flink->size >= fnode->size); fnode->flink->size >= fnode->size);
} }
}
assert(prev == NULL ||
prev->size == (node->preceding & ~MM_ALLOC_BIT)); /****************************************************************************
prev = node; * Public Functions
} ****************************************************************************/
assert(node == heap->mm_heapend[region]); /****************************************************************************
* Name: mm_checkcorruption
mm_givesemaphore(heap); *
} * 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);
} }