From patchwork Mon Sep 21 14:02:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7231361 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D0DC2BEEC1 for ; Mon, 21 Sep 2015 14:06:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E58632068E for ; Mon, 21 Sep 2015 14:06:45 +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 741D7207AD for ; Mon, 21 Sep 2015 14:06:44 +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 1Ze1hl-0002Qy-F8; Mon, 21 Sep 2015 14:04:29 +0000 Received: from mail-wi0-x22c.google.com ([2a00:1450:400c:c05::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ze1hI-00023j-KR for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2015 14:04:02 +0000 Received: by wicfx3 with SMTP id fx3so112955347wic.0 for ; Mon, 21 Sep 2015 07:03:39 -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=0yjZ/FCgKzbmsVZneoshhoYrGIDeIsZMvKdca9X6QuH08RPgqokIUA+i2D/jr3eXaI Vo/UDI95jyhvF8fpDnilG1BFevqrWCysUXuY9C+OJXnOw+fWYQxRxHUC7S52VYuElsgk uEbGeCHgRF3lDi+19wc/a0CI5oH1IrkZM1mDAEOxKufDXtAWgpmEYI8p3vJgsnFa/MiT LmaGqD0eFmKewfaSWIITle3lPXdnBGGH0iGrNozwTK6aavG34LspYfSEYA3JWuI3Zv9Z CCcFRu0qk1p06dkTHcFwWJ+tMlWPbALJGXnA8wkuPuIUWF6VllcikVMUNTOphWAY6tBz q3mg== X-Received: by 10.180.211.243 with SMTP id nf19mr14295560wic.74.1442844216773; Mon, 21 Sep 2015 07:03:36 -0700 (PDT) Received: from cizrna.lan ([109.72.12.69]) by smtp.gmail.com with ESMTPSA id gk9sm13687031wib.9.2015.09.21.07.03.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Sep 2015 07:03:35 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v6 03/22] of/platform: Point to struct device from device node Date: Mon, 21 Sep 2015 16:02:43 +0200 Message-Id: <1442844182-27787-4-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1442844182-27787-1-git-send-email-tomeu.vizoso@collabora.com> References: <1442844182-27787-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150921_070400_899183_BB72E6B7 X-CRM114-Status: GOOD ( 18.68 ) X-Spam-Score: -2.6 (--) 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, 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 , 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,RP_MATCHES_RCVD,T_DKIM_INVALID,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 */