Commit e0766ea4 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

driver core: bus: constantify the bus_find_* functions

All of the bus find and iterator functions do not modify the struct
bus_type passed to them, so mark them as constant to enforce this rule.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230208111330.439504-4-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 273afac6
...@@ -331,7 +331,7 @@ static struct device *next_device(struct klist_iter *i) ...@@ -331,7 +331,7 @@ static struct device *next_device(struct klist_iter *i)
* to retain this data, it should do so, and increment the reference * to retain this data, it should do so, and increment the reference
* count in the supplied callback. * count in the supplied callback.
*/ */
int bus_for_each_dev(struct bus_type *bus, struct device *start, int bus_for_each_dev(const struct bus_type *bus, struct device *start,
void *data, int (*fn)(struct device *, void *)) void *data, int (*fn)(struct device *, void *))
{ {
struct klist_iter i; struct klist_iter i;
...@@ -365,7 +365,7 @@ EXPORT_SYMBOL_GPL(bus_for_each_dev); ...@@ -365,7 +365,7 @@ EXPORT_SYMBOL_GPL(bus_for_each_dev);
* if it does. If the callback returns non-zero, this function will * if it does. If the callback returns non-zero, this function will
* return to the caller and not iterate over any more devices. * return to the caller and not iterate over any more devices.
*/ */
struct device *bus_find_device(struct bus_type *bus, struct device *bus_find_device(const struct bus_type *bus,
struct device *start, const void *data, struct device *start, const void *data,
int (*match)(struct device *dev, const void *data)) int (*match)(struct device *dev, const void *data))
{ {
...@@ -416,7 +416,7 @@ static struct device_driver *next_driver(struct klist_iter *i) ...@@ -416,7 +416,7 @@ static struct device_driver *next_driver(struct klist_iter *i)
* in the callback. It must also be sure to increment the refcount * in the callback. It must also be sure to increment the refcount
* so it doesn't disappear before returning to the caller. * so it doesn't disappear before returning to the caller.
*/ */
int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, int bus_for_each_drv(const struct bus_type *bus, struct device_driver *start,
void *data, int (*fn)(struct device_driver *, void *)) void *data, int (*fn)(struct device_driver *, void *))
{ {
struct klist_iter i; struct klist_iter i;
......
...@@ -149,9 +149,9 @@ int device_match_acpi_handle(struct device *dev, const void *handle); ...@@ -149,9 +149,9 @@ int device_match_acpi_handle(struct device *dev, const void *handle);
int device_match_any(struct device *dev, const void *unused); int device_match_any(struct device *dev, const void *unused);
/* iterator helpers for buses */ /* iterator helpers for buses */
int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, int bus_for_each_dev(const struct bus_type *bus, struct device *start, void *data,
int (*fn)(struct device *dev, void *data)); int (*fn)(struct device *dev, void *data));
struct device *bus_find_device(struct bus_type *bus, struct device *start, struct device *bus_find_device(const struct bus_type *bus, struct device *start,
const void *data, const void *data,
int (*match)(struct device *dev, const void *data)); int (*match)(struct device *dev, const void *data));
/** /**
...@@ -161,7 +161,7 @@ struct device *bus_find_device(struct bus_type *bus, struct device *start, ...@@ -161,7 +161,7 @@ struct device *bus_find_device(struct bus_type *bus, struct device *start,
* @start: Device to begin with * @start: Device to begin with
* @name: name of the device to match * @name: name of the device to match
*/ */
static inline struct device *bus_find_device_by_name(struct bus_type *bus, static inline struct device *bus_find_device_by_name(const struct bus_type *bus,
struct device *start, struct device *start,
const char *name) const char *name)
{ {
...@@ -175,7 +175,7 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus, ...@@ -175,7 +175,7 @@ static inline struct device *bus_find_device_by_name(struct bus_type *bus,
* @np: of_node of the device to match. * @np: of_node of the device to match.
*/ */
static inline struct device * static inline struct device *
bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np) bus_find_device_by_of_node(const struct bus_type *bus, const struct device_node *np)
{ {
return bus_find_device(bus, NULL, np, device_match_of_node); return bus_find_device(bus, NULL, np, device_match_of_node);
} }
...@@ -187,7 +187,7 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np) ...@@ -187,7 +187,7 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
* @fwnode: fwnode of the device to match. * @fwnode: fwnode of the device to match.
*/ */
static inline struct device * static inline struct device *
bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode) bus_find_device_by_fwnode(const struct bus_type *bus, const struct fwnode_handle *fwnode)
{ {
return bus_find_device(bus, NULL, fwnode, device_match_fwnode); return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
} }
...@@ -198,7 +198,7 @@ bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwno ...@@ -198,7 +198,7 @@ bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwno
* @bus: bus type * @bus: bus type
* @devt: device type of the device to match. * @devt: device type of the device to match.
*/ */
static inline struct device *bus_find_device_by_devt(struct bus_type *bus, static inline struct device *bus_find_device_by_devt(const struct bus_type *bus,
dev_t devt) dev_t devt)
{ {
return bus_find_device(bus, NULL, &devt, device_match_devt); return bus_find_device(bus, NULL, &devt, device_match_devt);
...@@ -211,7 +211,7 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus, ...@@ -211,7 +211,7 @@ static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
* @cur: device to begin the search with. * @cur: device to begin the search with.
*/ */
static inline struct device * static inline struct device *
bus_find_next_device(struct bus_type *bus,struct device *cur) bus_find_next_device(const struct bus_type *bus,struct device *cur)
{ {
return bus_find_device(bus, cur, NULL, device_match_any); return bus_find_device(bus, cur, NULL, device_match_any);
} }
...@@ -226,19 +226,19 @@ struct acpi_device; ...@@ -226,19 +226,19 @@ struct acpi_device;
* @adev: ACPI COMPANION device to match. * @adev: ACPI COMPANION device to match.
*/ */
static inline struct device * static inline struct device *
bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev) bus_find_device_by_acpi_dev(const struct bus_type *bus, const struct acpi_device *adev)
{ {
return bus_find_device(bus, NULL, adev, device_match_acpi_dev); return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
} }
#else #else
static inline struct device * static inline struct device *
bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev) bus_find_device_by_acpi_dev(const struct bus_type *bus, const void *adev)
{ {
return NULL; return NULL;
} }
#endif #endif
int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, int bus_for_each_drv(const struct bus_type *bus, struct device_driver *start,
void *data, int (*fn)(struct device_driver *, void *)); void *data, int (*fn)(struct device_driver *, void *));
void bus_sort_breadthfirst(struct bus_type *bus, void bus_sort_breadthfirst(struct bus_type *bus,
int (*compare)(const struct device *a, int (*compare)(const struct device *a,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment