[PATCH v2 1/3] lib: sbi: separate the swap operation of domain region
Inochi Amaoto
inochiama at outlook.com
Mon Oct 9 18:00:23 PDT 2023
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 <inochiama at outlook.com>
---
lib/sbi/sbi_domain.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index fd4a296..283b598 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -256,11 +256,21 @@ 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(const struct sbi_platform *plat,
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) {
@@ -324,9 +334,7 @@ static int sanitize_domain(const struct sbi_platform *plat,
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);
}
}
--
2.42.0
More information about the opensbi
mailing list