drivers/base: Introduce device_match_t for device finding APIs
authorZijun Hu <quic_zijuhu@quicinc.com>
Tue, 13 Aug 2024 14:19:32 +0000 (22:19 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 Sep 2024 10:48:51 +0000 (12:48 +0200)
There are several drivers/base APIs for finding a specific device, and
they currently use the following good type for the @match parameter:
int (*match)(struct device *dev, const void *data)

Since these operations do not modify the caller-provided @*data, this
type is worthy of a dedicated typedef:
typedef int (*device_match_t)(struct device *dev, const void *data)

Advantages of using device_match_t:
 - Shorter API declarations and definitions
 - Prevent further APIs from using a bad type for @match

So introduce device_match_t and apply it to the existing
(bus|class|driver|auxiliary)_find_device() APIs.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Link: https://lore.kernel.org/r/20240813-dev_match_api-v3-1-6c6878a99b9f@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/auxiliary.c
drivers/base/bus.c
drivers/base/class.c
drivers/base/driver.c
include/linux/auxiliary_bus.h
include/linux/device/bus.h
include/linux/device/class.h
include/linux/device/driver.h

index 54b92839e05cedd72b7eea6e91783b30caebf18d..7823888af4f68472627e9c31f296ebda1ee7b565 100644 (file)
@@ -352,7 +352,7 @@ EXPORT_SYMBOL_GPL(__auxiliary_device_add);
  */
 struct auxiliary_device *auxiliary_find_device(struct device *start,
                                               const void *data,
-                                              int (*match)(struct device *dev, const void *data))
+                                              device_match_t match)
 {
        struct device *dev;
 
index abf090ace8339af7ebf6826a6d12d9e5f58b860f..657c93c38b0dc2a2247e5f482fadd3a9376a58e8 100644 (file)
@@ -391,7 +391,7 @@ EXPORT_SYMBOL_GPL(bus_for_each_dev);
  */
 struct device *bus_find_device(const struct bus_type *bus,
                               struct device *start, const void *data,
-                              int (*match)(struct device *dev, const void *data))
+                              device_match_t match)
 {
        struct subsys_private *sp = bus_to_subsys(bus);
        struct klist_iter i;
index 7b38fdf8e1d78e95bf8f44ab4cf1cc48f317ec4f..ae22fa992c049d38fd0a279321b71a38213fa9f5 100644 (file)
@@ -433,8 +433,7 @@ EXPORT_SYMBOL_GPL(class_for_each_device);
  * code.  There's no locking restriction.
  */
 struct device *class_find_device(const struct class *class, const struct device *start,
-                                const void *data,
-                                int (*match)(struct device *, const void *))
+                                const void *data, device_match_t match)
 {
        struct subsys_private *sp = class_to_subsys(class);
        struct class_dev_iter iter;
index 88c6fd1f1992f5b6bc1c3e207b6fb44391d4ab66..b4eb5b89c4ee7bc35458fc75730b16a6d1e804d3 100644 (file)
@@ -150,7 +150,7 @@ EXPORT_SYMBOL_GPL(driver_for_each_device);
  */
 struct device *driver_find_device(const struct device_driver *drv,
                                  struct device *start, const void *data,
-                                 int (*match)(struct device *dev, const void *data))
+                                 device_match_t match)
 {
        struct klist_iter i;
        struct device *dev;
index 662b8ae54b6aad7c00436268bb40d54677bfb229..31762324bcc9b55810b3d4e4da1ea7eaf8920c02 100644 (file)
@@ -271,6 +271,6 @@ void auxiliary_driver_unregister(struct auxiliary_driver *auxdrv);
 
 struct auxiliary_device *auxiliary_find_device(struct device *start,
                                               const void *data,
-                                              int (*match)(struct device *dev, const void *data));
+                                              device_match_t match);
 
 #endif /* _AUXILIARY_BUS_H_ */
index 807831d6bf0f1504d1aa3040f3d05e1e094b6d96..cdc4757217f9bb4b36b5c3b8a48bab45737e44c5 100644 (file)
@@ -126,6 +126,9 @@ struct bus_attribute {
 int __must_check bus_create_file(const struct bus_type *bus, struct bus_attribute *attr);
 void bus_remove_file(const struct bus_type *bus, struct bus_attribute *attr);
 
+/* Matching function type for drivers/base APIs to find a specific device */
+typedef int (*device_match_t)(struct device *dev, const void *data);
+
 /* Generic device matching functions that all busses can use to match with */
 int device_match_name(struct device *dev, const void *name);
 int device_match_of_node(struct device *dev, const void *np);
@@ -139,8 +142,7 @@ int device_match_any(struct device *dev, const void *unused);
 int bus_for_each_dev(const struct bus_type *bus, struct device *start, void *data,
                     int (*fn)(struct device *dev, void *data));
 struct device *bus_find_device(const struct bus_type *bus, struct device *start,
-                              const void *data,
-                              int (*match)(struct device *dev, const void *data));
+                              const void *data, device_match_t match);
 /**
  * bus_find_device_by_name - device iterator for locating a particular device
  * of a specific name.
index c576b49c55c22ea0684fc480ba1e00ed64351944..518c9c83d64bdf85bb5607cea6ea640884ec3460 100644 (file)
@@ -95,7 +95,7 @@ void class_dev_iter_exit(struct class_dev_iter *iter);
 int class_for_each_device(const struct class *class, const struct device *start, void *data,
                          int (*fn)(struct device *dev, void *data));
 struct device *class_find_device(const struct class *class, const struct device *start,
-                                const void *data, int (*match)(struct device *, const void *));
+                                const void *data, device_match_t match);
 
 /**
  * class_find_device_by_name - device iterator for locating a particular device
index 1fc8b68786de57e910c16df4910ed4c2161039e8..5c04b8e3833b995f9fd4d65b8732b3dfce2eba7e 100644 (file)
@@ -157,7 +157,7 @@ int __must_check driver_for_each_device(struct device_driver *drv, struct device
                                        void *data, int (*fn)(struct device *dev, void *));
 struct device *driver_find_device(const struct device_driver *drv,
                                  struct device *start, const void *data,
-                                 int (*match)(struct device *dev, const void *data));
+                                 device_match_t match);
 
 /**
  * driver_find_device_by_name - device iterator for locating a particular device