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
164164 struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
165165 void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
166166
167+int device_match_name(struct device *dev, const void *name);
167168 int device_match_of_node(struct device *dev, const void *np);
168169
169170 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
171172 struct device *bus_find_device(struct bus_type *bus, struct device *start,
172173 const void *data,
173174 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+
177189 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
178190 struct device *hint);
179191 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
342354 struct device *start, const void *data,
343355 int (*match)(struct device *dev, const void *data));
344356
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+
345369 void driver_deferred_probe_add(struct device *dev);
346370 int driver_deferred_probe_check_state(struct device *dev);
347371 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
471495 struct device *start, const void *data,
472496 int (*match)(struct device *, const void *));
473497
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+
474510 struct class_attribute {
475511 struct attribute attr;
476512 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