[PATCH 1/5] memory: return error in barebox_add_memory_bank

Sascha Hauer s.hauer at pengutronix.de
Mon Oct 8 15:46:20 EDT 2012


When a memory bank is already registered, return an error code
instead of throwing a bug. This can happen if a board has registered
a memory bank and the same bank is then probed from the devicetree.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/memory.c  |    8 +++++---
 include/memory.h |    2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/common/memory.c b/common/memory.c
index 7174f14..2674002 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -113,15 +113,15 @@ void *sbrk(ptrdiff_t increment)
 
 LIST_HEAD(memory_banks);
 
-void barebox_add_memory_bank(const char *name, resource_size_t start,
+int barebox_add_memory_bank(const char *name, resource_size_t start,
 				    resource_size_t size)
 {
 	struct memory_bank *bank = xzalloc(sizeof(*bank));
 	struct device_d *dev;
 
 	bank->res = request_iomem_region(name, start, start + size - 1);
-
-	BUG_ON(!bank->res);
+	if (!bank->res)
+		return -EBUSY;
 
 	dev = add_mem_device(name, start, size, IORESOURCE_MEM_WRITEABLE);
 
@@ -130,6 +130,8 @@ void barebox_add_memory_bank(const char *name, resource_size_t start,
 	bank->size = size;
 
 	list_add_tail(&bank->list, &memory_banks);
+
+	return 0;
 }
 
 /*
diff --git a/include/memory.h b/include/memory.h
index 4be4340..165d2dc 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -18,7 +18,7 @@ struct memory_bank {
 
 extern struct list_head memory_banks;
 
-void barebox_add_memory_bank(const char *name, resource_size_t start,
+int barebox_add_memory_bank(const char *name, resource_size_t start,
 				    resource_size_t size);
 
 #define for_each_memory_bank(mem)	list_for_each_entry(mem, &memory_banks, list)
-- 
1.7.10.4




More information about the barebox mailing list