History

drivers: Introduce device lookup variants by name

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.

Suzuki K Poulose committed 7 years ago

Commit 6cda08a1 parent 5f9e83212 files · +54 −106Browse files

Showing the changes to include/linux (1 of 12 files). Show all

Unified · Split

include/linux/device.h+39−3
@@ -164,6 +164,7 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter, · 163 unmodified lines
164struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);164struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
165void subsys_dev_iter_exit(struct subsys_dev_iter *iter);165void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
166 166
167int device_match_name(struct device *dev, const void *name);
167int device_match_of_node(struct device *dev, const void *np);168int device_match_of_node(struct device *dev, const void *np);
168 169
169int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,170int 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
171struct device *bus_find_device(struct bus_type *bus, struct device *start,172struct device *bus_find_device(struct bus_type *bus, struct device *start,
172 const void *data,173 const void *data,
173 int (*match)(struct device *dev, const void *data));174 int (*match)(struct device *dev, const void *data));
174struct device *bus_find_device_by_name(struct bus_type *bus,175/**
175 struct device *start,176 * bus_find_device_by_name - device iterator for locating a particular device
176 const char *name);177 * of a specific name.
178 * @bus: bus type
179 * @start: Device to begin with
180 * @name: name of the device to match
181 */
182static 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
177struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,189struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
178 struct device *hint);190 struct device *hint);
179int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,191int 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 struct device *start, const void *data,354 struct device *start, const void *data,
343 int (*match)(struct device *dev, const void *data));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 */
363static 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
345void driver_deferred_probe_add(struct device *dev);369void driver_deferred_probe_add(struct device *dev);
346int driver_deferred_probe_check_state(struct device *dev);370int driver_deferred_probe_check_state(struct device *dev);
347int driver_deferred_probe_check_state_continue(struct device *dev);371int 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 struct device *start, const void *data,495 struct device *start, const void *data,
472 int (*match)(struct device *, const void *));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 */
504static 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
474struct class_attribute {510struct class_attribute {
475 struct attribute attr;511 struct attribute attr;
476 ssize_t (*show)(struct class *class, struct class_attribute *attr,512 ssize_t (*show)(struct class *class, struct class_attribute *attr,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t