From 4997eb28dab2916d7c4e8d53bfae5ec0d40a0742 Mon Sep 17 00:00:00 2001 From: Vladimir Kondratiev Date: Tue, 11 Nov 2025 12:43:26 +0200 Subject: [PATCH] lib: sbi: fix covered regions handling in sanitize_domain() 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++) { } /* 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. Fixes: 3b03cdd60ce5 ("lib: sbi: Add regions merging when sanitizing domain region") Signed-off-by: Vladimir Kondratiev Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20251111104327.1170919-2-vladimir.kondratiev@mobileye.com Signed-off-by: Anup Patel --- lib/sbi/sbi_domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index da0f0557..f31892fe 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -431,7 +431,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];