From patchwork Tue Oct 3 03:53:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 9981863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 01CFD60291 for ; Tue, 3 Oct 2017 07:19:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7C5328249 for ; Tue, 3 Oct 2017 07:19:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCAA6286C1; Tue, 3 Oct 2017 07:19:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6AF5E28249 for ; Tue, 3 Oct 2017 07:19:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 431026E3D6; Tue, 3 Oct 2017 07:19:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg0-x244.google.com (mail-pg0-x244.google.com [IPv6:2607:f8b0:400e:c05::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id B0F876E3A1 for ; Tue, 3 Oct 2017 03:54:15 +0000 (UTC) Received: by mail-pg0-x244.google.com with SMTP id p5so5804256pgn.2 for ; Mon, 02 Oct 2017 20:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R3wM4RKNDwf46gREaQZTw25pMFgS0rspo+GiFcrT59Y=; b=a8js91ahQGwEi1A9ZtdXvKMH5qKPI0+aW8Zotq0jAYx2oid2I609LL+EcH3BGPhKFC Q642w4uVgAgfGqEH4eAflXAc4pxWeJm/ygIVbSdteOQoKC5iwVL2PT4xFwrBdq3J74OS LyJ6GyX3B7wwjIfhi6DRnV9auCrCiLg00GRgNa2RueBvh4tWm6s03N2M+MDOIXOOOgyM tqH1NtpFf5qIGLUlbdS2px9q8uDw9nrwBL4S5Zd+J68NPXcyyuQHR2pD9eFQyIpSqZOo X+V4PHslvZ6lZBRRnmcl7qNEjILemPdwrB/5wjKKxqsJWOv3ts+F74FRSQSSVBSjjm0c Xtww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=R3wM4RKNDwf46gREaQZTw25pMFgS0rspo+GiFcrT59Y=; b=e7XphIHmRkRigYeKfXv5l+/U86bGySqSG1TVmFptWED6XWc+KwwXHaAVAuf3hNCK8E 4wZwuIKIoJRcheUbjmiaAPeVH4OemIGKFCejF9T8PI79poivYbF8lLxAd+xsdD8dyQGK bdqzT6bACW1GHGwrIfjNb+wc8hK0tYfPz4tHppcuk2r1kJW7az5oOKzlLZjeFdGt677p fXiQTlLh3eCtCUhWsWNhgwvCoU+ggTtWiMhXWrdjkFAukUekZUJQ4dgTbB08j81aYDnM mBsH7OYl3QPIeJUbMwBTEmScTNrBo9D+OoKp4oqyQWkFqwwm+naKTo8wkvXR/Lt4qRsM vopg== X-Gm-Message-State: AHPjjUhE5jrQFaL+fbb/tvKgTFsIoolwSajKzMilGirdc9PSZu6+rmVF ZxmgVt6jXNaQ4Ergf7D3Kqo= X-Google-Smtp-Source: AOwi7QDUPgW/mIX1gLz56xwNQQxS9wZ+6F9yxVG5hdk7xhwLinnw1lKCiVOlUBh0aLO17GM70uCGyg== X-Received: by 10.99.56.78 with SMTP id h14mr14370181pgn.192.1507002855328; Mon, 02 Oct 2017 20:54:15 -0700 (PDT) Received: from localhost.localdomain (c-73-93-215-6.hsd1.ca.comcast.net. [73.93.215.6]) by smtp.gmail.com with ESMTPSA id c16sm18609930pfj.123.2017.10.02.20.54.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Oct 2017 20:54:14 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , David Airlie , Jyri Sarha Subject: [PATCH 10/12] of: overlay: simplify applying symbols from an overlay Date: Mon, 2 Oct 2017 20:53:44 -0700 Message-Id: <1507002826-16393-11-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507002826-16393-1-git-send-email-frowand.list@gmail.com> References: <1507002826-16393-1-git-send-email-frowand.list@gmail.com> X-Mailman-Approved-At: Tue, 03 Oct 2017 07:19:35 +0000 Cc: Mark Rutland , devicetree@vger.kernel.org, Tomi Valkeinen , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Frank Rowand The code to apply symbols from an overlay to the live device tree was implemented with the intent to be minimally intrusive on the existing code. After recent restructuring of the overlay apply code, it is easier to disintangle the code that applies the symbols, and to make the overlay changeset creation code more straight forward and understandable. Remove the extra complexity, and make the code more obvious. Signed-off-by: Frank Rowand --- drivers/of/overlay.c | 91 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 26 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 4ed372af6ce7..172807d3f375 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -32,21 +32,22 @@ struct fragment { struct device_node *target; struct device_node *overlay; - bool is_symbols_node; }; /** * struct overlay_changeset - * @ovcs_list: list on which we are located - * @count: count of @fragments structures - * @fragments: info about fragment nodes in overlay expanded device tree - * @cset: changeset to apply fragments to live device tree + * @ovcs_list: list on which we are located + * @count: count of fragment structures + * @fragments: fragment nodes in the overlay expanded device tree + * @symbols_fragment: last element of @fragments[] is the __symbols__ node + * @cset: changeset to apply fragments to live device tree */ struct overlay_changeset { int id; struct list_head ovcs_list; int count; struct fragment *fragments; + bool symbols_fragment; struct of_changeset cset; }; @@ -68,8 +69,7 @@ static int devicetree_corrupt(void) static int build_changeset_next_level(struct overlay_changeset *ovcs, struct device_node *target_node, - const struct device_node *overlay_node, - bool is_symbols_node); + const struct device_node *overlay_node); /* * of_resolve_phandles() finds the largest phandle in the live tree. @@ -221,7 +221,7 @@ static struct property *dup_and_fixup_symbol_prop( * @ovcs: overlay changeset * @target_node: where to place @overlay_prop in live tree * @overlay_prop: property to add or update, from overlay tree - * is_symbols_node: 1 if @target_node is "/__symbols__" + * @is_symbols_prop: 1 if @overlay_prop is from node "/__symbols__" * * If @overlay_prop does not already exist in @target_node, add changeset entry * to add @overlay_prop in @target_node, else add changeset entry to update @@ -237,7 +237,7 @@ static struct property *dup_and_fixup_symbol_prop( static int add_changeset_property(struct overlay_changeset *ovcs, struct device_node *target_node, struct property *overlay_prop, - bool is_symbols_node) + bool is_symbols_prop) { struct property *new_prop = NULL, *prop; @@ -248,7 +248,7 @@ static int add_changeset_property(struct overlay_changeset *ovcs, !of_prop_cmp(overlay_prop->name, "linux,phandle")) return 0; - if (is_symbols_node) { + if (is_symbols_prop) { if (prop) return -EINVAL; new_prop = dup_and_fixup_symbol_prop(ovcs, overlay_prop); @@ -321,13 +321,13 @@ static int add_changeset_node(struct overlay_changeset *ovcs, if (ret) return ret; - return build_changeset_next_level(ovcs, tchild, node, 0); + return build_changeset_next_level(ovcs, tchild, node); } if (node->phandle && tchild->phandle) ret = -EINVAL; else - ret = build_changeset_next_level(ovcs, tchild, node, 0); + ret = build_changeset_next_level(ovcs, tchild, node); of_node_put(tchild); return ret; @@ -338,7 +338,6 @@ static int add_changeset_node(struct overlay_changeset *ovcs, * @ovcs: overlay changeset * @target_node: where to place @overlay_node in live tree * @overlay_node: node from within an overlay device tree fragment - * @is_symbols_node: @overlay_node is node "/__symbols__" * * Add the properties (if any) and nodes (if any) from @overlay_node to the * @ovcs->cset changeset. If an added node has child nodes, they will @@ -351,16 +350,14 @@ static int add_changeset_node(struct overlay_changeset *ovcs, */ static int build_changeset_next_level(struct overlay_changeset *ovcs, struct device_node *target_node, - const struct device_node *overlay_node, - bool is_symbols_node) + const struct device_node *overlay_node) { struct device_node *child; struct property *prop; int ret; for_each_property_of_node(overlay_node, prop) { - ret = add_changeset_property(ovcs, target_node, prop, - is_symbols_node); + ret = add_changeset_property(ovcs, target_node, prop, 0); if (ret) { pr_debug("Failed to apply prop @%pOF/%s, err=%d\n", target_node, prop->name, ret); @@ -368,9 +365,6 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs, } } - if (is_symbols_node) - return 0; - for_each_child_of_node(overlay_node, child) { ret = add_changeset_node(ovcs, target_node, child); if (ret) { @@ -384,6 +378,28 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs, return 0; } +/* + * Add the properties from __overlay__ node to the @ovcs->cset changeset. + */ +static int build_changeset_symbols_node(struct overlay_changeset *ovcs, + struct device_node *target_node, + const struct device_node *overlay_symbols_node) +{ + struct property *prop; + int ret; + + for_each_property_of_node(overlay_symbols_node, prop) { + ret = add_changeset_property(ovcs, target_node, prop, 1); + if (ret) { + pr_debug("Failed to apply prop @%pOF/%s, err=%d\n", + target_node, prop->name, ret); + return ret; + } + } + + return 0; +} + /** * build_changeset() - populate overlay changeset in @ovcs from @ovcs->fragments * @ovcs: Overlay changeset @@ -398,14 +414,33 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs, */ static int build_changeset(struct overlay_changeset *ovcs) { - int i, ret; + struct fragment *fragment; + int fragments_count, i, ret; - for (i = 0; i < ovcs->count; i++) { - struct fragment *fragment = &ovcs->fragments[i]; + /* + * if there is a symbols fragment in ovcs->fragments[i] it is + * the final element in the array + */ + if (ovcs->symbols_fragment) + fragments_count = ovcs->count - 1; + else + fragments_count = ovcs->count; + + for (i = 0; i < fragments_count; i++) { + fragment = &ovcs->fragments[i]; ret = build_changeset_next_level(ovcs, fragment->target, - fragment->overlay, - fragment->is_symbols_node); + fragment->overlay); + if (ret) { + pr_debug("apply failed '%pOF'\n", fragment->target); + return ret; + } + } + + if (ovcs->symbols_fragment) { + fragment = &ovcs->fragments[ovcs->count - 1]; + ret = build_changeset_symbols_node(ovcs, fragment->target, + fragment->overlay); if (ret) { pr_debug("apply failed '%pOF'\n", fragment->target); return ret; @@ -522,12 +557,16 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, } } + /* + * if there is a symbols fragment in ovcs->fragments[i] it is + * the final element in the array + */ node = of_get_child_by_name(tree, "__symbols__"); if (node) { + ovcs->symbols_fragment = 1; fragment = &fragments[cnt]; fragment->overlay = node; fragment->target = of_find_node_by_path("/__symbols__"); - fragment->is_symbols_node = 1; if (!fragment->target) { pr_err("no symbols in root of device tree.\n");