svn commit: r297776 - in head/sys: kern sys
John Baldwin
jhb at FreeBSD.org
Sun Apr 10 05:05:04 UTC 2016
Author: jhb
Date: Sun Apr 10 05:05:02 2016
New Revision: 297776
URL: https://svnweb.freebsd.org/changeset/base/297776
Log:
Add a function to lookup a device_t object by name.
This just walks the global list of devices looking for one with the
requested name. The one use case outside of devctl2's implementation
is for DDB commands that wish to lookup devices by name.
Modified:
head/sys/kern/subr_bus.c
head/sys/sys/bus.h
Modified: head/sys/kern/subr_bus.c
==============================================================================
--- head/sys/kern/subr_bus.c Sun Apr 10 04:16:34 2016 (r297775)
+++ head/sys/kern/subr_bus.c Sun Apr 10 05:05:02 2016 (r297776)
@@ -5125,6 +5125,18 @@ bus_free_resource(device_t dev, int type
return (bus_release_resource(dev, type, rman_get_rid(r), r));
}
+device_t
+device_lookup_by_name(const char *name)
+{
+ device_t dev;
+
+ TAILQ_FOREACH(dev, &bus_data_devices, devlink) {
+ if (dev->nameunit != NULL && strcmp(dev->nameunit, name) == 0)
+ return (dev);
+ }
+ return (NULL);
+}
+
/*
* /dev/devctl2 implementation. The existing /dev/devctl device has
* implicit semantics on open, so it could not be reused for this.
@@ -5145,12 +5157,10 @@ find_device(struct devreq *req, device_t
* Second, try to find an attached device whose name matches
* 'name'.
*/
- TAILQ_FOREACH(dev, &bus_data_devices, devlink) {
- if (dev->nameunit != NULL &&
- strcmp(dev->nameunit, req->dr_name) == 0) {
- *devp = dev;
- return (0);
- }
+ dev = device_lookup_by_name(req->dr_name);
+ if (dev != NULL) {
+ *devp = dev;
+ return (0);
}
/* Finally, give device enumerators a chance. */
Modified: head/sys/sys/bus.h
==============================================================================
--- head/sys/sys/bus.h Sun Apr 10 04:16:34 2016 (r297775)
+++ head/sys/sys/bus.h Sun Apr 10 05:05:02 2016 (r297776)
@@ -524,6 +524,7 @@ int device_is_attached(device_t dev); /*
int device_is_enabled(device_t dev);
int device_is_suspended(device_t dev);
int device_is_quiet(device_t dev);
+device_t device_lookup_by_name(const char *name);
int device_print_prettyname(device_t dev);
int device_printf(device_t dev, const char *, ...) __printflike(2, 3);
int device_probe(device_t dev);
More information about the svn-src-head
mailing list