[Skiboot] [RFC, PATCH 2/4] core/mem_region: Move reserved-ranges parsing into a separate function

Jeremy Kerr jk at ozlabs.org
Mon Jul 20 19:01:41 AEST 2015


This change moves the property-style reserved-memory parsing code to a
separate function.

We no longer need to defer the dt_del_property() calls, so we can
include them in the function, before dropping the mem_region_lock.

Signed-off-by: Jeremy Kerr <jk at ozlabs.org>

---
 core/mem_region.c |   76 +++++++++++++++++++++++++---------------------
 1 file changed, 42 insertions(+), 34 deletions(-)

diff --git a/core/mem_region.c b/core/mem_region.c
index 48fdd7d..fede263 100644
--- a/core/mem_region.c
+++ b/core/mem_region.c
@@ -798,10 +798,50 @@ void adjust_cpu_stacks_alloc(void)
 	skiboot_cpu_stacks.len = (cpu_max_pir + 1) * STACK_SIZE;
 }
 
+static void mem_region_parse_reserved_properties(void)
+{
+	const struct dt_property *names, *ranges;
+	struct mem_region *region;
+
+	names = dt_find_property(dt_root, "reserved-names");
+	ranges = dt_find_property(dt_root, "reserved-ranges");
+	if (names && ranges) {
+		const uint64_t *range;
+		int n, len;
+
+		range = (const void *)ranges->prop;
+
+		for (n = 0; n < names->len; n += len, range += 2) {
+			char *name;
+
+			len = strlen(names->prop + n) + 1;
+			name = strdup(names->prop + n);
+
+			region = new_region(name,
+					dt_get_number(range, 2),
+					dt_get_number(range + 1, 2),
+					NULL, REGION_HW_RESERVED);
+			list_add(&regions, &region->list);
+		}
+	} else if (names || ranges) {
+		prerror("Invalid properties: reserved-names=%p "
+				"with reserved-ranges=%p\n",
+				names, ranges);
+		abort();
+	} else {
+		return;
+	}
+
+	/* We generate the reservation properties from our own region list,
+	 * which now includes the existing data.
+	 */
+	dt_del_property(dt_root, (struct dt_property *)names);
+	dt_del_property(dt_root, (struct dt_property *)ranges);
+}
+
 /* Trawl through device tree, create memory regions from nodes. */
 void mem_region_init(void)
 {
-	const struct dt_property *names, *ranges;
 	struct mem_region *region;
 	struct dt_node *i;
 
@@ -861,42 +901,10 @@ void mem_region_init(void)
 	}
 
 	/* Add reserved ranges from the DT */
-	names = dt_find_property(dt_root, "reserved-names");
-	ranges = dt_find_property(dt_root, "reserved-ranges");
-	if (names && ranges) {
-		const uint64_t *range;
-		int n, len;
-
-		range = (const void *)ranges->prop;
-
-		for (n = 0; n < names->len; n += len, range += 2) {
-			char *name;
-
-			len = strlen(names->prop + n) + 1;
-			name = strdup(names->prop + n);
-
-			region = new_region(name,
-					dt_get_number(range, 2),
-					dt_get_number(range + 1, 2),
-					NULL, REGION_HW_RESERVED);
-			list_add(&regions, &region->list);
-		}
-	} else if (names || ranges) {
-		prerror("Invalid properties: reserved-names=%p "
-				"with reserved-ranges=%p\n",
-				names, ranges);
-		abort();
-	}
+	mem_region_parse_reserved_properties();
 
 	unlock(&mem_region_lock);
 
-	/* We generate the reservation properties from our own region list,
-	 * which now includes the existing data.
-	 */
-	if (names)
-		dt_del_property(dt_root, (struct dt_property *)names);
-	if (ranges)
-		dt_del_property(dt_root, (struct dt_property *)ranges);
 }
 
 static uint64_t allocated_length(const struct mem_region *r)


More information about the Skiboot mailing list