diff options
author | Simon Glass <sjg@chromium.org> | 2011-11-17 14:30:06 -0800 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2011-11-18 16:21:36 -0800 |
commit | a4a24c8a87ee3121bde71dde04e58b699670761d (patch) | |
tree | 4fa930ff7a747881ae5a0941e77fc193834070c1 /lib | |
parent | 318c9b21768d937e4a8984af86fec6fcd02242f2 (diff) |
Tidy up fdt_decode_alloc_region() to make alloc separate
Move the malloc() out of fdt_decode_alloc_region() and rename it
accordingly. This makes the code somewhat cleaner and allows us
to print a sensible error message.
BUG=chromium-os:17062
TEST=build and boot on Kaen
Change-Id: I8edc8809baa42578e74c5e42cf47494b31b774e7
Reviewed-on: https://gerrit.chromium.org/gerrit/11878
Commit-Ready: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chromeos/fdt_decode.c | 20 |
1 files changed, 18 insertions, 2 deletions
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; } |