summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Kondratiev <[email protected]>2025-11-11 12:43:27 +0200
committerAnup Patel <[email protected]>2025-12-02 10:52:52 +0530
commitde376252f4f3e3df4998bd14893cb687821b4102 (patch)
tree3d55525cfa38efd83c19fb474ca3ad992090b683
parent4997eb28dab2916d7c4e8d53bfae5ec0d40a0742 (diff)
lib: sbi: Remove static variable root_memregs_count
Calculate number of used memory regions using helper function when needed. Signed-off-by: Vladimir Kondratiev <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
-rw-r--r--lib/sbi/sbi_domain.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index f31892fe..99f453f9 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -25,7 +25,6 @@ static u32 domain_count = 0;
static bool domain_finalized = false;
#define ROOT_REGION_MAX 32
-static u32 root_memregs_count = 0;
struct sbi_domain root = {
.name = "root",
@@ -368,6 +367,17 @@ static void clear_region(struct sbi_domain_memregion* reg)
sbi_memset(reg, 0x0, sizeof(*reg));
}
+static int sbi_domain_used_memregions(const struct sbi_domain *dom)
+{
+ int count = 0;
+ struct sbi_domain_memregion *reg;
+
+ sbi_domain_for_each_memregion(dom, reg)
+ count++;
+
+ return count;
+}
+
static int sanitize_domain(struct sbi_domain *dom)
{
u32 i, j, count;
@@ -406,9 +416,7 @@ static int sanitize_domain(struct sbi_domain *dom)
}
/* Count memory regions */
- count = 0;
- sbi_domain_for_each_memregion(dom, reg)
- count++;
+ count = sbi_domain_used_memregions(dom);
/* Check presence of firmware regions */
if (!dom->fw_region_inited) {
@@ -692,6 +700,7 @@ static int root_add_memregion(const struct sbi_domain_memregion *reg)
int rc;
bool reg_merged;
struct sbi_domain_memregion *nreg, *nreg1, *nreg2;
+ int root_memregs_count = sbi_domain_used_memregions(&root);
/* Sanity checks */
if (!reg || domain_finalized || !root.regions ||
@@ -862,6 +871,7 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
int rc;
struct sbi_hartmask *root_hmask;
struct sbi_domain_memregion *root_memregs;
+ int root_memregs_count = 0;
SBI_INIT_LIST_HEAD(&domain_list);