[PATCH 4/6] of: warn about of_add_memory_bank errors

Ahmad Fatoum a.fatoum at pengutronix.de
Mon May 31 00:12:37 PDT 2021


Now that errors from of_probe are propagated to the respective initcalls
registering the device tree, propagate of_add_memory_bank errors as
well. This ensures that clashes of device-tree added regions with
previous ones don't go unnoticed. This can e.g. be the case if a device
tree happens to have both /memory at X { }; and /memory { }; nodes.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/mips/boot/dtb.c     |  9 ++++++---
 drivers/of/base.c        | 24 ++++++++++++++++++------
 drivers/of/mem_generic.c |  5 +++--
 include/of.h             |  2 +-
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/arch/mips/boot/dtb.c b/arch/mips/boot/dtb.c
index dbb6315d1f05..ece1494e5fdf 100644
--- a/arch/mips/boot/dtb.c
+++ b/arch/mips/boot/dtb.c
@@ -14,21 +14,24 @@
 void *glob_fdt;
 u32 glob_fdt_size;
 
-void of_add_memory_bank(struct device_node *node, bool dump, int r,
+int of_add_memory_bank(struct device_node *node, bool dump, int r,
 		u64 base, u64 size)
 {
 	static char str[12];
+	int ret;
 
 	if (IS_ENABLED(CONFIG_MMU)) {
 		sprintf(str, "kseg0_ram%d", r);
-		barebox_add_memory_bank(str, CKSEG0 | base, size);
+		ret = barebox_add_memory_bank(str, CKSEG0 | base, size);
 	} else {
 		sprintf(str, "kseg1_ram%d", r);
-		barebox_add_memory_bank(str, CKSEG1 | base, size);
+		ret = barebox_add_memory_bank(str, CKSEG1 | base, size);
 	}
 
 	if (dump)
 		pr_info("%s: %s: 0x%llx at 0x%llx\n", node->name, str, size, base);
+
+	return ret;
 }
 
 extern char __dtb_start[];
diff --git a/drivers/of/base.c b/drivers/of/base.c
index b99201a50fd5..17f58dba233e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2248,6 +2248,7 @@ int of_add_memory(struct device_node *node, bool dump)
 		return -ENXIO;
 
 	while (!of_address_to_resource(node, n, &res)) {
+		int err;
 		n++;
 		if (!resource_size(&res))
 			continue;
@@ -2255,12 +2256,15 @@ int of_add_memory(struct device_node *node, bool dump)
 		if (!of_device_is_available(node))
 			continue;
 
-		of_add_memory_bank(node, dump, mem_bank_num,
+		err = of_add_memory_bank(node, dump, mem_bank_num,
 				res.start, resource_size(&res));
+		if (err)
+			ret = err;
+
 		mem_bank_num++;
 	}
 
-	return 0;
+	return ret;
 }
 
 static struct device_node *of_chosen;
@@ -2283,18 +2287,25 @@ const struct of_device_id of_default_bus_match_table[] = {
 	}
 };
 
-static void of_probe_memory(void)
+static int of_probe_memory(void)
 {
 	struct device_node *memory = root_node;
+	int ret = 0;
 
 	/* Parse all available node with "memory" device_type */
 	while (1) {
+		int err;
+
 		memory = of_find_node_by_type(memory, "memory");
 		if (!memory)
 			break;
 
-		of_add_memory(memory, false);
+		err = of_add_memory(memory, false);
+		if (err)
+			ret = err;
 	}
+
+	return ret;
 }
 
 static void of_platform_device_create_root(struct device_node *np)
@@ -2315,6 +2326,7 @@ static void of_platform_device_create_root(struct device_node *np)
 int of_probe(void)
 {
 	struct device_node *firmware;
+	int ret;
 
 	if(!root_node)
 		return -ENODEV;
@@ -2325,7 +2337,7 @@ int of_probe(void)
 	if (of_model)
 		barebox_set_model(of_model);
 
-	of_probe_memory();
+	ret = of_probe_memory();
 
 	firmware = of_find_node_by_path("/firmware");
 	if (firmware)
@@ -2336,7 +2348,7 @@ int of_probe(void)
 	of_clk_init(root_node, NULL);
 	of_platform_populate(root_node, of_default_bus_match_table, NULL);
 
-	return 0;
+	return ret;
 }
 
 /**
diff --git a/drivers/of/mem_generic.c b/drivers/of/mem_generic.c
index 9094243c0400..55d93bcb06a8 100644
--- a/drivers/of/mem_generic.c
+++ b/drivers/of/mem_generic.c
@@ -2,14 +2,15 @@
 #include <of.h>
 #include <memory.h>
 
-void of_add_memory_bank(struct device_node *node, bool dump, int r,
+int of_add_memory_bank(struct device_node *node, bool dump, int r,
 		u64 base, u64 size)
 {
 	static char str[6];
 
 	sprintf(str, "ram%d", r);
-	barebox_add_memory_bank(str, base, size);
 
 	if (dump)
 		pr_info("%s: %s: 0x%llx at 0x%llx\n", node->name, str, size, base);
+
+	return barebox_add_memory_bank(str, base, size);
 }
diff --git a/include/of.h b/include/of.h
index 66d1edcc5c0d..c8ebf4009921 100644
--- a/include/of.h
+++ b/include/of.h
@@ -283,7 +283,7 @@ int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
 void *of_flatten_dtb(struct device_node *node);
 int of_add_memory(struct device_node *node, bool dump);
-void of_add_memory_bank(struct device_node *node, bool dump, int r,
+int of_add_memory_bank(struct device_node *node, bool dump, int r,
 		u64 base, u64 size);
 struct device_d *of_find_device_by_node_path(const char *path);
 #define OF_FIND_PATH_FLAGS_BB 1		/* return .bb device if available */
-- 
2.29.2




More information about the barebox mailing list