lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1560534863-15115-11-git-send-email-suzuki.poulose@arm.com>
Date:   Fri, 14 Jun 2019 18:54:05 +0100
From:   Suzuki K Poulose <suzuki.poulose@....com>
To:     linux-kernel@...r.kernel.org
Cc:     gregkh@...uxfoundation.org, rafael@...nel.org,
        suzuki.poulose@....com, Alessandro Zummo <a.zummo@...ertech.it>,
        Alexander Aring <alex.aring@...il.com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Alexandre Belloni <alexandre.belloni@...tlin.com>,
        Arnd Bergmann <arnd@...db.de>, Dan Murphy <dmurphy@...com>,
        Harald Freudenberger <freude@...ux.ibm.com>,
        Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
        Heiko Carstens <heiko.carstens@...ibm.com>,
        Jacek Anaszewski <jacek.anaszewski@...il.com>,
        Lee Jones <lee.jones@...aro.org>, linux-leds@...r.kernel.org,
        linux-rtc@...r.kernel.org, linux-usb@...r.kernel.org,
        linux-wpan@...r.kernel.org,
        Martin Schwidefsky <schwidefsky@...ibm.com>,
        Maxime Coquelin <mcoquelin.stm32@...il.com>,
        Pavel Machek <pavel@....cz>,
        Peter Oberparleiter <oberpar@...ux.ibm.com>,
        Stefan Schmidt <stefan@...enfreihafen.org>,
        "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>
Subject: [PATCH v2 10/28] drivers: Add generic helper to match by name

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 <a.zummo@...ertech.it>
Cc: Alexander Aring <alex.aring@...il.com>
Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc: Alexandre Belloni <alexandre.belloni@...tlin.com>
Cc: Arnd Bergmann <arnd@...db.de>
Cc: Dan Murphy <dmurphy@...com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Harald Freudenberger <freude@...ux.ibm.com>
Cc: Heikki Krogerus <heikki.krogerus@...ux.intel.com>
Cc: Heiko Carstens <heiko.carstens@...ibm.com>
Cc: Jacek Anaszewski <jacek.anaszewski@...il.com>
Cc: Lee Jones <lee.jones@...aro.org>
Cc: linux-leds@...r.kernel.org
Cc: linux-rtc@...r.kernel.org
Cc: linux-usb@...r.kernel.org
Cc: linux-wpan@...r.kernel.org
Cc: Martin Schwidefsky <schwidefsky@...ibm.com>
Cc: Maxime Coquelin <mcoquelin.stm32@...il.com>
Cc: Pavel Machek <pavel@....cz>
Cc: Peter Oberparleiter <oberpar@...ux.ibm.com>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>
Cc: Stefan Schmidt <stefan@...enfreihafen.org>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@....com>
---
 drivers/base/bus.c     | 24 ------------------------
 drivers/base/core.c    |  6 ++++++
 include/linux/device.h | 18 +++++++++++++++---
 3 files changed, 21 insertions(+), 27 deletions(-)

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,
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ