Release 4.11 drivers/base/driver.c
/*
* driver.c - centralized device driver management
*
* Copyright (c) 2002-3 Patrick Mochel
* Copyright (c) 2002-3 Open Source Development Labs
* Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
* Copyright (c) 2007 Novell Inc.
*
* This file is released under the GPLv2
*
*/
#include <linux/device.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include "base.h"
static struct device *next_device(struct klist_iter *i)
{
struct klist_node *n = klist_next(i);
struct device *dev = NULL;
struct device_private *dev_prv;
if (n) {
dev_prv = to_device_private_driver(n);
dev = dev_prv->device;
}
return dev;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Greg Kroah-Hartman | 30 | 52.63% | 2 | 66.67% |
Patrick Mochel | 27 | 47.37% | 1 | 33.33% |
Total | 57 | 100.00% | 3 | 100.00% |
/**
* 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, int (*fn)(struct device *, void *))
{
struct klist_iter i;
struct device *dev;
int error = 0;
if (!drv)
return -EINVAL;
klist_iter_init_node(&drv->p->klist_devices, &i,
start ? &start->p->knode_driver : NULL);
while ((dev = next_device(&i)) && !error)
error = fn(dev, data);
klist_iter_exit(&i);
return error;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Patrick Mochel | 109 | 96.46% | 2 | 50.00% |
Greg Kroah-Hartman | 4 | 3.54% | 2 | 50.00% |
Total | 113 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL_GPL(driver_for_each_device);
/**
* 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(struct device_driver *drv,
struct device *start, void *data,
int (*match)(struct device *dev, void *data))
{
struct klist_iter i;
struct device *dev;
if (!drv || !drv->p)
return NULL;
klist_iter_init_node(&drv->p->klist_devices, &i,
(start ? &start->p->knode_driver : NULL));
while ((dev = next_device(&i)))
if (match(dev, data) && get_device(dev))
break;
klist_iter_exit(&i);
return dev;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Cornelia Huck | 109 | 90.08% | 1 | 16.67% |
Greg Kroah-Hartman | 7 | 5.79% | 4 | 66.67% |
Hiroshi Doyu | 5 | 4.13% | 1 | 16.67% |
Total | 121 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL_GPL(driver_find_device);
/**
* driver_create_file - create sysfs file for driver.
* @drv: driver.
* @attr: driver attribute descriptor.
*/
int driver_create_file(struct device_driver *drv,
const struct driver_attribute *attr)
{
int error;
if (drv)
error = sysfs_create_file(&drv->p->kobj, &attr->attr);
else
error = -EINVAL;
return error;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Patrick Mochel | 46 | 93.88% | 1 | 33.33% |
Greg Kroah-Hartman | 2 | 4.08% | 1 | 33.33% |
Phil Carmody | 1 | 2.04% | 1 | 33.33% |
Total | 49 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(driver_create_file);
/**
* driver_remove_file - remove sysfs file for driver.
* @drv: driver.
* @attr: driver attribute descriptor.
*/
void driver_remove_file(struct device_driver *drv,
const struct driver_attribute *attr)
{
if (drv)
sysfs_remove_file(&drv->p->kobj, &attr->attr);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Patrick Mochel | 32 | 91.43% | 1 | 33.33% |
Greg Kroah-Hartman | 2 | 5.71% | 1 | 33.33% |
Phil Carmody | 1 | 2.86% | 1 | 33.33% |
Total | 35 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(driver_remove_file);
int driver_add_groups(struct device_driver *drv,
const struct attribute_group **groups)
{
return sysfs_create_groups(&drv->p->kobj, groups);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Cornelia Huck | 25 | 83.33% | 1 | 25.00% |
Greg Kroah-Hartman | 4 | 13.33% | 2 | 50.00% |
David Brownell | 1 | 3.33% | 1 | 25.00% |
Total | 30 | 100.00% | 4 | 100.00% |
void driver_remove_groups(struct device_driver *drv,
const struct attribute_group **groups)
{
sysfs_remove_groups(&drv->p->kobj, groups);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Cornelia Huck | 25 | 86.21% | 1 | 25.00% |
Greg Kroah-Hartman | 3 | 10.34% | 2 | 50.00% |
David Brownell | 1 | 3.45% | 1 | 25.00% |
Total | 29 | 100.00% | 4 | 100.00% |
/**
* 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;
BUG_ON(!drv->bus->p);
if ((drv->bus->probe && drv->probe) ||
(drv->bus->remove && drv->remove) ||
(drv->bus->shutdown && drv->shutdown))
printk(KERN_WARNING "Driver '%s' needs updating - please use "
"bus_type methods\n", drv->name);
other = driver_find(drv->name, drv->bus);
if (other) {
printk(KERN_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);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Russell King | 47 | 28.48% | 1 | 8.33% |
Stas Sergeev | 39 | 23.64% | 2 | 16.67% |
Cornelia Huck | 35 | 21.21% | 1 | 8.33% |
Sebastian Ott | 17 | 10.30% | 2 | 16.67% |
Patrick Mochel | 15 | 9.09% | 4 | 33.33% |
Dave Young | 10 | 6.06% | 1 | 8.33% |
Greg Kroah-Hartman | 2 | 1.21% | 1 | 8.33% |
Total | 165 | 100.00% | 12 | 100.00% |
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);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Kay Sievers | 20 | 45.45% | 1 | 20.00% |
Patrick Mochel | 15 | 34.09% | 3 | 60.00% |
Cornelia Huck | 9 | 20.45% | 1 | 20.00% |
Total | 44 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL_GPL(driver_unregister);
/**
* driver_find - locate driver on a bus by its name.
* @name: name of the driver.
* @bus: bus to scan for the driver.
*
* Call kset_find_obj() to iterate over list of drivers on
* a bus to find driver by name. Return driver if found.
*
* This routine provides no locking to prevent the driver it returns
* from being unregistered or unloaded while the caller is using it.
* The caller is responsible for preventing this.
*/
struct device_driver *driver_find(const char *name, struct bus_type *bus)
{
struct kobject *k = kset_find_obj(bus->p->drivers_kset, name);
struct driver_private *priv;
if (k) {
/* Drop reference added by kset_find_obj() */
kobject_put(k);
priv = to_driver(k);
return priv->driver;
}
return NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Torokhov | 41 | 63.08% | 1 | 20.00% |
Greg Kroah-Hartman | 18 | 27.69% | 3 | 60.00% |
Alan Stern | 6 | 9.23% | 1 | 20.00% |
Total | 65 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL_GPL(driver_find);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Patrick Mochel | 259 | 33.55% | 9 | 24.32% |
Cornelia Huck | 208 | 26.94% | 2 | 5.41% |
Greg Kroah-Hartman | 104 | 13.47% | 11 | 29.73% |
Russell King | 47 | 6.09% | 1 | 2.70% |
Dmitry Torokhov | 45 | 5.83% | 1 | 2.70% |
Stas Sergeev | 39 | 5.05% | 2 | 5.41% |
Kay Sievers | 20 | 2.59% | 1 | 2.70% |
Sebastian Ott | 17 | 2.20% | 2 | 5.41% |
Dave Young | 10 | 1.30% | 1 | 2.70% |
Alan Stern | 7 | 0.91% | 1 | 2.70% |
Hiroshi Doyu | 5 | 0.65% | 1 | 2.70% |
Matthew Wilcox | 3 | 0.39% | 1 | 2.70% |
Tejun Heo | 3 | 0.39% | 1 | 2.70% |
Phil Carmody | 2 | 0.26% | 1 | 2.70% |
David Brownell | 2 | 0.26% | 1 | 2.70% |
Randy Dunlap | 1 | 0.13% | 1 | 2.70% |
Total | 772 | 100.00% | 37 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.