Add a helper to match the device name for device lookup. Also reuse this generic exported helper for the existing bus_find_device_by_name(). and add similar variants for driver/class.
Showing the changes to include/linux (1 of 12 files). Show all
Unified · Split
| @@ -164,6 +164,7 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter, · 163 unmodified lines | ||
| 164 | 164 | struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); |
| 165 | 165 | void subsys_dev_iter_exit(struct subsys_dev_iter *iter); |
| 166 | 166 | |
| 167 | +int device_match_name(struct device *dev, const void *name); | |
| 167 | 168 | int device_match_of_node(struct device *dev, const void *np); |
| 168 | 169 | |
| 169 | 170 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, |
| @@ -171,9 +172,20 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, · 1 unmodified line | ||
| 171 | 172 | struct device *bus_find_device(struct bus_type *bus, struct device *start, |
| 172 | 173 | const void *data, |
| 173 | 174 | int (*match)(struct device *dev, const void *data)); |
| 174 | −struct device *bus_find_device_by_name(struct bus_type *bus, | |
| 175 | − struct device *start, | |
| 176 | − const char *name); | |
| 175 | +/** | |
| 176 | + * bus_find_device_by_name - device iterator for locating a particular device | |
| 177 | + * of a specific name. | |
| 178 | + * @bus: bus type | |
| 179 | + * @start: Device to begin with | |
| 180 | + * @name: name of the device to match | |
| 181 | + */ | |
| 182 | +static inline struct device *bus_find_device_by_name(struct bus_type *bus, | |
| 183 | + struct device *start, | |
| 184 | + const char *name) | |
| 185 | +{ | |
| 186 | + return bus_find_device(bus, start, name, device_match_name); | |
| 187 | +} | |
| 188 | + | |
| 177 | 189 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, |
| 178 | 190 | struct device *hint); |
| 179 | 191 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, |
| @@ -342,6 +354,18 @@ struct device *driver_find_device(struct device_driver *drv, · 162 unmodified lines | ||
| 342 | 354 | struct device *start, const void *data, |
| 343 | 355 | int (*match)(struct device *dev, const void *data)); |
| 344 | 356 | |
| 357 | +/** | |
| 358 | + * driver_find_device_by_name - device iterator for locating a particular device | |
| 359 | + * of a specific name. | |
| 360 | + * @driver: the driver we're iterating | |
| 361 | + * @name: name of the device to match | |
| 362 | + */ | |
| 363 | +static inline struct device *driver_find_device_by_name(struct device_driver *drv, | |
| 364 | + const char *name) | |
| 365 | +{ | |
| 366 | + return driver_find_device(drv, NULL, name, device_match_name); | |
| 367 | +} | |
| 368 | + | |
| 345 | 369 | void driver_deferred_probe_add(struct device *dev); |
| 346 | 370 | int driver_deferred_probe_check_state(struct device *dev); |
| 347 | 371 | int driver_deferred_probe_check_state_continue(struct device *dev); |
| @@ -471,6 +495,18 @@ extern struct device *class_find_device(struct class *class, · 123 unmodified lines | ||
| 471 | 495 | struct device *start, const void *data, |
| 472 | 496 | int (*match)(struct device *, const void *)); |
| 473 | 497 | |
| 498 | +/** | |
| 499 | + * class_find_device_by_name - device iterator for locating a particular device | |
| 500 | + * of a specific name. | |
| 501 | + * @class: class type | |
| 502 | + * @name: name of the device to match | |
| 503 | + */ | |
| 504 | +static inline struct device *class_find_device_by_name(struct class *class, | |
| 505 | + const char *name) | |
| 506 | +{ | |
| 507 | + return class_find_device(class, NULL, name, device_match_name); | |
| 508 | +} | |
| 509 | + | |
| 474 | 510 | struct class_attribute { |
| 475 | 511 | struct attribute attr; |
| 476 | 512 | ssize_t (*show)(struct class *class, struct class_attribute *attr, |