From patchwork Fri Nov 21 01:35:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 41267 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 343B125AEA for ; Fri, 21 Nov 2014 01:35:54 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id d49sf2429613eek.8 for ; Thu, 20 Nov 2014 17:35:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=pQthP+VXP+uh7C6aHNv0+83QRtAR628P99vik8eHpZo=; b=Suwmn3OFPvgEOMJcpmFJcdCwy/6C2UKL6WI+y+TANDOKotoPSJZpIvTLfNtX70sX8F CzSoD/RANrMwAedCXzj4QaQFi75dGMDoxpwY8gsbVDUZjLDLgZL72w5FbDmAR6d8uoXY RPrebxIrVt9wtxXpLqhHpoHbvwNXNrqXq0co+6kFsAemBgfqLdr6dEpP7TyB4Bmz5trF R7kmTFuolmV5oNindhkPKb1M7BFDS0IFIfDQ2BrJhFSMo10eJSBlIptKu4rW91Y+gdeh ks+KcXeumObkGs9C6F3pcpJlGFX5Nk3rXabqW3owmEZSWyNZW0jpFF9XyaquQtWXWidy WE5Q== X-Gm-Message-State: ALoCoQkDCaucKMqy0VLLklrajUMxr5Pb+01w7pZEoff9RWDtdpesm0yOZG48/dTuQ00iLnr2OhwV X-Received: by 10.180.219.66 with SMTP id pm2mr2202805wic.7.1416533753303; Thu, 20 Nov 2014 17:35:53 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.202.166 with SMTP id kj6ls131736lac.73.gmail; Thu, 20 Nov 2014 17:35:52 -0800 (PST) X-Received: by 10.112.139.196 with SMTP id ra4mr204857lbb.95.1416533752452; Thu, 20 Nov 2014 17:35:52 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id ef4si3576463lac.51.2014.11.20.17.35.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 17:35:52 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id z11so3198610lbi.39 for ; Thu, 20 Nov 2014 17:35:52 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr1244738laz.27.1416533751995; Thu, 20 Nov 2014 17:35:51 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp369176lbc; Thu, 20 Nov 2014 17:35:51 -0800 (PST) X-Received: by 10.70.31.97 with SMTP id z1mr1953628pdh.115.1416533750277; Thu, 20 Nov 2014 17:35:50 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qb3si5393893pac.218.2014.11.20.17.35.49 for ; Thu, 20 Nov 2014 17:35:50 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932266AbaKUBfg (ORCPT + 26 others); Thu, 20 Nov 2014 20:35:36 -0500 Received: from mail-wg0-f41.google.com ([74.125.82.41]:58137 "EHLO mail-wg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757359AbaKUBfc (ORCPT ); Thu, 20 Nov 2014 20:35:32 -0500 Received: by mail-wg0-f41.google.com with SMTP id y19so5301867wgg.0 for ; Thu, 20 Nov 2014 17:35:30 -0800 (PST) X-Received: by 10.194.58.180 with SMTP id s20mr2486864wjq.28.1416533730631; Thu, 20 Nov 2014 17:35:30 -0800 (PST) Received: from trevor.secretlab.ca (host86-166-84-117.range86-166.btcentralplus.com. [86.166.84.117]) by mx.google.com with ESMTPSA id cj3sm5767623wjb.45.2014.11.20.17.35.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Nov 2014 17:35:28 -0800 (PST) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id CF7FFC4154B; Fri, 21 Nov 2014 01:35:21 +0000 (GMT) From: Grant Likely To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pantelis Antoniou Cc: Rob Herring , Grant Likely Subject: [PATCH 2/8] of: Refactor __of_node_alloc() into __of_node_dup() Date: Fri, 21 Nov 2014 01:35:09 +0000 Message-Id: <1416533715-9758-3-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416533715-9758-1-git-send-email-grant.likely@linaro.org> References: <1416533715-9758-1-git-send-email-grant.likely@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: grant.likely@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add a node argument to __of_node_alloc() and rename it to __of_node_dup() so that it can also be used to duplicate a node with its properties. This is important for the overlay code so that it can create new nodes without using separate changeset items for every single property. At the same time rework the overlay code to use the new function and drop the extra changeset items. Signed-off-by: Grant Likely --- drivers/of/dynamic.c | 40 +++++++++++++++++++++++++++++----------- drivers/of/of_private.h | 2 +- drivers/of/unittest.c | 14 ++++++++++---- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 2d452be1200b..7c095bffef3a 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -272,15 +272,16 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags) } /** - * __of_node_alloc() - Create an empty device node dynamically. - * @full_name: Full name of the new device node + * __of_node_dup() - Duplicate or create an empty device node dynamically. + * @fmt: Format string (plus vargs) for new full name of the device node * - * Create an empty device tree node, suitable for further modification. - * The node data are dynamically allocated and all the node flags - * have the OF_DYNAMIC & OF_DETACHED bits set. - * Returns the newly allocated node or NULL on out of memory error. + * Create an device tree node, either by duplicating an empty node or by allocating + * an empty one suitable for further modification. The node data are + * dynamically allocated and all the node flags have the OF_DYNAMIC & + * OF_DETACHED bits set. Returns the newly allocated node or NULL on out of + * memory error. */ -struct device_node *__of_node_alloc(const char *fmt, ...) +struct device_node *__of_node_dup(const struct device_node *np, const char *fmt, ...) { va_list vargs; struct device_node *node; @@ -291,17 +292,34 @@ struct device_node *__of_node_alloc(const char *fmt, ...) va_start(vargs, fmt); node->full_name = kvasprintf(GFP_KERNEL, fmt, vargs); va_end(vargs); - if (!node->full_name) - goto err_free; + if (!node->full_name) { + kfree(node); + return NULL; + } of_node_set_flag(node, OF_DYNAMIC); of_node_set_flag(node, OF_DETACHED); of_node_init(node); + /* Iterate over and duplicate all properties */ + if (np) { + struct property *pp, *new_pp; + for_each_property_of_node(np, pp) { + new_pp = __of_prop_dup(pp, GFP_KERNEL); + if (!new_pp) + goto err_prop; + if (__of_add_property(node, new_pp)) { + kfree(new_pp->name); + kfree(new_pp->value); + kfree(new_pp); + goto err_prop; + } + } + } return node; - err_free: - kfree(node); + err_prop: + of_node_put(node); /* Frees the node and properties */ return NULL; } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 1e21b1c6de71..5b0599066d59 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -61,7 +61,7 @@ static inline int of_property_notify(int action, struct device_node *np, * own the devtree lock or work on detached trees only. */ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags); -struct device_node *__of_node_alloc(const char *fmt, ...); +struct device_node *__of_node_dup(const struct device_node *np, const char *fmt, ...); extern const void *__of_get_property(const struct device_node *np, const char *name, int *lenp); diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 79630760ea4f..60eb28422077 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -445,15 +445,15 @@ static void __init of_selftest_changeset(void) struct property *ppadd, padd = { .name = "prop-add", .length = 0, .value = "" }; struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" }; struct property *ppremove; - struct device_node *n1, *n2, *n21, *nremove, *parent; + struct device_node *n1, *n2, *n21, *nremove, *parent, *np; struct of_changeset chgset; of_changeset_init(&chgset); - n1 = __of_node_alloc("/testcase-data/changeset/n1"); + n1 = __of_node_dup(NULL, "/testcase-data/changeset/n1"); selftest(n1, "testcase setup failure\n"); - n2 = __of_node_alloc("/testcase-data/changeset/n2"); + n2 = __of_node_dup(NULL, "/testcase-data/changeset/n2"); selftest(n2, "testcase setup failure\n"); - n21 = __of_node_alloc("/testcase-data/changeset/n2/n21"); + n21 = __of_node_dup(NULL, "%s/%s", "/testcase-data/changeset/n2", "n21"); selftest(n21, "testcase setup failure %p\n", n21); nremove = of_find_node_by_path("/testcase-data/changeset/node-remove"); selftest(nremove, "testcase setup failure\n"); @@ -481,6 +481,12 @@ static void __init of_selftest_changeset(void) selftest(!of_changeset_apply(&chgset), "apply failed\n"); mutex_unlock(&of_mutex); + /* Make sure node names are constructed correctly */ + selftest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")), + "'%s' not added\n", n21->full_name); + if (np) + of_node_put(np); + mutex_lock(&of_mutex); selftest(!of_changeset_revert(&chgset), "revert failed\n"); mutex_unlock(&of_mutex);