From 58e71097ced49600de1b38d2b59a823a9db66f19 Mon Sep 17 00:00:00 2001 From: Eric Auger Date: Fri, 19 Feb 2016 09:42:30 -0700 Subject: 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 Reviewed-by: Peter Crosthwaite Signed-off-by: Alex Williamson --- device_tree.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'device_tree.c') 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); } -- cgit v1.2.1