From 08de658eb90031339c16fe97588802bea935af55 Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Wed, 28 Feb 2018 14:22:57 -0800 Subject: [PATCH] kernel: mem_domain: Use u8_t for number of partitions in struct During system initialization, the global static variable (to mem_domain.c) is initialized with the number of maximum partitions per domain. This variable is of u8_t type. Assertions throughout the code will check ranges and test for overflow by relying on implicit type conversion. Use an u8_t instead of u32_t to avoid doubts. Also, reorder the k_mem_partition struct to remove the alignment hole created by reducing sizeof(num_partitions). Signed-off-by: Leandro Pereira --- include/kernel.h | 6 +++--- kernel/mem_domain.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/kernel.h b/include/kernel.h index 43addc98841..0de24ae2968 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -4260,14 +4260,14 @@ struct k_mem_partition { /* memory domian */ struct k_mem_domain { - /* number of partitions in the domain */ - u32_t num_partitions; #ifdef CONFIG_USERSPACE /* partitions in the domain */ struct k_mem_partition partitions[CONFIG_MAX_DOMAIN_PARTITIONS]; #endif /* CONFIG_USERSPACE */ /* domain q */ sys_dlist_t mem_domain_q; + /* number of partitions in the domain */ + u8_t num_partitions; }; @@ -4282,7 +4282,7 @@ struct k_mem_domain { * if num_parts is zero. */ -extern void k_mem_domain_init(struct k_mem_domain *domain, u32_t num_parts, +extern void k_mem_domain_init(struct k_mem_domain *domain, u8_t num_parts, struct k_mem_partition *parts[]); /** * @brief Destroy a memory domain. diff --git a/kernel/mem_domain.c b/kernel/mem_domain.c index f23b058f96c..513dfe94a55 100644 --- a/kernel/mem_domain.c +++ b/kernel/mem_domain.c @@ -68,8 +68,8 @@ static inline bool sane_partition_domain(const struct k_mem_domain *domain, #define sane_partition_domain(...) (true) #endif -void k_mem_domain_init(struct k_mem_domain *domain, u32_t num_parts, - struct k_mem_partition *parts[]) +void k_mem_domain_init(struct k_mem_domain *domain, u8_t num_parts, + struct k_mem_partition *parts[]) { unsigned int key;