From patchwork Tue Feb 20 23:10:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 875877 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kwn5P8Iz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zmGZf0mVMz9ryg for ; Wed, 21 Feb 2018 10:11:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751786AbeBTXLF (ORCPT ); Tue, 20 Feb 2018 18:11:05 -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: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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 */ /**