[PATCH] lib/sbi: fix covered regions handling in sanitize_domain()
Vladimir Kondratiev
vladimir.kondratiev at mobileye.com
Tue Nov 11 01:22:22 PST 2025
In the sanitize_domain, code that checks for the case when one
memory region covered by the other, was never executed. Quote:
/* Sort the memory regions */
for (i = 0; i < (count - 1); i++) {
<skip>
}
/* Remove covered regions */
while(i < (count - 1)) {
Here "while" loop never executed because condition "i < (count - 1)"
is always false after the "for" loop just above.
In addition, when clearing region, "root_memregs_count"
should be adjusted as well, otherwise code that adds memory region
in the "root_add_memregion" will use wrong position:
/* Append the memregion to root memregions */
nreg = &root.regions[root_memregs_count];
empty entry will be created in the middle of regions array, new
regions will be added after this empty entry while sanitizing code
will stop when reaching empty entry.
Fixing: commit 3b03cdd60ce5 ("lib: sbi: Add regions merging when sanitizing domain region")
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev at mobileye.com>
---
lib/sbi/sbi_domain.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index 8cf5fcfe4926..955bf59f877e 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -344,7 +344,7 @@ static int sanitize_domain(struct sbi_domain *dom)
}
/* Remove covered regions */
- while(i < (count - 1)) {
+ for (i = 0; i < (count - 1);) {
is_covered = false;
reg = &dom->regions[i];
@@ -364,6 +364,7 @@ static int sanitize_domain(struct sbi_domain *dom)
&dom->regions[j + 1]);
clear_region(&dom->regions[count - 1]);
count--;
+ root_memregs_count--;
} else
i++;
}
--
2.43.0
More information about the opensbi
mailing list