Skip to content

Commit b45ed06

Browse files
zijun-hugregkh
authored andcommitted
drivers/base: Introduce device_match_t for device finding APIs
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f0e5311 commit b45ed06

File tree

8 files changed

+11
-10
lines changed

8 files changed

+11
-10
lines changed

drivers/base/auxiliary.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ EXPORT_SYMBOL_GPL(__auxiliary_device_add);
352352
*/
353353
struct auxiliary_device *auxiliary_find_device(struct device *start,
354354
const void *data,
355-
int (*match)(struct device *dev, const void *data))
355+
device_match_t match)
356356
{
357357
struct device *dev;
358358

drivers/base/bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ EXPORT_SYMBOL_GPL(bus_for_each_dev);
391391
*/
392392
struct device *bus_find_device(const struct bus_type *bus,
393393
struct device *start, const void *data,
394-
int (*match)(struct device *dev, const void *data))
394+
device_match_t match)
395395
{
396396
struct subsys_private *sp = bus_to_subsys(bus);
397397
struct klist_iter i;

drivers/base/class.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ EXPORT_SYMBOL_GPL(class_for_each_device);
433433
* code. There's no locking restriction.
434434
*/
435435
struct device *class_find_device(const struct class *class, const struct device *start,
436-
const void *data,
437-
int (*match)(struct device *, const void *))
436+
const void *data, device_match_t match)
438437
{
439438
struct subsys_private *sp = class_to_subsys(class);
440439
struct class_dev_iter iter;

drivers/base/driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ EXPORT_SYMBOL_GPL(driver_for_each_device);
150150
*/
151151
struct device *driver_find_device(const struct device_driver *drv,
152152
struct device *start, const void *data,
153-
int (*match)(struct device *dev, const void *data))
153+
device_match_t match)
154154
{
155155
struct klist_iter i;
156156
struct device *dev;

include/linux/auxiliary_bus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,6 @@ void auxiliary_driver_unregister(struct auxiliary_driver *auxdrv);
271271

272272
struct auxiliary_device *auxiliary_find_device(struct device *start,
273273
const void *data,
274-
int (*match)(struct device *dev, const void *data));
274+
device_match_t match);
275275

276276
#endif /* _AUXILIARY_BUS_H_ */

include/linux/device/bus.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ struct bus_attribute {
126126
int __must_check bus_create_file(const struct bus_type *bus, struct bus_attribute *attr);
127127
void bus_remove_file(const struct bus_type *bus, struct bus_attribute *attr);
128128

129+
/* Matching function type for drivers/base APIs to find a specific device */
130+
typedef int (*device_match_t)(struct device *dev, const void *data);
131+
129132
/* Generic device matching functions that all busses can use to match with */
130133
int device_match_name(struct device *dev, const void *name);
131134
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);
139142
int bus_for_each_dev(const struct bus_type *bus, struct device *start, void *data,
140143
int (*fn)(struct device *dev, void *data));
141144
struct device *bus_find_device(const struct bus_type *bus, struct device *start,
142-
const void *data,
143-
int (*match)(struct device *dev, const void *data));
145+
const void *data, device_match_t match);
144146
/**
145147
* bus_find_device_by_name - device iterator for locating a particular device
146148
* of a specific name.

include/linux/device/class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void class_dev_iter_exit(struct class_dev_iter *iter);
9595
int class_for_each_device(const struct class *class, const struct device *start, void *data,
9696
int (*fn)(struct device *dev, void *data));
9797
struct device *class_find_device(const struct class *class, const struct device *start,
98-
const void *data, int (*match)(struct device *, const void *));
98+
const void *data, device_match_t match);
9999

100100
/**
101101
* class_find_device_by_name - device iterator for locating a particular device

include/linux/device/driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ int __must_check driver_for_each_device(struct device_driver *drv, struct device
157157
void *data, int (*fn)(struct device *dev, void *));
158158
struct device *driver_find_device(const struct device_driver *drv,
159159
struct device *start, const void *data,
160-
int (*match)(struct device *dev, const void *data));
160+
device_match_t match);
161161

162162
/**
163163
* driver_find_device_by_name - device iterator for locating a particular device

0 commit comments

Comments
 (0)