summaryrefslogtreecommitdiffstats
path: root/device_tree.c
diff options
context:
space:
mode:
authorEric Auger <eric.auger@linaro.org>2016-02-19 09:42:30 -0700
committerTimothy Pearson <tpearson@raptorengineering.com>2019-11-29 19:45:30 -0600
commitc05a16860d17cbf495e7dda9b8683c61e2b493b2 (patch)
treec992568553a50672422cd3519c45b772e6d2cb14 /device_tree.c
parentd5b2c32e8d12f9e60dde39debcb4954a4f2350b1 (diff)
downloadhqemu-c05a16860d17cbf495e7dda9b8683c61e2b493b2.zip
hqemu-c05a16860d17cbf495e7dda9b8683c61e2b493b2.tar.gz
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.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/device_tree.c b/device_tree.c
index 3d41c44..6204af8 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);
}
OpenPOWER on IntegriCloud