mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: mol@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/6] of: warn about of_add_memory_bank errors
Date: Mon, 31 May 2021 09:12:37 +0200
Message-ID: <20210531071239.30653-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210531071239.30653-1-a.fatoum@pengutronix.de>

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@X { }; and /memory { }; nodes.

Signed-off-by: Ahmad Fatoum <a.fatoum@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@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@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-05-31  7:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-31  7:12 [PATCH 0/6] memory: fuse overlapping memory banks Ahmad Fatoum
2021-05-31  7:12 ` [PATCH 1/6] common: memory: allocate all memory devices at once Ahmad Fatoum
2021-05-31  7:12 ` [PATCH 2/6] memory: fuse overlapping memory banks Ahmad Fatoum
2021-05-31  7:12 ` [PATCH 3/6] of: propagate errors inside barebox_register_{of, fdt} into initcalls Ahmad Fatoum
2021-05-31  7:12 ` Ahmad Fatoum [this message]
2021-05-31  7:12 ` [PATCH 5/6] ARM: <asm/memory.h>: propagate error codes from arm_add_mem_device() Ahmad Fatoum
2021-05-31  7:12 ` [PATCH 6/6] ARM: report probe error at arm_add_mem_device() callsites on failure Ahmad Fatoum
2021-06-02  6:38 ` [PATCH 0/6] memory: fuse overlapping memory banks Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210531071239.30653-5-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=mol@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git