VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / base / driver.c
index 0236ba3..735bd17 100644 (file)
@@ -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 <linux/string.h>
 #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);