summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/fdt_decode.c14
-rw-r--r--include/fdt_decode.h10
-rw-r--r--lib/chromeos/fdt_decode.c20
3 files changed, 28 insertions, 16 deletions
diff --git a/common/fdt_decode.c b/common/fdt_decode.c
index b6beebda69..dab673a02c 100644
--- a/common/fdt_decode.c
+++ b/common/fdt_decode.c
@@ -23,7 +23,6 @@
#include <fdt_decode.h>
#include <libfdt.h>
-#include <malloc.h>
#include <serial.h>
/* we need a generic GPIO interface here */
@@ -703,22 +702,19 @@ int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config)
return fdt_decode_gpio(blob, node, "wp-gpio", &config->wp_gpio);
}
-void *fdt_decode_alloc_region(const void *blob, int node,
- const char *prop_name, size_t *size)
+int fdt_decode_region(const void *blob, int node,
+ const char *prop_name, void **ptrp, size_t *size)
{
const addr_t *cell;
- void *ptr;
int len;
debug("%s: %s\n", __func__, prop_name);
cell = fdt_getprop(blob, node, prop_name, &len);
if (!cell || (len != sizeof(addr_t) * 2))
- return NULL;
+ return -1;
- ptr = (void *)addr_to_cpu(*cell);
+ *ptrp = (void *)addr_to_cpu(*cell);
*size = size_to_cpu(cell[1]);
debug("%s: size=%zx\n", __func__, *size);
- if (!ptr)
- ptr = malloc(*size);
- return ptr;
+ return 0;
}
diff --git a/include/fdt_decode.h b/include/fdt_decode.h
index e787b902bf..6087c21861 100644
--- a/include/fdt_decode.h
+++ b/include/fdt_decode.h
@@ -600,8 +600,7 @@ int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config);
/**
* Look up a property in a node which contains a memory region address and
- * size. Then return a pointer to this address. if the address is zero, it is
- * allocated with malloc() instead.
+ * size. Then return a pointer to this address.
*
* The property must hold one address with a length. This is only tested on
* 32-bit machines.
@@ -609,8 +608,9 @@ int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config);
* @param blob FDT blob
* @param node node to examine
* @param prop_name name of property to find
+ * @param ptrp returns pointer to region, or NULL if no address
* @param size returns size of region
- * @return pointer to region, or NULL if property not found/malloc failed
+ * @return 0 if ok, -1 on error (propery not found)
*/
-void *fdt_decode_alloc_region(const void *blob, int node,
- const char *prop_name, size_t *size);
+int fdt_decode_region(const void *blob, int node,
+ const char *prop_name, void **ptrp, size_t *size);
diff --git a/lib/chromeos/fdt_decode.c b/lib/chromeos/fdt_decode.c
index fbc44a320e..3be76643d2 100644
--- a/lib/chromeos/fdt_decode.c
+++ b/lib/chromeos/fdt_decode.c
@@ -15,6 +15,7 @@
#include <chromeos/fmap.h>
#include <fdt_decode.h>
#include <linux/string.h>
+#include <malloc.h>
#define PREFIX "chromeos/fdt_decode: "
@@ -161,9 +162,24 @@ void *fdt_decode_chromeos_alloc_region(const void *blob,
const char *prop_name, size_t *size)
{
int node = fdt_path_offset(blob, "/chromeos-config");
+ void *ptr;
- if (node < 0)
+ if (node < 0) {
+ VBDEBUG(PREFIX "failed to find /chromeos-config in fdt'\n");
return NULL;
+ }
- return fdt_decode_alloc_region(blob, node, prop_name, size);
+ if (fdt_decode_region(blob, node, prop_name, &ptr, size)) {
+ VBDEBUG(PREFIX "failed to find %s in /chromeos-config'\n",
+ prop_name);
+ return NULL;
+ }
+
+ if (!ptr)
+ ptr = malloc(*size);
+ if (!ptr) {
+ VBDEBUG(PREFIX "failed to alloc %d bytes for %s'\n",
+ *size, prop_name);
+ }
+ return ptr;
}