X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=drivers%2Fbase%2Fdriver.c;h=735bd1702c40fed1006d7add8941d4bb86310db4;hb=9bf4aaab3e101692164d49b7ca357651eb691cb6;hp=0236ba33542b9dbde06ef6e1f6f9846d510fb321;hpb=db216c3d5e4c040e557a50f8f5d35d5c415e8c1c;p=linux-2.6.git diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 0236ba335..735bd1702 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -3,7 +3,7 @@ * * Copyright (c) 2002-3 Patrick Mochel * Copyright (c) 2002-3 Open Source Development Labs - * + * * This file is released under the GPLv2 * */ @@ -15,8 +15,8 @@ #include #include "base.h" -#define to_dev(node) container_of(node,struct device,driver_list) -#define to_drv(obj) container_of(obj,struct device_driver,kobj) +#define to_dev(node) container_of(node, struct device, driver_list) +#define to_drv(obj) container_of(obj, struct device_driver, kobj) /** * driver_create_file - create sysfs file for driver. @@ -28,7 +28,7 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att { int error; if (get_driver(drv)) { - error = sysfs_create_file(&drv->kobj,&attr->attr); + error = sysfs_create_file(&drv->kobj, &attr->attr); put_driver(drv); } else error = -EINVAL; @@ -45,7 +45,7 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr) { if (get_driver(drv)) { - sysfs_remove_file(&drv->kobj,&attr->attr); + sysfs_remove_file(&drv->kobj, &attr->attr); put_driver(drv); } } @@ -76,7 +76,7 @@ void put_driver(struct device_driver * drv) * @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 + * since most of the things we have to do deal with the bus * structures. * * The one interesting aspect is that we initialize @drv->unload_sem @@ -99,8 +99,8 @@ int driver_register(struct device_driver * drv) * * Though, once that is done, we attempt to take @drv->unload_sem. * This will block until the driver refcount reaches 0, and it is - * released. Only modular drivers will call this function, and we - * have to guarantee that it won't complete, letting the driver + * released. Only modular drivers will call this function, and we + * have to guarantee that it won't complete, letting the driver * unload until all references are gone. */ @@ -111,10 +111,29 @@ void driver_unregister(struct device_driver * drv) up(&drv->unload_sem); } +/** + * 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. + * + * Note that kset_find_obj increments driver's reference count. + */ +struct device_driver *driver_find(const char *name, struct bus_type *bus) +{ + struct kobject *k = kset_find_obj(&bus->drivers, name); + if (k) + return to_drv(k); + return NULL; +} + EXPORT_SYMBOL(driver_register); EXPORT_SYMBOL(driver_unregister); EXPORT_SYMBOL(get_driver); EXPORT_SYMBOL(put_driver); +EXPORT_SYMBOL(driver_find); EXPORT_SYMBOL(driver_create_file); EXPORT_SYMBOL(driver_remove_file);