Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3292840imm; Mon, 8 Oct 2018 01:13:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV63JISfg/H9Gdy9WUcVFLiTM/LJfu7jI+Z/dIjAHDDF0N7AsHqzSaufOjgF0elpKPl8BBE2G X-Received: by 2002:a62:2741:: with SMTP id n62-v6mr16855524pfn.138.1538986429404; Mon, 08 Oct 2018 01:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538986429; cv=none; d=google.com; s=arc-20160816; b=YSMpetf45eOP8e0waMP0p+bagh9/aQriCM7lw5PluH1iv8t6aQFLf4vRPEdANs26TX bDQ84Y9zkLcenuNu9f2+UnX577+3i3p5IAEg5OXrl/bDxeG7gvvZXJzLBkb0DUFdCjLa VJvcehSl0BafWA0qnG6xApIsrA3qgOzbMbofse0Lg2DT4LGDdXaqSTktI6EJoHAmSJ0H 10eVujbDjKduW7j5NeqHBtgSfBG00YiU5O4bXGWUuNv/Zl9CVnszpydqRlu2tC979l9Z SQwi770YtUiFw6OwJhClNeaHVflQ41fXsxSShm3xCdVGA+Nd4EN7nPJrVpA5cpFX16dZ 9NyQ== 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; bh=PznUbTrfR6qUTimaak66NhD6E9qcxnwJqTLfRp98mb0=; b=gGWGng+TqAhnL+waBohkr27NMqpNoYqspDSz9ipchto08pkRU/oBAZpE0NRMFqepFi Z91o8Ta6DJ5SpL9GqFUep1j73WM9/sNPQb3c85IiZyK54o6pEh27xXFG0Iv/sonrzPZF Sdk9cLegtmWahHj1ZPE+xjStKqKtqTNbxg7Ix9+qNdpAvME/tyCIkqA9GYvWqDpRMfbT +FX+BTRIeFiZwoTdVSa1NAukuhSCqiAS8MwIPuAwGmcnd95ke4nVjX3hxQTvtP6/arRE PXqZAdFG3wfhqnKRTV08lH5pGVAU9J+YytOnDhzlwM+l6FzjZbhs6dQX+YseWc8YyGbW qCFQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 h7-v6si19551923pfe.72.2018.10.08.01.13.34; Mon, 08 Oct 2018 01:13:49 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726861AbeJHPX4 (ORCPT + 99 others); Mon, 8 Oct 2018 11:23:56 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:46764 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725983AbeJHPXz (ORCPT ); Mon, 8 Oct 2018 11:23:55 -0400 Received: by mail-oi1-f196.google.com with SMTP id k64-v6so15069439oia.13 for ; Mon, 08 Oct 2018 01:13:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PznUbTrfR6qUTimaak66NhD6E9qcxnwJqTLfRp98mb0=; b=PaIcSm9u7WJLPFK5Td/bQmVU1iyrWjBmJryqOt3EdXM4A7NaAu875USFcjAp1ooSF4 U3VtC1oa0wWbKQS6LhPP78mdM9ybv/BVhn5ydsBpdJV7EHh/+zLs3Kj0jBHuHxgCXpet 9tbGH2BvuYMlLyC1lVlY3CXVued2dAtarz9OMSoOJkkewLr/0J9zjPlnAqDzWVTsyUZp ETHaL1zzpS0PTdum4Q3ZKrRDNl17+xiL+M7OpQFu+xIMnbYWPO/s+CIAe4YfkTeGpxnx YKBC3DECMa/uFyrjeUWcOI+DMFJZYv/LdXmOj6zkTDSQoa32akk7Q2t/UJ3WhVG02k9B djHg== X-Gm-Message-State: ABuFfoifykI19RZoDvxUWpGRqwrLwDMEZUWqktO0gN6uugYmpBt6UqPL FFljuCGUGYUfFuUZ2gxE2QxpxLgPL8q6mLgLlvE= X-Received: by 2002:aca:1314:: with SMTP id e20-v6mr4383032oii.216.1538986405551; Mon, 08 Oct 2018 01:13:25 -0700 (PDT) MIME-Version: 1.0 References: <1537853328-1282-1-git-send-email-svellattu@mvista.com> In-Reply-To: <1537853328-1282-1-git-send-email-svellattu@mvista.com> From: "Rafael J. Wysocki" Date: Mon, 8 Oct 2018 10:13:14 +0200 Message-ID: Subject: Re: [PATCH v2 1/2] Driver core: add bus_find_device_by_fwnode To: svellattu@mvista.com Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Linux Kernel Mailing List , Rob Herring , Frank Rowand 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 On Tue, Sep 25, 2018 at 7:29 AM Silesh C V wrote: > > Some drivers need to find the device on a bus having a specific firmware > node. Currently, such drivers have their own implementations to do this. > Provide a helper similar to bus_find_device_by_name so that each driver > does not have to reinvent this. > > Signed-off-by: Silesh C V > > --- > drivers/base/bus.c | 26 ++++++++++++++++++++++++++ > include/linux/device.h | 3 +++ > 2 files changed, 29 insertions(+) > > diff --git a/drivers/base/bus.c b/drivers/base/bus.c > index 8bfd27e..148b198 100644 > --- a/drivers/base/bus.c > +++ b/drivers/base/bus.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include "base.h" > #include "power/power.h" > > @@ -373,6 +374,31 @@ struct device *bus_find_device_by_name(struct bus_type *bus, > } > EXPORT_SYMBOL_GPL(bus_find_device_by_name); > > +static int match_fwnode(struct device *dev, void *data) > +{ > + struct fwnode_handle *fwnode = data; > + struct device_node *of_node = to_of_node(fwnode); > + > + if (of_node) > + return dev->of_node == of_node; > + else > + return dev->fwnode == fwnode; Why don't you use dev_fwnode() here? > +} > + > +/** > + * bus_find_device_by_fwnode - device iterator for locating a particular device > + * having a specific firmware node > + * @bus: bus type > + * @start: Device to begin with > + * @fwnode: firmware node of the device to match > + */ > +struct device *bus_find_device_by_fwnode(struct bus_type *bus, struct device *start, > + struct fwnode_handle *fwnode) > +{ > + return bus_find_device(bus, start, (void *)fwnode, match_fwnode); > +} > +EXPORT_SYMBOL_GPL(bus_find_device_by_fwnode); > + > /** > * subsys_find_device_by_id - find a device with a specific enumeration number > * @subsys: subsystem > diff --git a/include/linux/device.h b/include/linux/device.h > index 8f88254..09384f6 100644 > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -171,6 +171,9 @@ struct device *bus_find_device(struct bus_type *bus, struct device *start, > struct device *bus_find_device_by_name(struct bus_type *bus, > struct device *start, > const char *name); > +struct device *bus_find_device_by_fwnode(struct bus_type *bus, > + struct device *start, > + struct fwnode_handle *fwnode); > struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, > struct device *hint); > int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, > -- > 1.9.1 >