From d8b51ea9cd3a2c89c93cdfc2bc69d598ded2be69 Mon Sep 17 00:00:00 2001 From: Ioannis Glaropoulos Date: Tue, 13 Nov 2018 18:00:25 +0100 Subject: [PATCH] kernel: mem_domain: optimize sane partition checking This commit optimizes the process of checking that the added partitions in a mem_domain are sane. It places the sane_partition checking inside the loop of adding the partitions in the mem_domain, so that the checkings are not performed twice, and no partition is checked against itself. Signed-off-by: Ioannis Glaropoulos --- kernel/mem_domain.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/kernel/mem_domain.c b/kernel/mem_domain.c index b38eda01f44..33f369a047c 100644 --- a/kernel/mem_domain.c +++ b/kernel/mem_domain.c @@ -81,7 +81,7 @@ void k_mem_domain_init(struct k_mem_domain *domain, u8_t num_parts, key = irq_lock(); - domain->num_partitions = num_parts; + domain->num_partitions = 0; (void)memset(domain->partitions, 0, sizeof(domain->partitions)); if (num_parts) { @@ -92,16 +92,14 @@ void k_mem_domain_init(struct k_mem_domain *domain, u8_t num_parts, __ASSERT((parts[i]->start + parts[i]->size) > parts[i]->start, ""); - domain->partitions[i] = *parts[i]; - } - #if defined(CONFIG_EXECUTE_XOR_WRITE) - for (i = 0; i < num_parts; i++) { __ASSERT(sane_partition_domain(domain, - &domain->partitions[i]), + parts[i]), ""); - } #endif + domain->partitions[i] = *parts[i]; + domain->num_partitions++; + } } sys_dlist_init(&domain->mem_domain_q);