From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755522AbbJVAdZ (ORCPT ); Wed, 21 Oct 2015 20:33:25 -0400 Received: from v094114.home.net.pl ([79.96.170.134]:65224 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752161AbbJVAdW (ORCPT ); Wed, 21 Oct 2015 20:33:22 -0400 From: "Rafael J. Wysocki" To: Tomeu Vizoso Cc: linux-kernel@vger.kernel.org, Rob Herring , Stephen Warren , Javier Martinez Canillas , Greg Kroah-Hartman , Mark Brown , Thierry Reding , Alan Stern , linux-arm-kernel@lists.infradead.org, Dmitry Torokhov , devicetree@vger.kernel.org, Linus Walleij , linux-acpi@vger.kernel.org, Arnd Bergmann Subject: Re: [PATCH v6 03/22] of/platform: Point to struct device from device node Date: Thu, 22 Oct 2015 03:02:14 +0200 Message-ID: <1800338.r1NE3r6BDS@vostro.rjw.lan> User-Agent: KMail/4.11.5 (Linux/4.1.0-rc5+; KDE/4.11.5; x86_64; ; ) In-Reply-To: <1442844182-27787-4-git-send-email-tomeu.vizoso@collabora.com> References: <1442844182-27787-1-git-send-email-tomeu.vizoso@collabora.com> <1442844182-27787-4-git-send-email-tomeu.vizoso@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday, September 21, 2015 04:02:43 PM Tomeu Vizoso wrote: > 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; There are cases in which multiple device objects point to the same device_node, so is the single struct device pointer here really sufficient? > > struct property *properties; > struct property *deadprops; /* removed properties */ > Thanks, Rafael