From patchwork Wed Sep 14 08:42:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 114636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E33B3B71D0 for ; Wed, 14 Sep 2011 20:44:17 +1000 (EST) Received: from localhost ([::1]:59518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3l4V-0000G9-A4 for incoming@patchwork.ozlabs.org; Wed, 14 Sep 2011 04:43:55 -0400 Received: from eggs.gnu.org ([140.186.70.92]:42486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3l3U-0007QQ-JG for qemu-devel@nongnu.org; Wed, 14 Sep 2011 04:43:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R3l3G-0000YG-O6 for qemu-devel@nongnu.org; Wed, 14 Sep 2011 04:42:52 -0400 Received: from cantor2.suse.de ([195.135.220.15]:36935 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3l3G-0000Vq-BD; Wed, 14 Sep 2011 04:42:38 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 5482890B96; Wed, 14 Sep 2011 10:42:36 +0200 (CEST) From: Alexander Graf To: qemu-devel Developers Date: Wed, 14 Sep 2011 10:42:51 +0200 Message-Id: <1315989802-18753-28-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1315989802-18753-1-git-send-email-agraf@suse.de> References: <1315989802-18753-1-git-send-email-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Blue Swirl , qemu-ppc@nongnu.org, Aurelien Jarno Subject: [Qemu-devel] [PATCH 27/58] device tree: dont fail operations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When we screw up and issue an FDT command that doesn't work, we really need to know immediately and usually can't continue to create the machine. To make sure we don't need to add error checking in all device tree modification code users, we can just add the fail checks to the qemu abstract functions. Signed-off-by: Alexander Graf --- device_tree.c | 76 ++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 51 insertions(+), 25 deletions(-) diff --git a/device_tree.c b/device_tree.c index f4a78c8..751538e 100644 --- a/device_tree.c +++ b/device_tree.c @@ -72,56 +72,81 @@ fail: return NULL; } -int qemu_devtree_setprop(void *fdt, const char *node_path, - const char *property, void *val_array, int size) +static int findnode_nofail(void *fdt, const char *node_path) { int offset; offset = fdt_path_offset(fdt, node_path); - if (offset < 0) - return offset; + if (offset < 0) { + fprintf(stderr, "%s Couldn't find node %s: %s\n", __func__, node_path, + fdt_strerror(offset)); + exit(1); + } + + return offset; +} + +int qemu_devtree_setprop(void *fdt, const char *node_path, + const char *property, void *val_array, int size) +{ + int r; + + r = fdt_setprop(fdt, findnode_nofail(fdt, node_path), property, val_array, size); + if (r < 0) { + fprintf(stderr, "%s: Couldn't set %s/%s: %s\n", __func__, node_path, + property, fdt_strerror(r)); + exit(1); + } - return fdt_setprop(fdt, offset, property, val_array, size); + return r; } int qemu_devtree_setprop_cell(void *fdt, const char *node_path, const char *property, uint32_t val) { - int offset; + int r; - offset = fdt_path_offset(fdt, node_path); - if (offset < 0) - return offset; + r = fdt_setprop_cell(fdt, findnode_nofail(fdt, node_path), property, val); + if (r < 0) { + fprintf(stderr, "%s: Couldn't set %s/%s = %#08x: %s\n", __func__, + node_path, property, val, fdt_strerror(r)); + exit(1); + } - return fdt_setprop_cell(fdt, offset, property, val); + return r; } int qemu_devtree_setprop_string(void *fdt, const char *node_path, const char *property, const char *string) { - int offset; + int r; - offset = fdt_path_offset(fdt, node_path); - if (offset < 0) - return offset; + r = fdt_setprop_string(fdt, findnode_nofail(fdt, node_path), property, string); + if (r < 0) { + fprintf(stderr, "%s: Couldn't set %s/%s = %s: %s\n", __func__, + node_path, property, string, fdt_strerror(r)); + exit(1); + } - return fdt_setprop_string(fdt, offset, property, string); + return r; } int qemu_devtree_nop_node(void *fdt, const char *node_path) { - int offset; + int r; - offset = fdt_path_offset(fdt, node_path); - if (offset < 0) - return offset; + r = fdt_nop_node(fdt, findnode_nofail(fdt, node_path)); + if (r < 0) { + fprintf(stderr, "%s: Couldn't nop node %s: %s\n", __func__, node_path, + fdt_strerror(r)); + exit(1); + } - return fdt_nop_node(fdt, offset); + return r; } int qemu_devtree_add_subnode(void *fdt, const char *name) { - int offset; char *dupname = g_strdup(name); char *basename = strrchr(dupname, '/'); int retval; @@ -133,12 +158,13 @@ int qemu_devtree_add_subnode(void *fdt, const char *name) basename[0] = '\0'; basename++; - offset = fdt_path_offset(fdt, dupname); - if (offset < 0) { - return offset; + retval = fdt_add_subnode(fdt, findnode_nofail(fdt, dupname), basename); + if (retval < 0) { + fprintf(stderr, "FDT: Failed to create subnode %s: %s\n", name, + fdt_strerror(retval)); + exit(1); } - retval = fdt_add_subnode(fdt, offset, basename); g_free(dupname); return retval; }