Received: by 2002:a17:90a:37a3:0:0:0:0 with SMTP id v32csp4113043pjb; Mon, 10 Jun 2019 10:38:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVd6PV71GCc/mYfBGTnKjpavKZsQa9+Hvxqk7k45lFGDBUTR2Fn+fPmgp66Dwv6q9l2Ojv X-Received: by 2002:a17:902:ac1:: with SMTP id 59mr10346595plp.168.1560188290126; Mon, 10 Jun 2019 10:38:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560188290; cv=none; d=google.com; s=arc-20160816; b=Psp/cOSRCdOc0YUVcFilbdCHkQspkBk2jUB7B2eS3o6E7ua9lBSCzVKaPGrksnF2Qt whrDcgTNFoHF1xUh09yP6CyAb4d3cbLZqzdjpYGBAI9hC9l+c9364kptXhdeBxMGkGJu cC/dXHFYRO8XU4jUkqIeDZgd6jytYAALwzufAdrEVdncPeNah2XQJMsfhCfgCKySf2uy rrAOESBTn+pEeSZQj0YVYOMFKbnkdOPr7II4Yjeyu/M6ExPVELF9X1+fNjWzqTKw1Kf0 M8EJ+4sfAL0sZLWzGI2ftOIxbH89v4WaIeZxXBEmdXkArvcCnueilLQx7GtvPzui98Xr +z1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7D5SSC0UErQfii5N6iWs6lJs5oLFBR5/X5t8RLcvB1c=; b=FUsbGCHWTsacwKBa1AnmIbohlzyCAaW88mL0yPZXTTUNdEtQgfPNyy3eMt3WrFRXEN KrE7xRVx3xyQ42FfzupbfCJ7sB7m8D8Ka+glrNkPKBDsuW0hUkfJX4sI0LbMCRRseH6h IcBJryzxYkW9/4ZMerePXAVoaSQKRr3C5zgjj9qe3b2fQgr6DjWu9nLZ3CHVsmSlWDHQ y4BkEL0J4VyM4Js08BTAVVPUcFLgyxf/0+0JKYXNLhdA7SJOTMfmPLl51vUGZEuF6qIm m5Xd3WJI4ypJbXGvoTRZbeZJBV18X2nC0uWqc+9R4adFvGKBF5cncW/5xbmKP97i+3cs nm5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y4R0V50h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si10304090pgm.431.2019.06.10.10.37.54; Mon, 10 Jun 2019 10:38:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y4R0V50h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388412AbfFJRgP (ORCPT + 99 others); Mon, 10 Jun 2019 13:36:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:32976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387896AbfFJRgP (ORCPT ); Mon, 10 Jun 2019 13:36:15 -0400 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE864212F5; Mon, 10 Jun 2019 17:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560188174; bh=yngxEUZsDeO9jKmEiRe01p0lStP+ET5zKpvRqAHTYfo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=y4R0V50he40BZyVZoGvfZOLeGR9Yrv9zwQ2ODQEkSLmmY6IjxWbijj/cYZaBfHcSE lTrnAUVtkiTSKUcD1Kb6twXgMKRGDssIK3Vo0wnibdUaHElr7dxNcBjH4lznkTa1if Xevy2XkW1wP3o9PpLrLv5c5l3Tv1RTD6EDFpzrGU= Received: by mail-qk1-f178.google.com with SMTP id g18so5992388qkl.3; Mon, 10 Jun 2019 10:36:13 -0700 (PDT) X-Gm-Message-State: APjAAAXXg3nU2ZidC90s6jygqUguwjBFL9D7u8SOfV2QDNjYhboV0xVM hs2EeKRFBtDGuGuhBChaocnlA5JH1LO+01BQcQ== X-Received: by 2002:ae9:f801:: with SMTP id x1mr14208781qkh.151.1560188173041; Mon, 10 Jun 2019 10:36:13 -0700 (PDT) MIME-Version: 1.0 References: <20190604003218.241354-1-saravanak@google.com> <20190604003218.241354-2-saravanak@google.com> In-Reply-To: <20190604003218.241354-2-saravanak@google.com> From: Rob Herring Date: Mon, 10 Jun 2019 11:36:01 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RESEND PATCH v1 1/5] of/platform: Speed up of_find_device_by_node() To: Saravana Kannan Cc: Mark Rutland , Greg Kroah-Hartman , "Rafael J. Wysocki" , Frank Rowand , David Collins , devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" , Android Kernel Team Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Why are you resending this rather than replying to Frank's last comments on the original? On Mon, Jun 3, 2019 at 6:32 PM Saravana Kannan wrote: > > Add a pointer from device tree node to the device created from it. > This allows us to find the device corresponding to a device tree node > without having to loop through all the platform devices. > > However, fallback to looping through the platform devices to handle > any devices that might set their own of_node. > > Signed-off-by: Saravana Kannan > --- > drivers/of/platform.c | 20 +++++++++++++++++++- > include/linux/of.h | 3 +++ > 2 files changed, 22 insertions(+), 1 deletion(-) > > diff --git a/drivers/of/platform.c b/drivers/of/platform.c > index 04ad312fd85b..1115a8d80a33 100644 > --- a/drivers/of/platform.c > +++ b/drivers/of/platform.c > @@ -42,6 +42,8 @@ static int of_dev_node_match(struct device *dev, void *data) > return dev->of_node == data; > } > > +static DEFINE_SPINLOCK(of_dev_lock); > + > /** > * of_find_device_by_node - Find the platform_device associated with a node > * @np: Pointer to device tree node > @@ -55,7 +57,18 @@ 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); > + /* > + * Spinlock needed to make sure np->dev doesn't get freed between NULL > + * check inside and kref count increment inside get_device(). This is > + * achieved by grabbing the spinlock before setting np->dev = NULL in > + * of_platform_device_destroy(). > + */ > + spin_lock(&of_dev_lock); > + dev = get_device(np->dev); > + spin_unlock(&of_dev_lock); > + if (!dev) > + dev = bus_find_device(&platform_bus_type, NULL, np, > + of_dev_node_match); > return dev ? to_platform_device(dev) : NULL; > } > EXPORT_SYMBOL(of_find_device_by_node); > @@ -196,6 +209,7 @@ static struct platform_device *of_platform_device_create_pdata( > platform_device_put(dev); > goto err_clear_flag; > } > + np->dev = &dev->dev; > > return dev; > > @@ -556,6 +570,10 @@ 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); > > + /* Spinlock is needed for of_find_device_by_node() to work */ > + spin_lock(&of_dev_lock); > + dev->of_node->dev = NULL; > + spin_unlock(&of_dev_lock); > of_node_clear_flag(dev->of_node, OF_POPULATED); > of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); > > diff --git a/include/linux/of.h b/include/linux/of.h > index 0cf857012f11..f2b4912cbca1 100644 > --- a/include/linux/of.h > +++ b/include/linux/of.h > @@ -48,6 +48,8 @@ struct property { > struct of_irq_controller; > #endif > > +struct device; > + > struct device_node { > const char *name; > phandle phandle; > @@ -68,6 +70,7 @@ struct device_node { > unsigned int unique_id; > struct of_irq_controller *irq_trans; > #endif > + struct device *dev; /* Device created from this node */ > }; > > #define MAX_PHANDLE_ARGS 16 > -- > 2.22.0.rc1.257.g3120a18244-goog >