From patchwork Fri Jun 14 17:54:05 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: 166885 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2352694ilk; Fri, 14 Jun 2019 10:55:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPwRnCrGljQZvvvIASqqXOeM1Yui5bUeWwdZyNJz40oNgVfLS1QIlblANUB01JZEtgfOWe X-Received: by 2002:a63:e54d:: with SMTP id z13mr36778176pgj.132.1560534909756; Fri, 14 Jun 2019 10:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534909; cv=none; d=google.com; s=arc-20160816; b=Gj6WsSgxG+fR/6iZ5VmZG36wjev52Np4+aavjp7BO8MwQv8Faxsu7ZQ8ENAijlp6G1 QjhCTqgRi59vb1VBq+n87DvHMcabrJmcEwKCXENKy/pcclOIpv2JJBRB2s7/b5LEQlKN xA9+6XIlTGZFiHdE1oDSl4MjfbOSQpDgVxsvxUMBYLKmeojA1RRNtbU2+463T6DjSnSB 44MpaIFWM91C0qZSz7wG0jBiwjuqJ5H7xlW427YcAipyN8ZnV+8QyfovmkrdILaxWGt4 r2b7msCtYQDiZ8vJgkSCLpVwUUu8lO3T3qR6N1RFzZIMuJ0knJuT9irbEm8wzlMuICP2 pDjg== 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=zWrn72NEPIaq9uHfMY9JsitT/U6NIhl9BpjU4fepj+8=; b=azVJFew7SFyionTGXkEZRhdqFfSIj/KkS+IQqpJMqVXgFPLJzEnn1XIkxoLH4wq34b a0nkPyKywTf7XJTImoQcevT7k49LNI3bRpFumwcXIOPcbTvZnO2LtfWNyGbMDC7T67Fq xncqRYi7WB6xgp/gplXMSa7i2C0l9X5BEXSSrCxl9VFJyYrCCC9PQPG9FdlwxLpo4rFT izICUqDdGHYNSlZ5p+UT3uUDLdSZdEY+d5w2Btqtl1J3RM0ELrBBoJw7kYOvCcy8sbdD 6ZkkPgVeqptULQD37mJWBUROgXRw0hkGpYeAOI9zqOEeNA73qFoSX84iiImxpSZ6bw67 vcZA== 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 a20si3109760pgw.306.2019.06.14.10.55.09; Fri, 14 Jun 2019 10:55:09 -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 S1727487AbfFNRzI (ORCPT + 17 others); Fri, 14 Jun 2019 13:55:08 -0400 Received: from foss.arm.com ([217.140.110.172]:39448 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727434AbfFNRzH (ORCPT ); Fri, 14 Jun 2019 13:55:07 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3123E346; Fri, 14 Jun 2019 10:55:06 -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 302813F718; Fri, 14 Jun 2019 10:55:03 -0700 (PDT) From: Suzuki K Poulose To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, rafael@kernel.org, suzuki.poulose@arm.com, Alessandro Zummo , Alexander Aring , Alexander Shishkin , Alexandre Belloni , Arnd Bergmann , Dan Murphy , Harald Freudenberger , Heikki Krogerus , Heiko Carstens , Jacek Anaszewski , Lee Jones , linux-leds@vger.kernel.org, linux-rtc@vger.kernel.org, linux-usb@vger.kernel.org, linux-wpan@vger.kernel.org, Martin Schwidefsky , Maxime Coquelin , Pavel Machek , Peter Oberparleiter , Stefan Schmidt , "Rafael J. Wysocki" Subject: [PATCH v2 10/28] drivers: Add generic helper to match by name Date: Fri, 14 Jun 2019 18:54:05 +0100 Message-Id: <1560534863-15115-11-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560534863-15115-1-git-send-email-suzuki.poulose@arm.com> References: <1560534863-15115-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 Add a helper to match the device name. Also reuse this generic exported helper for bus_find_device_by_name(). This will also be used to add similar interface for (driver/class)_find_device() Cc: Alessandro Zummo Cc: Alexander Aring Cc: Alexander Shishkin Cc: Alexandre Belloni Cc: Arnd Bergmann Cc: Dan Murphy Cc: Greg Kroah-Hartman Cc: Harald Freudenberger Cc: Heikki Krogerus Cc: Heiko Carstens Cc: Jacek Anaszewski Cc: Lee Jones Cc: linux-leds@vger.kernel.org Cc: linux-rtc@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: linux-wpan@vger.kernel.org Cc: Martin Schwidefsky Cc: Maxime Coquelin Cc: Pavel Machek Cc: Peter Oberparleiter Cc: "Rafael J. Wysocki" Cc: Stefan Schmidt Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Signed-off-by: Suzuki K Poulose --- drivers/base/bus.c | 24 ------------------------ drivers/base/core.c | 6 ++++++ include/linux/device.h | 18 +++++++++++++++--- 3 files changed, 21 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/drivers/base/core.c b/drivers/base/core.c index 597095b..5724f93 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3352,3 +3352,9 @@ int device_match_acpi_dev(struct device *dev, const void *adev) return ACPI_COMPANION(dev) == adev; } EXPORT_SYMBOL(device_match_acpi_dev); + +int device_match_name(struct device *dev, const void *name) +{ + return sysfs_streq(dev_name(dev), name); +} +EXPORT_SYMBOL_GPL(device_match_name); diff --git a/include/linux/device.h b/include/linux/device.h index a03b50d..b9b82b7 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -167,15 +167,27 @@ int device_match_of_node(struct device *dev, const void *np); int device_match_fwnode(struct device *dev, const void *fwnode); int device_match_devt(struct device *dev, const void *pdevt); int device_match_acpi_dev(struct device *dev, const void *adev); +int device_match_name(struct device *dev, const void *name); int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, int (*fn)(struct device *dev, 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); +} + 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,