if (n) {
dev_prv = to_device_private_driver(n);
dev = dev_prv->device;
} return dev;
}
/** * driver_set_override() - Helper to set or clear driver override. * @dev: Device to change * @override: Address of string to change (e.g. &device->driver_override); * The contents will be freed and hold newly allocated override. * @s: NUL-terminated string, new driver name to force a match, pass empty * string to clear it ("" or "\n", where the latter is only for sysfs * interface). * @len: length of @s * * Helper to set or clear driver override in a device, intended for the cases * when the driver_override field is allocated by driver/bus code. * * Returns: 0 on success or a negative error code on failure.
*/ int driver_set_override(struct device *dev, constchar **override, constchar *s, size_t len)
{ constchar *new, *old; char *cp;
if (!override || !s) return -EINVAL;
/* * The stored value will be used in sysfs show callback (sysfs_emit()), * which has a length limit of PAGE_SIZE and adds a trailing newline. * Thus we can store one character less to avoid truncation during sysfs * show.
*/ if (len >= (PAGE_SIZE - 1)) return -EINVAL;
/* * Compute the real length of the string in case userspace sends us a * bunch of \0 characters like python likes to do.
*/
len = strlen(s);
if (!len) { /* Empty string passed - clear override */
device_lock(dev);
old = *override;
*override = NULL;
device_unlock(dev);
kfree(old);
return 0;
}
cp = strnchr(s, len, '\n'); if (cp)
len = cp - s;
new = kstrndup(s, len, GFP_KERNEL); if (!new) return -ENOMEM;
/** * driver_for_each_device - Iterator for devices bound to a driver. * @drv: Driver we're iterating. * @start: Device to begin with * @data: Data to pass to the callback. * @fn: Function to call for each device. * * Iterate over the @drv's list of devices calling @fn for each one.
*/ int driver_for_each_device(struct device_driver *drv, struct device *start, void *data, device_iter_t fn)
{ struct klist_iter i; struct device *dev; int error = 0;
/** * driver_find_device - device iterator for locating a particular device. * @drv: The device's driver * @start: Device to begin with * @data: Data to pass to match function * @match: Callback function to check device * * This is similar to the driver_for_each_device() function above, but * it returns a reference to a device that is 'found' for later use, as * determined by the @match callback. * * The callback should return 0 if the device doesn't match and non-zero * if it does. If the callback returns non-zero, this function will * return to the caller and not iterate over any more devices.
*/ struct device *driver_find_device(conststruct device_driver *drv, struct device *start, constvoid *data,
device_match_t match)
{ struct klist_iter i; struct device *dev;
/** * driver_register - register driver with bus * @drv: driver to register * * We pass off most of the work to the bus_add_driver() call, * since most of the things we have to do deal with the bus * structures.
*/ int driver_register(struct device_driver *drv)
{ int ret; struct device_driver *other;
if (!bus_is_registered(drv->bus)) {
pr_err("Driver '%s' was unable to register with bus_type '%s' because the bus was not initialized.\n",
drv->name, drv->bus->name); return -EINVAL;
}
other = driver_find(drv->name, drv->bus); if (other) {
pr_err("Error: Driver '%s' is already registered, " "aborting...\n", drv->name); return -EBUSY;
}
ret = bus_add_driver(drv); if (ret) return ret;
ret = driver_add_groups(drv, drv->groups); if (ret) {
bus_remove_driver(drv); return ret;
}
kobject_uevent(&drv->p->kobj, KOBJ_ADD);
deferred_probe_extend_timeout();
return ret;
}
EXPORT_SYMBOL_GPL(driver_register);
/** * driver_unregister - remove driver from system. * @drv: driver. * * Again, we pass off most of the work to the bus-level call.
*/ void driver_unregister(struct device_driver *drv)
{ if (!drv || !drv->p) {
WARN(1, "Unexpected driver unregister!\n"); return;
}
driver_remove_groups(drv, drv->groups);
bus_remove_driver(drv);
}
EXPORT_SYMBOL_GPL(driver_unregister);
Messung V0.5
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.