From 784c27fb02cb6af25f49691ea3a98104260bee43 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Thu, 19 May 2016 19:32:08 +0000 Subject: Make fdt_node_add_property() behave like fdt_node_set_property() if the property already exists. --- sys/arch/armv7/stand/efiboot/fdt.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'sys') diff --git a/sys/arch/armv7/stand/efiboot/fdt.c b/sys/arch/armv7/stand/efiboot/fdt.c index f49522965ea..8d95817a075 100644 --- a/sys/arch/armv7/stand/efiboot/fdt.c +++ b/sys/arch/armv7/stand/efiboot/fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdt.c,v 1.3 2016/05/17 23:16:10 kettenis Exp $ */ +/* $OpenBSD: fdt.c,v 1.4 2016/05/19 19:32:07 kettenis Exp $ */ /* * Copyright (c) 2009 Dariusz Swiderski @@ -265,28 +265,30 @@ fdt_node_set_property(void *node, char *name, char *data, int len) int fdt_node_add_property(void *node, char *name, char *data, int len) { - uint32_t *ptr; - + char *dummy; + if (!tree_inited) return 0; - ptr = (uint32_t *)node; + if (!fdt_node_property(node, name, &dummy)) { + uint32_t *ptr = (uint32_t *)node; - if (betoh32(*ptr) != FDT_NODE_BEGIN) - return 0; + if (betoh32(*ptr) != FDT_NODE_BEGIN) + return 0; - ptr = skip_node_name(ptr + 1); + ptr = skip_node_name(ptr + 1); - memmove(ptr + 3, ptr, tree.end - (char *)ptr); - tree.struct_size += 3 * sizeof(uint32_t); - if (tree.strings > tree.tree) - tree.strings += 3 * sizeof(uint32_t); - if (tree.memory > tree.tree) - tree.memory += 3 * sizeof(uint32_t); - tree.end += 3 * sizeof(uint32_t); - *ptr++ = htobe32(FDT_PROPERTY); - *ptr++ = htobe32(0); - *ptr++ = htobe32(fdt_add_str(name)); + memmove(ptr + 3, ptr, tree.end - (char *)ptr); + tree.struct_size += 3 * sizeof(uint32_t); + if (tree.strings > tree.tree) + tree.strings += 3 * sizeof(uint32_t); + if (tree.memory > tree.tree) + tree.memory += 3 * sizeof(uint32_t); + tree.end += 3 * sizeof(uint32_t); + *ptr++ = htobe32(FDT_PROPERTY); + *ptr++ = htobe32(0); + *ptr++ = htobe32(fdt_add_str(name)); + } return fdt_node_set_property(node, name, data, len); } -- cgit v1.2.3