From 39eaeefb78f36724adbdc47400d6f60372b68344 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Thu, 27 Jan 2022 12:17:20 +0800 Subject: [PATCH] mm/mm_heap: remove the unnecessary check for memory node size Signed-off-by: Jiuzhu Dong --- mm/mm_heap/mm.h | 37 +++++++++++++++++-------------------- mm/mm_heap/mm_initialize.c | 9 --------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index 4726acb29b..1d7219dcaa 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -29,6 +29,7 @@ #include +#include #include #include #include @@ -103,12 +104,23 @@ #ifdef CONFIG_MM_SMALL # define MM_ALLOC_BIT 0x8000 +# define MMSIZE_MAX UINT16_MAX #else # define MM_ALLOC_BIT 0x80000000 +# define MMSIZE_MAX UINT32_MAX #endif + #define MM_IS_ALLOCATED(n) \ ((int)((FAR struct mm_allocnode_s *)(n)->preceding) < 0) +/* What is the size of the allocnode? */ + +#define SIZEOF_MM_ALLOCNODE sizeof(struct mm_allocnode_s) + +/* What is the size of the freenode? */ + +#define SIZEOF_MM_FREENODE sizeof(struct mm_freenode_s) + /**************************************************************************** * Public Types ****************************************************************************/ @@ -117,10 +129,8 @@ #ifdef CONFIG_MM_SMALL typedef uint16_t mmsize_t; -# define MMSIZE_MAX UINT16_MAX #else typedef uint32_t mmsize_t; -# define MMSIZE_MAX UINT32_MAX #endif /* This describes an allocated chunk. An allocated chunk is @@ -134,16 +144,8 @@ struct mm_allocnode_s mmsize_t preceding; /* Size of the preceding chunk */ }; -/* What is the size of the allocnode? */ - -#ifdef CONFIG_MM_SMALL -# define SIZEOF_MM_ALLOCNODE (4) -#else -# define SIZEOF_MM_ALLOCNODE (8) -#endif - -#define CHECK_ALLOCNODE_SIZE \ - DEBUGASSERT(sizeof(struct mm_allocnode_s) == SIZEOF_MM_ALLOCNODE) +static_assert(SIZEOF_MM_ALLOCNODE <= MM_MIN_CHUNK, + "Error size for struct mm_allocnode_s\n"); /* This describes a free chunk */ @@ -155,19 +157,14 @@ struct mm_freenode_s FAR struct mm_freenode_s *blink; }; +static_assert(SIZEOF_MM_FREENODE <= MM_MIN_CHUNK, + "Error size for struct mm_freenode_s\n"); + struct mm_delaynode_s { FAR struct mm_delaynode_s *flink; }; -/* What is the size of the freenode? */ - -#define MM_PTR_SIZE sizeof(FAR struct mm_freenode_s *) -#define SIZEOF_MM_FREENODE (SIZEOF_MM_ALLOCNODE + 2*MM_PTR_SIZE) - -#define CHECK_FREENODE_SIZE \ - DEBUGASSERT(sizeof(struct mm_freenode_s) == SIZEOF_MM_FREENODE) - /* This describes one heap (possibly with multiple regions) */ struct mm_heap_s diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c index 4e2a21b658..bf84db41c1 100644 --- a/mm/mm_heap/mm_initialize.c +++ b/mm/mm_heap/mm_initialize.c @@ -182,15 +182,6 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name, heapsize -= sizeof(struct mm_heap_s); heapstart = (FAR char *)heap_adj + sizeof(struct mm_heap_s); - /* The following two lines have cause problems for some older ZiLog - * compilers in the past (but not the more recent). Life is easier if we - * just the suppress them altogther for those tools. - */ - -#ifndef __ZILOG__ - CHECK_ALLOCNODE_SIZE; - CHECK_FREENODE_SIZE; -#endif DEBUGASSERT(MM_MIN_CHUNK >= SIZEOF_MM_FREENODE); DEBUGASSERT(MM_MIN_CHUNK >= SIZEOF_MM_ALLOCNODE);