diff options
author | Eric Auger <eric.auger@linaro.org> | 2016-02-19 09:42:30 -0700 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2016-02-19 09:42:30 -0700 |
commit | 58e71097ced49600de1b38d2b59a823a9db66f19 (patch) | |
tree | 54f61c6fb3704a282575d4586710b941d86e94ab /device_tree.c | |
parent | 78e24f235eda4d3313917a50e135b7e06a046407 (diff) |
device_tree: qemu_fdt_getprop_cell converted to use the error API
This patch aligns the prototype with qemu_fdt_getprop. The caller
can choose whether the function self-asserts on error (passing
&error_fatal as Error ** argument, corresponding to the legacy behavior),
or behaves differently such as simply output a message.
In this later case the caller can use the new lenp parameter to interpret
the error if any.
Signed-off-by: Eric Auger <eric.auger@linaro.org>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'device_tree.c')
-rw-r--r-- | device_tree.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/device_tree.c b/device_tree.c index 3d41c4434b..6204af88c8 100644 --- a/device_tree.c +++ b/device_tree.c @@ -350,15 +350,22 @@ const void *qemu_fdt_getprop(void *fdt, const char *node_path, } uint32_t qemu_fdt_getprop_cell(void *fdt, const char *node_path, - const char *property) + const char *property, int *lenp, Error **errp) { int len; - const uint32_t *p = qemu_fdt_getprop(fdt, node_path, property, &len, - &error_fatal); - if (len != 4) { - error_report("%s: %s/%s not 4 bytes long (not a cell?)", - __func__, node_path, property); - exit(1); + const uint32_t *p; + + if (!lenp) { + lenp = &len; + } + p = qemu_fdt_getprop(fdt, node_path, property, lenp, errp); + if (!p) { + return 0; + } else if (*lenp != 4) { + error_setg(errp, "%s: %s/%s not 4 bytes long (not a cell?)", + __func__, node_path, property); + *lenp = -EINVAL; + return 0; } return be32_to_cpu(*p); } |