From patchwork Wed Jun 5 15:13:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 165899 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp7485924ili; Wed, 5 Jun 2019 08:15:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2BJkkbm9j78pP69uYnQuIgCdgi0hgrwb2Q8lXlFHcQbHsfcoDwkcr1EsRm+t35fHSc0EQ X-Received: by 2002:a17:902:14e:: with SMTP id 72mr45515619plb.36.1559747701281; Wed, 05 Jun 2019 08:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559747701; cv=none; d=google.com; s=arc-20160816; b=gxVDNa+H2Mphc3H9E3o8+t7LffzJrtABGUXMoL76Thbven499kPOn4BV/iL6SLBzwW 0V9SyW7k3PYtXVdWiOWLlRMc7XHRINlw/XFwycMA7q/eFa52c9ViinwiYAoppclaPq+X S99UeHo5yteAhMD9zpaZlJed81XCy4rltkAhAntopXQMLGZcXkp47aTl+65zzC7CX6a8 qDQ3RMauotVptNFFXYk4FlYqgSIR8vSVWPA17ESH8f5TZUuH0g3GPC6uCZG1xewJiOrZ ENVksdYxwD3v28q3nAx3cgx3QhzunUIO0gu3VniaINSWEXmTBhbgzCRJt+Y9eo8kzWzO CK3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=dV5UpgpBZ3Z65b11Na9WADjIHjgtOSXIcnoOHfUcIaU=; b=bsaVEH0bVlSDm9Qhg1QjcZ194WRcpyYDAMa6U96gw75HDazGQ0ETx63VUbLP1rXwEz nlUt0IcRGxs+oj5I9rW7Xxvf00WYdLaX5/GecZbQXNuY3m/UDsqEFpNbFrXre03Oe+Bl SaRo9JYW2KwsPyd1V70z1CGWeLa5/dMxEOKj9kw9dJMJdCBxQfnYMfoaQx30n4myRMGM mwA3L10Y0qBIgk3z0s5rs4EyliiFdnxKdEl/9Ylv3DxKAkOedcFcnwNXqGQNn3J4Wu8G +6sNCTXLsajVlTtXQJBKR64PAMC5ZLYdOqCcu2S8LAtmm+/9lTy94m/Z6BfcEObsrr9N 6+/g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h68si26807792pgc.270.2019.06.05.08.15.00; Wed, 05 Jun 2019 08:15:01 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728654AbfFEPPA (ORCPT + 30 others); Wed, 5 Jun 2019 11:15:00 -0400 Received: from foss.arm.com ([217.140.101.70]:33586 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728510AbfFEPO6 (ORCPT ); Wed, 5 Jun 2019 11:14:58 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8D7F0374; Wed, 5 Jun 2019 08:14:57 -0700 (PDT) Received: from en101.cambridge.arm.com (en101.cambridge.arm.com [10.1.196.93]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AFD3E3F246; Wed, 5 Jun 2019 08:14:52 -0700 (PDT) From: Suzuki K Poulose To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, rafael@kernel.org, suzuki.poulose@arm.com, Alexander Shishkin , Andrew Lunn , Daniel Vetter , David Airlie , "David S. Miller" , devicetree@vger.kernel.org, Doug Ledford , dri-devel@lists.freedesktop.org, Florian Fainelli , Frank Rowand , Heiko Stuebner , Jason Gunthorpe , Liam Girdwood , linux-i2c@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-spi@vger.kernel.org, linux-usb@vger.kernel.org, Maarten Lankhorst , Mark Brown , Mathieu Poirier , Maxime Ripard , Oliver Neukum , Rob Herring , Sebastian Andrzej Siewior , Srinivas Kandagatla , Takashi Iwai , Wolfram Sang Subject: [PATCH 11/13] drivers: Introduce variants for bus_find_device() Date: Wed, 5 Jun 2019 16:13:48 +0100 Message-Id: <1559747630-28065-12-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559747630-28065-1-git-send-email-suzuki.poulose@arm.com> References: <1559747630-28065-1-git-send-email-suzuki.poulose@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Similar to the class_find_device_by_*() introduce the variants for bus_find_device() to automatically search for device by generic device properties. Here is the list of new helpers : bus_find_device_by_of_node bus_find_device_by_fwnode bus_find_device_by_devt bus_find_next_device While at it convert the bus_find_device_by_name to static inline reusing the generic helper to match the name. Cc: Alexander Shishkin Cc: Andrew Lunn Cc: Daniel Vetter Cc: David Airlie Cc: "David S. Miller" Cc: devicetree@vger.kernel.org Cc: Doug Ledford Cc: dri-devel@lists.freedesktop.org Cc: Florian Fainelli Cc: Frank Rowand Cc: Greg Kroah-Hartman Cc: Heiko Stuebner Cc: Jason Gunthorpe Cc: Liam Girdwood Cc: linux-i2c@vger.kernel.org Cc: linux-rockchip@lists.infradead.org Cc: linux-spi@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: Maarten Lankhorst Cc: Mark Brown Cc: Mathieu Poirier Cc: Maxime Ripard Cc: Oliver Neukum Cc: "Rafael J. Wysocki" Cc: Rob Herring Cc: Sebastian Andrzej Siewior Cc: Srinivas Kandagatla Cc: Takashi Iwai Cc: Wolfram Sang Signed-off-by: Suzuki K Poulose --- drivers/base/bus.c | 24 ------------------- include/linux/device.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 27 deletions(-) -- 2.7.4 diff --git a/drivers/base/bus.c b/drivers/base/bus.c index df3cac7..a1d1e82 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus, } EXPORT_SYMBOL_GPL(bus_find_device); -static int match_name(struct device *dev, const void *data) -{ - const char *name = data; - - return sysfs_streq(name, dev_name(dev)); -} - -/** - * bus_find_device_by_name - device iterator for locating a particular device of a specific name - * @bus: bus type - * @start: Device to begin with - * @name: name of the device to match - * - * This is similar to the bus_find_device() function above, but it handles - * searching by a name automatically, no need to write another strcmp matching - * function. - */ -struct device *bus_find_device_by_name(struct bus_type *bus, - struct device *start, const char *name) -{ - return bus_find_device(bus, start, (void *)name, match_name); -} -EXPORT_SYMBOL_GPL(bus_find_device_by_name); - /** * 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 4396edc..10de79d 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -175,9 +175,67 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, struct device *bus_find_device(struct bus_type *bus, struct device *start, const void *data, int (*match)(struct device *dev, const void *data)); -struct device *bus_find_device_by_name(struct bus_type *bus, - struct device *start, - const char *name); +/** + * bus_find_device_by_name - device iterator for locating a particular device + * of a specific name. + * @bus: bus type + * @start: Device to begin with + * @name: name of the device to match + */ +static inline struct device *bus_find_device_by_name(struct bus_type *bus, + struct device *start, + const char *name) +{ + return bus_find_device(bus, start, name, device_match_name); +} + +/** + * bus_find_device_by_of_node : device iterator for locating a particular device + * matching the of_node. + * @bus: bus type + * @np: of_node of the device to match. + */ +static inline struct device * +bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np) +{ + return bus_find_device(bus, NULL, np, device_match_of_node); +} + +/** + * bus_find_device_by_fwnode : device iterator for locating a particular device + * matching the fwnode. + * @bus: bus type + * @fwnode: fwnode of the device to match. + */ +static inline struct device * +bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode) +{ + return bus_find_device(bus, NULL, fwnode, device_match_fwnode); +} + +/** + * bus_find_device_by_devt : device iterator for locating a particular device + * matching the device type. + * @bus: bus type + * @start: device to start the search from + * @devt: device type of the device to match. + */ +static inline struct device * +bus_find_device_by_devt(struct bus_type *bus, struct device *start, dev_t devt) +{ + return bus_find_device(bus, start, &devt, device_match_devt); +} + +/** + * bus_find_next_device - Find the next device after a given device in a + * given bus. + */ +static inline struct device * +bus_find_next_device(struct bus_type *bus,struct device *cur) +{ + return bus_find_device(bus, cur, NULL, device_match_any); +} + 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,