From nobody Tue Feb 10 02:00:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1604891236; cv=none; d=zohomail.com; s=zohoarc; b=gCHOpOtuXP8H9YXANb9SLj3oscCjej2MOhf6Bl7E5UJTT4wxjSqiuRWQHruZF2+e+d2503cFMD2wUBnkAg6kMLWzkqPJQCry+1jrHCIeDjKS39Q/6CC+MYmQxdx7Zhdr/CYpEkOA/gMPTHJ+/05vOJVITXMszKFJyejYBti06mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604891236; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iL7MCbwqGVoU1q+dcPxA2igQwOuVu+H+71SnaBwX7Sw=; b=TVsSw8azThYy4O//7b0OO6R8aILzmJMgK98R36wHSQIG6LJociCAJgWuwwqee9/x1sx6ZFG1qHQgmlZEKHRGgTyXJuGhjsinwKBBLhxlNl31EZRM8MZTaPnArGcblq+2y0oEE/9h0iGbQWXJn3H1h6fTlbcNmYzioF4rEo2xfWY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604891236954756.9301697533623; Sun, 8 Nov 2020 19:07:16 -0800 (PST) Received: from localhost ([::1]:44860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbxWV-0003RN-AU for importer@patchew.org; Sun, 08 Nov 2020 22:07:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbxUs-0001as-66; Sun, 08 Nov 2020 22:05:34 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2080) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbxUn-0006ab-LN; Sun, 08 Nov 2020 22:05:33 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CTwpd2b2Rzhhqx; Mon, 9 Nov 2020 11:05:13 +0800 (CST) Received: from localhost (10.174.186.67) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 11:05:11 +0800 From: Ying Fang To: Subject: [RFC PATCH v3 04/13] device_tree: Add qemu_fdt_add_path Date: Mon, 9 Nov 2020 11:04:43 +0800 Message-ID: <20201109030452.2197-5-fangying1@huawei.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201109030452.2197-1-fangying1@huawei.com> References: <20201109030452.2197-1-fangying1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.186.67] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=fangying1@huawei.com; helo=szxga06-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 22:05:17 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: drjones@redhat.com, zhang.zhanghailiang@huawei.com, qemu-devel@nongnu.org, shannon.zhaosl@gmail.com, qemu-arm@nongnu.org, alistair.francis@wdc.com, imammedo@redhat.com, salil.mehta@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Andrew Jones qemu_fdt_add_path() works like qemu_fdt_add_subnode(), except it also adds any missing parent nodes. We also tweak an error message of qemu_fdt_add_subnode(). We'll make use of the new function in a coming patch. Signed-off-by: Andrew Jones --- device_tree.c | 45 ++++++++++++++++++++++++++++++++++-- include/sysemu/device_tree.h | 1 + 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/device_tree.c b/device_tree.c index b335dae707..c080909bb9 100644 --- a/device_tree.c +++ b/device_tree.c @@ -515,8 +515,8 @@ int qemu_fdt_add_subnode(void *fdt, const char *name) =20 retval =3D fdt_add_subnode(fdt, parent, basename); if (retval < 0) { - error_report("FDT: Failed to create subnode %s: %s", name, - fdt_strerror(retval)); + error_report("%s: Failed to create subnode %s: %s", + __func__, name, fdt_strerror(retval)); exit(1); } =20 @@ -524,6 +524,47 @@ int qemu_fdt_add_subnode(void *fdt, const char *name) return retval; } =20 +/* + * Like qemu_fdt_add_subnode(), but will add all missing + * subnodes in the path. + */ +int qemu_fdt_add_path(void *fdt, const char *path) +{ + char *dupname, *basename, *p; + int parent, retval =3D -1; + + if (path[0] !=3D '/') { + return retval; + } + + parent =3D fdt_path_offset(fdt, "/"); + p =3D dupname =3D g_strdup(path); + + while (p) { + *p =3D '/'; + basename =3D p + 1; + p =3D strchr(p + 1, '/'); + if (p) { + *p =3D '\0'; + } + retval =3D fdt_path_offset(fdt, dupname); + if (retval < 0 && retval !=3D -FDT_ERR_NOTFOUND) { + error_report("%s: Invalid path %s: %s", + __func__, path, fdt_strerror(retval)); + exit(1); + } else if (retval =3D=3D -FDT_ERR_NOTFOUND) { + retval =3D fdt_add_subnode(fdt, parent, basename); + if (retval < 0) { + break; + } + } + parent =3D retval; + } + + g_free(dupname); + return retval; +} + void qemu_fdt_dumpdtb(void *fdt, int size) { const char *dumpdtb =3D qemu_opt_get(qemu_get_machine_opts(), "dumpdtb= "); diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index 982c89345f..15fb98af98 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -104,6 +104,7 @@ uint32_t qemu_fdt_get_phandle(void *fdt, const char *pa= th); uint32_t qemu_fdt_alloc_phandle(void *fdt); int qemu_fdt_nop_node(void *fdt, const char *node_path); int qemu_fdt_add_subnode(void *fdt, const char *name); +int qemu_fdt_add_path(void *fdt, const char *path); =20 #define qemu_fdt_setprop_cells(fdt, node_path, property, ...) = \ do { = \ --=20 2.23.0