arch: riscv: pmp: fix return value of arch_mem_domain_partition_remove()
If no thread use this memory domain, there isn't any user PMP region translated from memory partitions in domain. In this case, memory partition removal doesn't need to remove user PMP region and arch_mem_domain_partition_remove() could just successfully return. Signed-off-by: Jim Shu <cwshu@andestech.com>
This commit is contained in:
parent
fd1e5aebc0
commit
e0329a5525
1 changed files with 22 additions and 8 deletions
|
@ -434,7 +434,7 @@ int arch_mem_domain_max_partitions_get(void)
|
|||
}
|
||||
|
||||
int arch_mem_domain_partition_remove(struct k_mem_domain *domain,
|
||||
uint32_t partition_id)
|
||||
uint32_t partition_id)
|
||||
{
|
||||
sys_dnode_t *node, *next_node;
|
||||
uint32_t index, i, num;
|
||||
|
@ -445,6 +445,18 @@ int arch_mem_domain_partition_remove(struct k_mem_domain *domain,
|
|||
ulong_t start = (ulong_t) domain->partitions[partition_id].start;
|
||||
int ret = 0;
|
||||
|
||||
node = sys_dlist_peek_head(&domain->mem_domain_q);
|
||||
if (!node) {
|
||||
/*
|
||||
* No thread use this memory domain currently, so there isn't
|
||||
* any user PMP region translated from this memory partition.
|
||||
*
|
||||
* We could do nothing and just successfully return.
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (size == 4) {
|
||||
pmp_type = PMP_NA4;
|
||||
pmp_addr = TO_PMP_ADDR(start);
|
||||
|
@ -463,14 +475,11 @@ int arch_mem_domain_partition_remove(struct k_mem_domain *domain,
|
|||
num = 1U;
|
||||
}
|
||||
|
||||
node = sys_dlist_peek_head(&domain->mem_domain_q);
|
||||
if (!node) {
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the user PMP region translated from removed
|
||||
* memory partition.
|
||||
*/
|
||||
thread = CONTAINER_OF(node, struct k_thread, mem_domain_info);
|
||||
|
||||
uchar_pmpcfg = (unsigned char *) thread->arch.u_pmpcfg;
|
||||
for (index = PMP_REGION_NUM_FOR_U_THREAD;
|
||||
index < CONFIG_PMP_SLOT;
|
||||
|
@ -487,6 +496,11 @@ int arch_mem_domain_partition_remove(struct k_mem_domain *domain,
|
|||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove the user PMP region translated from removed
|
||||
* memory partition. The removal affects all threads
|
||||
* using this memory domain.
|
||||
*/
|
||||
#if !defined(CONFIG_PMP_POWER_OF_TWO_ALIGNMENT) || defined(CONFIG_PMP_STACK_GUARD)
|
||||
if (pmp_type == PMP_TOR) {
|
||||
index--;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue