diff mbox

[03/10] core/device: Allow for large DT props

Message ID 20170609065546.28963-3-matthew.brown.dev@gmail.com
State New
Headers show

Commit Message

Matt Brown June 9, 2017, 6:55 a.m. UTC
As the skiboot heap is only 16MB, we cannot allocate large amounts of
memory using malloc. By using local_alloc we can allocate beyond the
skiboot heap.
This is useful for allocating large DT properties.

Any DT properties with size > 1MB will now be allocated using local_alloc
instead of malloc.

Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>
---
 core/device.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/core/device.c b/core/device.c
index 76c2f84..869deae 100644
--- a/core/device.c
+++ b/core/device.c
@@ -376,11 +376,19 @@  struct dt_node *dt_find_by_phandle(struct dt_node *root, u32 phandle)
 	return NULL;
 }
 
+/* Any property larger than MAX_ALLOC will be allocated using local_alloc */
+#define MAX_MALLOC 1048576
+
 static struct dt_property *new_property(struct dt_node *node,
 					const char *name, size_t size)
 {
-	struct dt_property *p = malloc(sizeof(*p) + size);
 	char *path;
+	struct dt_property *p;
+
+	if (size > MAX_MALLOC)
+		p = local_alloc(0, sizeof(*p)+size, 0x10000);
+	else
+		p = malloc(sizeof(*p) + size);
 
 	if (!p) {
 		path = dt_get_path(node);