Received: by 10.223.185.116 with SMTP id b49csp28338wrg; Tue, 20 Feb 2018 15:12:16 -0800 (PST) X-Google-Smtp-Source: AH8x226qpP+g9ZDSTLE6S8Jm4vYXqWO+OLFGNH24uqVOcZi4NRB69fMfHY/Y9J6Yno0idLJ9BOq9 X-Received: by 10.99.97.211 with SMTP id v202mr975975pgb.193.1519168335947; Tue, 20 Feb 2018 15:12:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519168335; cv=none; d=google.com; s=arc-20160816; b=eWMdWv3VB0OYHcEiFWTQHKRLLIDa4XtWH6XVKa89FXsgan6wm2TQmKZdvP2iAEm6Ns zovHv1xqTDO06n/uO0v5EdMJ9Ggeg1hRv0MUg9OFi0H2KdGbX+qn5T9YdU4GfHiy8RoL 2hxMBcU56fNJTXyYGfq6qUu2tNN8R8u5tPjszt5m06paqUpm4dv/ifZmNsW83xzY0Hy9 poiAqSK3QlKd4iHIqBJFBkg+F7x7zuyWQpbk79GLTN0nHxyFkj7RmjNtZle9DrrZsyb2 pi8YlQwZRjeQ2SAVTYlVXvmu/HprkgeVycJmCAodQOE3+1oWBSqmtLp+5C9oeeGZFCYF 2aWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=34uKQvYXBvXeYqvSfBP6bbeWqHbXJ047Nu1HrRVE/kM=; b=n6dU+TE0rOsJtyACVXvPCSO5DWceLtI7aH1OoFe380dZjja3rIh5VYJVzCaG2alLVW VhwosbVx3sW0fljOqss/SEXtGH0vZ7NjEB7Sj8iCJO+A6iJmw7BU4LlgU+f21ENEN5UX 594h0maHN8rqeSqm7mZU01zEpVh4akOG6Lc2X7BN4yvunawqRVTfZm8Y5+wTwLGvFaK6 sSSLyLgk31ANviuxJvEkhNw30lnU0+6whm5VgPqFWpdr3eqfK/BlXFcmlhr+uQxZx4nc avAv+KxakO43BvZvX8Od0j+9xYWK685ANXQoZ86W4pqMD/sld4VGVLug2glMkFx09lfp DDEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=kwn5P8Iz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 32-v6si1519705ple.673.2018.02.20.15.12.01; Tue, 20 Feb 2018 15:12:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=kwn5P8Iz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751904AbeBTXLG (ORCPT + 99 others); Tue, 20 Feb 2018 18:11:06 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:38076 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751725AbeBTXKP (ORCPT ); Tue, 20 Feb 2018 18:10:15 -0500 Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id E8E102118E; Wed, 21 Feb 2018 00:08:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1519168110; bh=DQnJNo0idNTcLcRaFDAdmkEDOQIyLJLhUutbQcPzKlE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kwn5P8IzBw87V8VAvalFSSXYuNEZ1GxJoi/pQ++CMO9/HX9MlvR6Qq4NnNt0dtmgQ IF5kDJSqkH/KKopB1yeGAvzTvyMqWSkH3Pp5ZS3v//jEDx35hb3hrc2XJZhZHmPeMM tOXXwbH/i5aRBDzgMYcfYgSddnUHU4Po0qTLT4MM= From: Laurent Pinchart To: dri-devel@lists.freedesktop.org Cc: linux-renesas-soc@vger.kernel.org, Pantelis Antoniou , Rob Herring , Frank Rowand , Matt Porter , Koen Kooi , Guenter Roeck , Marek Vasut , Wolfram Sang , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Subject: [PATCH v4 05/16] of: changeset: Add of_changeset_node_move method Date: Wed, 21 Feb 2018 01:10:35 +0200 Message-Id: <20180220231046.32638-6-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180220231046.32638-1-laurent.pinchart+renesas@ideasonboard.com> References: <20180220231046.32638-1-laurent.pinchart+renesas@ideasonboard.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pantelis Antoniou Adds a changeset helper for moving a subtree to a different place in the running tree. This is useful in advances cases of dynamic device tree construction. Signed-off-by: Pantelis Antoniou Signed-off-by: Laurent Pinchart --- drivers/of/dynamic.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 9 +++++++ 2 files changed, 75 insertions(+) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 85e722ed8631..27d9057ef360 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -1132,3 +1132,69 @@ int __of_changeset_add_update_property_string_list( return ret; } EXPORT_SYMBOL_GPL(__of_changeset_add_update_property_string_list); + +static struct device_node * +__of_changeset_node_move_one(struct of_changeset *ocs, + struct device_node *np, struct device_node *new_parent) +{ + struct device_node *np2; + const char *unitname; + int err; + + err = of_changeset_detach_node(ocs, np); + if (err) + return ERR_PTR(err); + + unitname = strrchr(np->full_name, '/'); + if (!unitname) + unitname = np->full_name; + + np2 = __of_node_dup(np, "%s/%s", + new_parent->full_name, unitname); + if (!np2) + return ERR_PTR(-ENOMEM); + np2->parent = new_parent; + + err = of_changeset_attach_node(ocs, np2); + if (err) + return ERR_PTR(err); + + return np2; +} + +/** + * of_changeset_node_move_to - Moves a subtree to a new place in + * the tree + * + * @ocs: changeset pointer + * @np: device node pointer to be moved + * @to: device node of the new parent + * + * Moves a subtree to a new place in the tree. + * Note that a move is a safe operation because the phandles + * remain valid. + * + * Returns zero on success, a negative error value otherwise. + */ +int of_changeset_node_move(struct of_changeset *ocs, + struct device_node *np, struct device_node *new_parent) +{ + struct device_node *npc, *nppc; + + /* move the root first */ + nppc = __of_changeset_node_move_one(ocs, np, new_parent); + if (IS_ERR(nppc)) + return PTR_ERR(nppc); + + /* move the subtrees next */ + for_each_child_of_node(np, npc) { + nppc = __of_changeset_node_move_one(ocs, npc, nppc); + if (IS_ERR(nppc)) { + of_node_put(npc); + return PTR_ERR(nppc); + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(of_changeset_node_move); diff --git a/include/linux/of.h b/include/linux/of.h index 7aef555f9bc2..76197bc75346 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1328,6 +1328,9 @@ int __of_changeset_add_update_property_string_list( struct of_changeset *ocs, struct device_node *np, const char *name, const char **strs, int count, bool update); +int of_changeset_node_move(struct of_changeset *ocs, + struct device_node *np, struct device_node *new_parent); + #else /* CONFIG_OF_DYNAMIC */ static inline int of_reconfig_notifier_register(struct notifier_block *nb) { @@ -1390,6 +1393,12 @@ static inline int __of_changeset_add_update_property_string_list( return -EINVAL; } +static inline int of_changeset_node_move(struct of_changeset *ocs, + struct device_node *np, struct device_node *new_parent) +{ + return -EINVAL; +} + #endif /* CONFIG_OF_DYNAMIC */ /** -- Regards, Laurent Pinchart