mm/mm_heap: remove the unnecessary check for memory node size

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-01-27 12:17:20 +08:00 committed by Xiang Xiao
parent b95022f8de
commit 39eaeefb78
2 changed files with 17 additions and 29 deletions

View File

@ -29,6 +29,7 @@
#include <nuttx/fs/procfs.h>
#include <assert.h>
#include <sys/types.h>
#include <stdbool.h>
#include <string.h>
@ -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

View File

@ -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);