]> err.no Git - linux-2.6/blobdiff - drivers/base/dd.c
Driver core: Cleanup get_device_parent() in device_add() and device_move()
[linux-2.6] / drivers / base / dd.c
index b0088b0efecdd1e5395e4104d23d0fe34dbb9a0d..b0726eb6405e03b7189f3170de5e58bf09709a76 100644 (file)
@@ -11,6 +11,8 @@
  *
  *     Copyright (c) 2002-5 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
  */
@@ -23,8 +25,6 @@
 #include "base.h"
 #include "power/power.h"
 
-#define to_drv(node) container_of(node, struct device_driver, kobj.entry)
-
 
 static void driver_bound(struct device *dev)
 {
@@ -34,27 +34,27 @@ static void driver_bound(struct device *dev)
                return;
        }
 
-       pr_debug("bound device '%s' to driver '%s'\n",
-                dev->bus_id, dev->driver->name);
+       pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->bus_id,
+                __FUNCTION__, dev->driver->name);
 
        if (dev->bus)
-               blocking_notifier_call_chain(&dev->bus->bus_notifier,
+               blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
                                             BUS_NOTIFY_BOUND_DRIVER, dev);
 
-       klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices);
+       klist_add_tail(&dev->knode_driver, &dev->driver->p->klist_devices);
 }
 
 static int driver_sysfs_add(struct device *dev)
 {
        int ret;
 
-       ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj,
+       ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj,
                          kobject_name(&dev->kobj));
        if (ret == 0) {
-               ret = sysfs_create_link(&dev->kobj, &dev->driver->kobj,
+               ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj,
                                        "driver");
                if (ret)
-                       sysfs_remove_link(&dev->driver->kobj,
+                       sysfs_remove_link(&dev->driver->p->kobj,
                                        kobject_name(&dev->kobj));
        }
        return ret;
@@ -65,7 +65,7 @@ static void driver_sysfs_remove(struct device *dev)
        struct device_driver *drv = dev->driver;
 
        if (drv) {
-               sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
+               sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj));
                sysfs_remove_link(&dev->kobj, "driver");
        }
 }
@@ -102,8 +102,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
        int ret = 0;
 
        atomic_inc(&probe_count);
-       pr_debug("%s: Probing driver %s with device %s\n",
-                drv->bus->name, drv->name, dev->bus_id);
+       pr_debug("bus: '%s': %s: probing driver %s with device %s\n",
+                drv->bus->name, __FUNCTION__, drv->name, dev->bus_id);
        WARN_ON(!list_empty(&dev->devres_head));
 
        dev->driver = drv;
@@ -125,8 +125,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 
        driver_bound(dev);
        ret = 1;
-       pr_debug("%s: Bound Device %s to Driver %s\n",
-                drv->bus->name, dev->bus_id, drv->name);
+       pr_debug("bus: '%s': %s: bound device %s to driver %s\n",
+                drv->bus->name, __FUNCTION__, dev->bus_id, drv->name);
        goto done;
 
 probe_failed:
@@ -192,8 +192,8 @@ int driver_probe_device(struct device_driver * drv, struct device * dev)
        if (drv->bus->match && !drv->bus->match(dev, drv))
                goto done;
 
-       pr_debug("%s: Matched Device %s with Driver %s\n",
-                drv->bus->name, dev->bus_id, drv->name);
+       pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
+                drv->bus->name, __FUNCTION__, dev->bus_id, drv->name);
 
        ret = really_probe(dev, drv);
 
@@ -281,30 +281,21 @@ int driver_attach(struct device_driver * drv)
        return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
 }
 
-/**
- *     device_release_driver - manually detach device from driver.
- *     @dev:   device.
- *
- *     Manually detach device from driver.
- *
+/*
  *     __device_release_driver() must be called with @dev->sem held.
- *     When called for a USB interface, @dev->parent->sem must be held
- *     as well.
+ *     When called for a USB interface, @dev->parent->sem must be held as well.
  */
-
 static void __device_release_driver(struct device * dev)
 {
        struct device_driver * drv;
 
        drv = dev->driver;
        if (drv) {
-               get_driver(drv);
                driver_sysfs_remove(dev);
                sysfs_remove_link(&dev->kobj, "driver");
-               klist_remove(&dev->knode_driver);
 
                if (dev->bus)
-                       blocking_notifier_call_chain(&dev->bus->bus_notifier,
+                       blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
                                                     BUS_NOTIFY_UNBIND_DRIVER,
                                                     dev);
 
@@ -314,10 +305,17 @@ static void __device_release_driver(struct device * dev)
                        drv->remove(dev);
                devres_release_all(dev);
                dev->driver = NULL;
-               put_driver(drv);
+               klist_remove(&dev->knode_driver);
        }
 }
 
+/**
+ *     device_release_driver - manually detach device from driver.
+ *     @dev:   device.
+ *
+ *     Manually detach device from driver.
+ *     When called for a USB interface, @dev->parent->sem must be held.
+ */
 void device_release_driver(struct device * dev)
 {
        /*
@@ -340,15 +338,15 @@ void driver_detach(struct device_driver * drv)
        struct device * dev;
 
        for (;;) {
-               spin_lock(&drv->klist_devices.k_lock);
-               if (list_empty(&drv->klist_devices.k_list)) {
-                       spin_unlock(&drv->klist_devices.k_lock);
+               spin_lock(&drv->p->klist_devices.k_lock);
+               if (list_empty(&drv->p->klist_devices.k_list)) {
+                       spin_unlock(&drv->p->klist_devices.k_lock);
                        break;
                }
-               dev = list_entry(drv->klist_devices.k_list.prev,
+               dev = list_entry(drv->p->klist_devices.k_list.prev,
                                struct device, knode_driver.n_node);
                get_device(dev);
-               spin_unlock(&drv->klist_devices.k_lock);
+               spin_unlock(&drv->p->klist_devices.k_lock);
 
                if (dev->parent)        /* Needed for USB */
                        down(&dev->parent->sem);