From patchwork Fri Nov 21 01:35:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 41272 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B31D125AEA for ; Fri, 21 Nov 2014 01:36:59 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id b6sf2396688lbj.4 for ; Thu, 20 Nov 2014 17:36:58 -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=N3IqMC7dPvliwVz0XuW3e/QGIHURUdaNZa3wIhUSjoQ=; b=jZa+Pq1Sagl+3WhUyxq/Zu4WReCg9PPSaqs9oJQQs8j4cvcYIh/Ps6d+wsGawai6KJ MOxPeZPIgR9Uug2SxscR1jvOXhoy9dGOsMK1wevHfwSLW3uSUXHfaDFG1gTvRDSEsmn/ 835bjOohk991qnyQfeiIdIvv75ApYbu0fFFmvxJth60TEbmLgsM+U6hVfKkGAjENPVNZ V9pFKi7DBNoFRzpZ4vudt3wH7s3PVkS1u/ijbkTKGq1RZ7IVcR4ngkPTN9BwiZdNJXa/ /CrzxjDdYKdpgVij6pVkz5S28lov5kiZDHNXx7zlrgtkhf1rJCZR1K/T5We0U8NrQECh x+dA== X-Gm-Message-State: ALoCoQlmDXBFgwDqJc0JGTkV/BM2p4vWlE5JAFO9yklGfeLd9R0baKgJ8KykTm8YL5T2pkQumfo2 X-Received: by 10.112.142.36 with SMTP id rt4mr516797lbb.3.1416533818673; Thu, 20 Nov 2014 17:36:58 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.38 with SMTP id ld6ls137397lac.50.gmail; Thu, 20 Nov 2014 17:36:58 -0800 (PST) X-Received: by 10.112.45.102 with SMTP id l6mr1354824lbm.46.1416533818331; Thu, 20 Nov 2014 17:36:58 -0800 (PST) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id nz8si3628006lbb.12.2014.11.20.17.36.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 17:36:58 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by mail-lb0-f173.google.com with SMTP id z12so383483lbi.18 for ; Thu, 20 Nov 2014 17:36:58 -0800 (PST) X-Received: by 10.112.138.137 with SMTP id qq9mr1304779lbb.80.1416533818181; Thu, 20 Nov 2014 17:36:58 -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 ew9csp369265lbc; Thu, 20 Nov 2014 17:36:57 -0800 (PST) X-Received: by 10.66.120.129 with SMTP id lc1mr2351619pab.86.1416533815800; Thu, 20 Nov 2014 17:36:55 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nw13si5606019pdb.199.2014.11.20.17.36.55 for ; Thu, 20 Nov 2014 17:36:55 -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 S932541AbaKUBgy (ORCPT + 26 others); Thu, 20 Nov 2014 20:36:54 -0500 Received: from mail-wi0-f176.google.com ([209.85.212.176]:39180 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757308AbaKUBfb (ORCPT ); Thu, 20 Nov 2014 20:35:31 -0500 Received: by mail-wi0-f176.google.com with SMTP id ex7so10554652wid.3 for ; Thu, 20 Nov 2014 17:35:30 -0800 (PST) X-Received: by 10.180.91.49 with SMTP id cb17mr3006836wib.30.1416533730252; 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 h2sm6521255wix.5.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 CCA68C403DC; 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 1/8] of: Use vargs in __of_node_alloc Date: Fri, 21 Nov 2014 01:35:08 +0000 Message-Id: <1416533715-9758-2-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.173 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 da2509d639c8..2d452be1200b 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..1e21b1c6de71 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); +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 082bb2b6a5ad..79630760ea4f 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");