summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInochi Amaoto <[email protected]>2023-11-16 18:49:38 +0800
committerAnup Patel <[email protected]>2023-11-16 20:58:56 +0530
commit5b2f55d65ac2af9a0a880665a2e9172688616755 (patch)
tree41507d7ace98cb36e50e297d3e2c694e37d2ac06
parent98bc25f181a3dbdda1c630a4473f5a5a50ac7d58 (diff)
lib: sbi: separate the swap operation of domain region
Swapping domain region is a common operation when sorting domain region, so separate it as a function to make code clean. Signed-off-by: Inochi Amaoto <[email protected]> Reviewed-by: Anup Patel <[email protected]>
-rw-r--r--lib/sbi/sbi_domain.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index 4d248d0b..71cb381f 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -256,10 +256,20 @@ static const struct sbi_domain_memregion *find_next_subset_region(
return ret;
}
+static void swap_region(struct sbi_domain_memregion* reg1,
+ struct sbi_domain_memregion* reg2)
+{
+ struct sbi_domain_memregion treg;
+
+ sbi_memcpy(&treg, reg1, sizeof(treg));
+ sbi_memcpy(reg1, reg2, sizeof(treg));
+ sbi_memcpy(reg2, &treg, sizeof(treg));
+}
+
static int sanitize_domain(struct sbi_domain *dom)
{
u32 i, j, count;
- struct sbi_domain_memregion treg, *reg, *reg1;
+ struct sbi_domain_memregion *reg, *reg1;
/* Check possible HARTs */
if (!dom->possible_harts) {
@@ -323,9 +333,7 @@ static int sanitize_domain(struct sbi_domain *dom)
if (!is_region_before(reg1, reg))
continue;
- sbi_memcpy(&treg, reg1, sizeof(treg));
- sbi_memcpy(reg1, reg, sizeof(treg));
- sbi_memcpy(reg, &treg, sizeof(treg));
+ swap_region(reg, reg1);
}
}