diff options
author | Simon Glass <sjg@chromium.org> | 2020-01-27 08:49:44 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2020-02-05 19:33:45 -0700 |
commit | a8167d8ee2305f688d970f7ea4c38d7ca9b205ca (patch) | |
tree | 758aba45e1a725e5933aa5f9684413bf70f57e40 /drivers/core/ofnode.c | |
parent | 14ca9f7f5abf7b94d71cfd466fb339bf64f58bda (diff) |
dm: core: Add ofnode_read_prop()
Add a new function to read a property that supports reading the length as
well.
Reimplement ofnode_read_string() using it and fix its comment.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core/ofnode.c')
-rw-r--r-- | drivers/core/ofnode.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 011b43bc02..eebc5a7dce 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -101,30 +101,47 @@ bool ofnode_read_bool(ofnode node, const char *propname) return prop ? true : false; } -const char *ofnode_read_string(ofnode node, const char *propname) +const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep) { - const char *str = NULL; - int len = -1; + const char *val = NULL; + int len; assert(ofnode_valid(node)); debug("%s: %s: ", __func__, propname); if (ofnode_is_np(node)) { struct property *prop = of_find_property( - ofnode_to_np(node), propname, NULL); + ofnode_to_np(node), propname, &len); if (prop) { - str = prop->value; + val = prop->value; len = prop->length; } } else { - str = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), + val = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname, &len); } - if (!str) { + if (!val) { debug("<not found>\n"); + if (sizep) + *sizep = -FDT_ERR_NOTFOUND; return NULL; } + if (sizep) + *sizep = len; + + return val; +} + +const char *ofnode_read_string(ofnode node, const char *propname) +{ + const char *str; + int len; + + str = ofnode_read_prop(node, propname, &len); + if (!str) + return NULL; + if (strnlen(str, len) >= len) { debug("<invalid>\n"); return NULL; |