mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08:00
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 <Jonathan.Cameron@huawei.com> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com> Link: https://lore.kernel.org/r/20250105-class_fix-v6-7-3a2f1768d4d4@quicinc.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
523c6b3ed7
commit
767b74e0d1
@@ -354,7 +354,7 @@ static struct device *next_device(struct klist_iter *i)
|
||||
* count in the supplied callback.
|
||||
*/
|
||||
int bus_for_each_dev(const struct bus_type *bus, struct device *start,
|
||||
void *data, int (*fn)(struct device *, void *))
|
||||
void *data, device_iter_t fn)
|
||||
{
|
||||
struct subsys_private *sp = bus_to_subsys(bus);
|
||||
struct klist_iter i;
|
||||
|
||||
@@ -402,7 +402,7 @@ EXPORT_SYMBOL_GPL(class_dev_iter_exit);
|
||||
* code. There's no locking restriction.
|
||||
*/
|
||||
int class_for_each_device(const struct class *class, const struct device *start,
|
||||
void *data, int (*fn)(struct device *, void *))
|
||||
void *data, device_iter_t fn)
|
||||
{
|
||||
struct subsys_private *sp = class_to_subsys(class);
|
||||
struct class_dev_iter iter;
|
||||
|
||||
@@ -3980,7 +3980,7 @@ const char *device_get_devnode(const struct device *dev,
|
||||
* other than 0, we break out and return that value.
|
||||
*/
|
||||
int device_for_each_child(struct device *parent, void *data,
|
||||
int (*fn)(struct device *dev, void *data))
|
||||
device_iter_t fn)
|
||||
{
|
||||
struct klist_iter i;
|
||||
struct device *child;
|
||||
@@ -4010,7 +4010,7 @@ EXPORT_SYMBOL_GPL(device_for_each_child);
|
||||
* other than 0, we break out and return that value.
|
||||
*/
|
||||
int device_for_each_child_reverse(struct device *parent, void *data,
|
||||
int (*fn)(struct device *dev, void *data))
|
||||
device_iter_t fn)
|
||||
{
|
||||
struct klist_iter i;
|
||||
struct device *child;
|
||||
@@ -4044,7 +4044,7 @@ EXPORT_SYMBOL_GPL(device_for_each_child_reverse);
|
||||
*/
|
||||
int device_for_each_child_reverse_from(struct device *parent,
|
||||
struct device *from, void *data,
|
||||
int (*fn)(struct device *, void *))
|
||||
device_iter_t fn)
|
||||
{
|
||||
struct klist_iter i;
|
||||
struct device *child;
|
||||
|
||||
@@ -115,7 +115,7 @@ EXPORT_SYMBOL_GPL(driver_set_override);
|
||||
* Iterate over the @drv's list of devices calling @fn for each one.
|
||||
*/
|
||||
int driver_for_each_device(struct device_driver *drv, struct device *start,
|
||||
void *data, int (*fn)(struct device *, void *))
|
||||
void *data, device_iter_t fn)
|
||||
{
|
||||
struct klist_iter i;
|
||||
struct device *dev;
|
||||
|
||||
@@ -1075,12 +1075,12 @@ void device_del(struct device *dev);
|
||||
DEFINE_FREE(device_del, struct device *, if (_T) device_del(_T))
|
||||
|
||||
int device_for_each_child(struct device *parent, void *data,
|
||||
int (*fn)(struct device *dev, void *data));
|
||||
device_iter_t fn);
|
||||
int device_for_each_child_reverse(struct device *parent, void *data,
|
||||
int (*fn)(struct device *dev, void *data));
|
||||
device_iter_t fn);
|
||||
int device_for_each_child_reverse_from(struct device *parent,
|
||||
struct device *from, void *data,
|
||||
int (*fn)(struct device *, void *));
|
||||
device_iter_t fn);
|
||||
struct device *device_find_child(struct device *parent, const void *data,
|
||||
device_match_t match);
|
||||
struct device *device_find_child_by_name(struct device *parent,
|
||||
|
||||
@@ -139,9 +139,12 @@ int device_match_acpi_dev(struct device *dev, const void *adev);
|
||||
int device_match_acpi_handle(struct device *dev, const void *handle);
|
||||
int device_match_any(struct device *dev, const void *unused);
|
||||
|
||||
/* Device iterating function type for various driver core for_each APIs */
|
||||
typedef int (*device_iter_t)(struct device *dev, void *data);
|
||||
|
||||
/* iterator helpers for buses */
|
||||
int bus_for_each_dev(const struct bus_type *bus, struct device *start, void *data,
|
||||
int (*fn)(struct device *dev, void *data));
|
||||
int bus_for_each_dev(const struct bus_type *bus, struct device *start,
|
||||
void *data, device_iter_t fn);
|
||||
struct device *bus_find_device(const struct bus_type *bus, struct device *start,
|
||||
const void *data, device_match_t match);
|
||||
/**
|
||||
|
||||
@@ -92,8 +92,8 @@ void class_dev_iter_init(struct class_dev_iter *iter, const struct class *class,
|
||||
struct device *class_dev_iter_next(struct class_dev_iter *iter);
|
||||
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));
|
||||
int class_for_each_device(const struct class *class, const struct device *start,
|
||||
void *data, device_iter_t fn);
|
||||
struct device *class_find_device(const struct class *class, const struct device *start,
|
||||
const void *data, device_match_t match);
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ void driver_remove_file(const struct device_driver *driver,
|
||||
int driver_set_override(struct device *dev, const char **override,
|
||||
const char *s, size_t len);
|
||||
int __must_check driver_for_each_device(struct device_driver *drv, struct device *start,
|
||||
void *data, int (*fn)(struct device *dev, void *));
|
||||
void *data, device_iter_t fn);
|
||||
struct device *driver_find_device(const struct device_driver *drv,
|
||||
struct device *start, const void *data,
|
||||
device_match_t match);
|
||||
|
||||
Reference in New Issue
Block a user