From patchwork Mon Nov 24 22:33:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 41435 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AE9EE25E23 for ; Mon, 24 Nov 2014 22:39:09 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id s18sf5953838lam.6 for ; Mon, 24 Nov 2014 14:39:08 -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=JFzzVi4PCQMf+E4A8I8Etkt9WxV54nlyuklkkAd/0e8=; b=O/ZQBgX9wb13UbFL4jiuZFXXSjdeWZEdJDwyJaQ6f1yTHZ+3mu3QkCTvsJBo/i1LEP LjTh8o0KFQTaRMmVzJF5DR93bQBYufra3xFRhr9gvI4fMinoPuqhgDYSjdXgd0gHQ4/f YicvIgF8tSYvc64F2dc+UYxWtAXPcRccioyHijzfIj3lAV0uts1qHb4tpJHkLkuK6mCu xDmPxYopWZgg+W7MIkuMlGzzJY3gTNONm83JCKGToQ6Y89QUjgF5eDChtXdicgiCwj/D sbDWks7sJD0NyMNCft7IyW1D0wpTW3+918QcWu3iEh1R+MtSzZqfLK/ZVBwxz8UiRFbg /izQ== X-Gm-Message-State: ALoCoQm7uqmfdRlqdEgASjj5V8AB8Nwh2KO7HgdtlJPlzB+BEYT4yVrfGnAV56TCyN0M1iFEBo/K X-Received: by 10.180.108.101 with SMTP id hj5mr4645840wib.3.1416868748538; Mon, 24 Nov 2014 14:39:08 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.226 with SMTP id b2ls448879lak.36.gmail; Mon, 24 Nov 2014 14:39:08 -0800 (PST) X-Received: by 10.152.204.9 with SMTP id ku9mr22820658lac.55.1416868748377; Mon, 24 Nov 2014 14:39:08 -0800 (PST) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id g8si16569779lae.48.2014.11.24.14.39.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Nov 2014 14:39:08 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id u10so5247379lbd.20 for ; Mon, 24 Nov 2014 14:39:08 -0800 (PST) X-Received: by 10.152.6.228 with SMTP id e4mr22827312laa.71.1416868748287; Mon, 24 Nov 2014 14:39:08 -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 ew9csp348133lbc; Mon, 24 Nov 2014 14:39:07 -0800 (PST) X-Received: by 10.68.213.8 with SMTP id no8mr37709952pbc.92.1416868746134; Mon, 24 Nov 2014 14:39:06 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mv8si23678905pdb.96.2014.11.24.14.39.05 for ; Mon, 24 Nov 2014 14:39:06 -0800 (PST) Received-SPF: none (google.com: devicetree-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 S1751971AbaKXWim (ORCPT + 4 others); Mon, 24 Nov 2014 17:38:42 -0500 Received: from mail-wg0-f44.google.com ([74.125.82.44]:52920 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750786AbaKXWeK (ORCPT ); Mon, 24 Nov 2014 17:34:10 -0500 Received: by mail-wg0-f44.google.com with SMTP id b13so13570772wgh.3 for ; Mon, 24 Nov 2014 14:34:08 -0800 (PST) X-Received: by 10.194.122.10 with SMTP id lo10mr36490247wjb.19.1416868448478; Mon, 24 Nov 2014 14:34:08 -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 u5sm237230wiz.9.2014.11.24.14.34.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Nov 2014 14:34:07 -0800 (PST) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id 45391C4420B; Mon, 24 Nov 2014 22:33:45 +0000 (GMT) From: Grant Likely To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pantelis Antoniou Cc: Rob Herring , Mark Brown , Wolfram Sang , Grant Likely Subject: [PATCH v2 01/14] of: Use vargs in __of_node_alloc Date: Mon, 24 Nov 2014 22:33:29 +0000 Message-Id: <1416868422-22103-2-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416868422-22103-1-git-send-email-grant.likely@linaro.org> References: <1416868422-22103-1-git-send-email-grant.likely@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@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.175 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: , The overlay code needs to construct a new full_name from the parent name and the node name, but the current method has to allocate and then free an temporary string which is wasteful. Fix this problem by using vargs to pass in a format and arguments into __of_node_alloc(). At the same time remove the allocflags argument to __of_node_alloc(). The only users all use GFP_KERNEL, so there is no need to provide it as an option. If there is ever a need later it can be added back. Signed-off-by: Grant Likely --- drivers/of/dynamic.c | 16 ++++++++-------- drivers/of/of_private.h | 2 +- drivers/of/unittest.c | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index d43f3059963b..af1b1ecd6a3d 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -274,33 +274,33 @@ 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 - * @allocflags: Allocation flags (typically pass GFP_KERNEL) * * 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. */ -struct device_node *__of_node_alloc(const char *full_name, gfp_t allocflags) +struct device_node *__of_node_alloc(const char *fmt, ...) { + va_list vargs; struct device_node *node; - node = kzalloc(sizeof(*node), allocflags); + node = kzalloc(sizeof(*node), GFP_KERNEL); if (!node) return NULL; - - node->full_name = kstrdup(full_name, allocflags); - of_node_set_flag(node, OF_DYNAMIC); - of_node_set_flag(node, OF_DETACHED); + va_start(vargs, fmt); + node->full_name = kvasprintf(GFP_KERNEL, fmt, vargs); + va_end(vargs); if (!node->full_name) goto err_free; + of_node_set_flag(node, OF_DYNAMIC); + of_node_set_flag(node, OF_DETACHED); of_node_init(node); return node; err_free: - kfree(node->full_name); kfree(node); return NULL; } diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 858e0a5d9a11..618abcad307e 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 *full_name, gfp_t allocflags); +__printf(1, 2) struct device_node *__of_node_alloc(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 46af7019d291..7634a17af1d5 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -449,11 +449,11 @@ static void __init of_selftest_changeset(void) struct of_changeset chgset; of_changeset_init(&chgset); - n1 = __of_node_alloc("/testcase-data/changeset/n1", GFP_KERNEL); + n1 = __of_node_alloc("/testcase-data/changeset/n1"); selftest(n1, "testcase setup failure\n"); - n2 = __of_node_alloc("/testcase-data/changeset/n2", GFP_KERNEL); + n2 = __of_node_alloc("/testcase-data/changeset/n2"); selftest(n2, "testcase setup failure\n"); - n21 = __of_node_alloc("/testcase-data/changeset/n2/n21", GFP_KERNEL); + n21 = __of_node_alloc("/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");