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 <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
Ioannis Glaropoulos 2018-11-13 18:00:25 +01:00 committed by Anas Nashif
commit d8b51ea9cd

View file

@ -81,7 +81,7 @@ void k_mem_domain_init(struct k_mem_domain *domain, u8_t num_parts,
key = irq_lock(); key = irq_lock();
domain->num_partitions = num_parts; domain->num_partitions = 0;
(void)memset(domain->partitions, 0, sizeof(domain->partitions)); (void)memset(domain->partitions, 0, sizeof(domain->partitions));
if (num_parts) { 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) > __ASSERT((parts[i]->start + parts[i]->size) >
parts[i]->start, ""); parts[i]->start, "");
domain->partitions[i] = *parts[i];
}
#if defined(CONFIG_EXECUTE_XOR_WRITE) #if defined(CONFIG_EXECUTE_XOR_WRITE)
for (i = 0; i < num_parts; i++) {
__ASSERT(sane_partition_domain(domain, __ASSERT(sane_partition_domain(domain,
&domain->partitions[i]), parts[i]),
""); "");
}
#endif #endif
domain->partitions[i] = *parts[i];
domain->num_partitions++;
}
} }
sys_dlist_init(&domain->mem_domain_q); sys_dlist_init(&domain->mem_domain_q);