From patchwork Tue Sep 29 09:10:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7284201 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0FD789F32B for ; Tue, 29 Sep 2015 09:17:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2192D206C0 for ; Tue, 29 Sep 2015 09:16:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 365A4206B8 for ; Tue, 29 Sep 2015 09:16:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zgr0V-0000zV-Eh; Tue, 29 Sep 2015 09:15:31 +0000 Received: from mail-wi0-x230.google.com ([2a00:1450:400c:c05::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZgqxV-0000JY-Uv for linux-arm-kernel@lists.infradead.org; Tue, 29 Sep 2015 09:12:26 +0000 Received: by wicfx3 with SMTP id fx3so5926584wic.0 for ; Tue, 29 Sep 2015 02:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EZ5U2Rckktrz2HOlxuI7JmCF+pZfKv562UdaEXR8yw0=; b=SU5o6TSJQOSYesr4uMAtVKLRynFr8Z0leZ88MaKm/+OXkKNc5rwEkvIOLdXRf7BXV0 HZI8IOBOTGw1d/fwLiG8ElFT6ucjOhUhjRMMN0P6YzBDZwWAIqpZGIuyFkQbavQ+otol itZwYLj1shx2fXBEvefGsJwemq/Vv9+6m1Ko3C8cWsBYgr5JXq96e1uYfKsakj8Ewz2y oCKU9L5GE09B3OwJghyE9YpIaNtmjFZrcxUI1Qt8wzTc0yf9xcVPVUJP1eDKp1zslpLU wPtq0urBHns3Ci0X2QNxv6uLiIuc9WdBEYaUqIaVZd/xuTNh97kMHSL0ZnLDL3BQBc81 jqGw== X-Received: by 10.180.211.116 with SMTP id nb20mr24851740wic.50.1443517924383; Tue, 29 Sep 2015 02:12:04 -0700 (PDT) Received: from cizrna.lan ([109.72.12.204]) by smtp.gmail.com with ESMTPSA id lj12sm22757276wic.0.2015.09.29.02.12.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2015 02:12:03 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v7 03/20] of/platform: Point to struct device from device node Date: Tue, 29 Sep 2015 11:10:41 +0200 Message-Id: <1443517859-30376-4-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443517859-30376-1-git-send-email-tomeu.vizoso@collabora.com> References: <1443517859-30376-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150929_021226_151665_F6E814CC X-CRM114-Status: GOOD ( 19.45 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , devicetree@vger.kernel.org, Ulf Hansson , linux-acpi@vger.kernel.org, Arnd Bergmann , Stephen Warren , Greg Kroah-Hartman , Linus Walleij , Dmitry Torokhov , "Rafael J. Wysocki" , Rob Herring , Javier Martinez Canillas , Mark Brown , Thierry Reding , Russell King , Alan Stern , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When adding platform and AMBA devices, set the device node's device member to point to it. This speeds lookups considerably and is safe because we only create one of these devices for any given device node. Signed-off-by: Tomeu Vizoso --- Changes in v5: - Set the pointer to struct device also for AMBA devices - Unset the pointer to struct device when the platform device is about to be unregistered - Increase the reference count of the device before returning from of_find_device_by_node() drivers/of/platform.c | 19 ++++++++++--------- include/linux/of.h | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 1001efaedcb8..408d89f1d124 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -32,11 +32,6 @@ const struct of_device_id of_default_bus_match_table[] = { {} /* Empty terminated list */ }; -static int of_dev_node_match(struct device *dev, void *data) -{ - return dev->of_node == data; -} - /** * of_find_device_by_node - Find the platform_device associated with a node * @np: Pointer to device tree node @@ -45,10 +40,10 @@ static int of_dev_node_match(struct device *dev, void *data) */ struct platform_device *of_find_device_by_node(struct device_node *np) { - struct device *dev; - - dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match); - return dev ? to_platform_device(dev) : NULL; + if (np->device && np->device->bus == &platform_bus_type && + get_device(np->device)) + return to_platform_device(np->device); + return NULL; } EXPORT_SYMBOL(of_find_device_by_node); @@ -192,6 +187,8 @@ static struct platform_device *of_platform_device_create_pdata( goto err_clear_flag; } + np->device = &dev->dev; + return dev; err_clear_flag: @@ -272,6 +269,8 @@ static struct amba_device *of_amba_device_create(struct device_node *node, goto err_free; } + node->device = &dev->dev; + return dev; err_free: @@ -476,6 +475,8 @@ static int of_platform_device_destroy(struct device *dev, void *data) if (of_node_check_flag(dev->of_node, OF_POPULATED_BUS)) device_for_each_child(dev, NULL, of_platform_device_destroy); + dev->of_node->device = NULL; + if (dev->bus == &platform_bus_type) platform_device_unregister(to_platform_device(dev)); #ifdef CONFIG_ARM_AMBA diff --git a/include/linux/of.h b/include/linux/of.h index 2194b8ca41f9..eb091be0f8ee 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -52,6 +52,7 @@ struct device_node { phandle phandle; const char *full_name; struct fwnode_handle fwnode; + struct device *device; struct property *properties; struct property *deadprops; /* removed properties */