Skip to content

Commit 767b74e

Browse files
zijun-hugregkh
authored andcommitted
driver core: Introduce device_iter_t for device iterating APIs
There are several for_each APIs which has parameter with type below: int (*fn)(struct device *dev, void *data) They iterate over various device lists and call @fn() for each device with caller provided data @*data, and they usually need to modify @*data. Give the type an dedicated typedef with advantages shown below: typedef int (*device_iter_t)(struct device *dev, void *data) - Shorter API declarations and definitions - Prevent further for_each APIs from using bad parameter type So introduce device_iter_t and apply it to various existing APIs below: bus_for_each_dev() (class|driver)_for_each_device() device_for_each_child(_reverse|_reverse_from)(). Reviewed-by: Jonathan Cameron <[email protected]> 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 523c6b3 commit 767b74e

File tree

8 files changed

+17
-14
lines changed

8 files changed

+17
-14
lines changed

drivers/base/bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static struct device *next_device(struct klist_iter *i)
354354
* count in the supplied callback.
355355
*/
356356
int bus_for_each_dev(const struct bus_type *bus, struct device *start,
357-
void *data, int (*fn)(struct device *, void *))
357+
void *data, device_iter_t fn)
358358
{
359359
struct subsys_private *sp = bus_to_subsys(bus);
360360
struct klist_iter i;

drivers/base/class.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ EXPORT_SYMBOL_GPL(class_dev_iter_exit);
402402
* code. There's no locking restriction.
403403
*/
404404
int class_for_each_device(const struct class *class, const struct device *start,
405-
void *data, int (*fn)(struct device *, void *))
405+
void *data, device_iter_t fn)
406406
{
407407
struct subsys_private *sp = class_to_subsys(class);
408408
struct class_dev_iter iter;

drivers/base/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,7 +3980,7 @@ const char *device_get_devnode(const struct device *dev,
39803980
* other than 0, we break out and return that value.
39813981
*/
39823982
int device_for_each_child(struct device *parent, void *data,
3983-
int (*fn)(struct device *dev, void *data))
3983+
device_iter_t fn)
39843984
{
39853985
struct klist_iter i;
39863986
struct device *child;
@@ -4010,7 +4010,7 @@ EXPORT_SYMBOL_GPL(device_for_each_child);
40104010
* other than 0, we break out and return that value.
40114011
*/
40124012
int device_for_each_child_reverse(struct device *parent, void *data,
4013-
int (*fn)(struct device *dev, void *data))
4013+
device_iter_t fn)
40144014
{
40154015
struct klist_iter i;
40164016
struct device *child;
@@ -4044,7 +4044,7 @@ EXPORT_SYMBOL_GPL(device_for_each_child_reverse);
40444044
*/
40454045
int device_for_each_child_reverse_from(struct device *parent,
40464046
struct device *from, void *data,
4047-
int (*fn)(struct device *, void *))
4047+
device_iter_t fn)
40484048
{
40494049
struct klist_iter i;
40504050
struct device *child;

drivers/base/driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ EXPORT_SYMBOL_GPL(driver_set_override);
115115
* Iterate over the @drv's list of devices calling @fn for each one.
116116
*/
117117
int driver_for_each_device(struct device_driver *drv, struct device *start,
118-
void *data, int (*fn)(struct device *, void *))
118+
void *data, device_iter_t fn)
119119
{
120120
struct klist_iter i;
121121
struct device *dev;

include/linux/device.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,12 +1075,12 @@ void device_del(struct device *dev);
10751075
DEFINE_FREE(device_del, struct device *, if (_T) device_del(_T))
10761076

10771077
int device_for_each_child(struct device *parent, void *data,
1078-
int (*fn)(struct device *dev, void *data));
1078+
device_iter_t fn);
10791079
int device_for_each_child_reverse(struct device *parent, void *data,
1080-
int (*fn)(struct device *dev, void *data));
1080+
device_iter_t fn);
10811081
int device_for_each_child_reverse_from(struct device *parent,
10821082
struct device *from, void *data,
1083-
int (*fn)(struct device *, void *));
1083+
device_iter_t fn);
10841084
struct device *device_find_child(struct device *parent, const void *data,
10851085
device_match_t match);
10861086
struct device *device_find_child_by_name(struct device *parent,

include/linux/device/bus.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,12 @@ int device_match_acpi_dev(struct device *dev, const void *adev);
139139
int device_match_acpi_handle(struct device *dev, const void *handle);
140140
int device_match_any(struct device *dev, const void *unused);
141141

142+
/* Device iterating function type for various driver core for_each APIs */
143+
typedef int (*device_iter_t)(struct device *dev, void *data);
144+
142145
/* iterator helpers for buses */
143-
int bus_for_each_dev(const struct bus_type *bus, struct device *start, void *data,
144-
int (*fn)(struct device *dev, void *data));
146+
int bus_for_each_dev(const struct bus_type *bus, struct device *start,
147+
void *data, device_iter_t fn);
145148
struct device *bus_find_device(const struct bus_type *bus, struct device *start,
146149
const void *data, device_match_t match);
147150
/**

include/linux/device/class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ void class_dev_iter_init(struct class_dev_iter *iter, const struct class *class,
9292
struct device *class_dev_iter_next(struct class_dev_iter *iter);
9393
void class_dev_iter_exit(struct class_dev_iter *iter);
9494

95-
int class_for_each_device(const struct class *class, const struct device *start, void *data,
96-
int (*fn)(struct device *dev, void *data));
95+
int class_for_each_device(const struct class *class, const struct device *start,
96+
void *data, device_iter_t fn);
9797
struct device *class_find_device(const struct class *class, const struct device *start,
9898
const void *data, device_match_t match);
9999

include/linux/device/driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void driver_remove_file(const struct device_driver *driver,
154154
int driver_set_override(struct device *dev, const char **override,
155155
const char *s, size_t len);
156156
int __must_check driver_for_each_device(struct device_driver *drv, struct device *start,
157-
void *data, int (*fn)(struct device *dev, void *));
157+
void *data, device_iter_t fn);
158158
struct device *driver_find_device(const struct device_driver *drv,
159159
struct device *start, const void *data,
160160
device_match_t match);

0 commit comments

Comments
 (0)