Revert "sysdev: fix prototype for memory_sysdev_class show/store functions"
[safe/jmp/linux-2.6] / drivers / base / bus.c
index 0f0a504..c0c5a43 100644 (file)
@@ -198,7 +198,7 @@ static ssize_t driver_bind(struct device_driver *drv,
        int err = -ENODEV;
 
        dev = bus_find_device_by_name(bus, NULL, buf);
-       if (dev && dev->driver == NULL) {
+       if (dev && dev->driver == NULL && driver_match_device(drv, dev)) {
                if (dev->parent)        /* Needed for USB */
                        down(&dev->parent->sem);
                down(&dev->sem);
@@ -279,7 +279,7 @@ static struct device *next_device(struct klist_iter *i)
  *
  * NOTE: The device that returns a non-zero value is not retained
  * in any way, nor is its refcount incremented. If the caller needs
- * to retain this data, it should do, and increment the reference
+ * to retain this data, it should do so, and increment the reference
  * count in the supplied callback.
  */
 int bus_for_each_dev(struct bus_type *bus, struct device *start,
@@ -459,8 +459,9 @@ static inline void remove_deprecated_bus_links(struct device *dev) { }
  * bus_add_device - add device to bus
  * @dev: device being added
  *
+ * - Add device's bus attributes.
+ * - Create links to device's bus.
  * - Add the device to its bus's list of devices.
- * - Create link to device's bus.
  */
 int bus_add_device(struct device *dev)
 {
@@ -483,6 +484,7 @@ int bus_add_device(struct device *dev)
                error = make_deprecated_bus_links(dev);
                if (error)
                        goto out_deprecated;
+               klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices);
        }
        return 0;
 
@@ -498,24 +500,19 @@ out_put:
 }
 
 /**
- * bus_attach_device - add device to bus
- * @dev: device tried to attach to a driver
+ * bus_probe_device - probe drivers for a new device
+ * @dev: device to probe
  *
- * - Add device to bus's list of devices.
- * - Try to attach to driver.
+ * - Automatically probe for a driver if the bus allows it.
  */
-void bus_attach_device(struct device *dev)
+void bus_probe_device(struct device *dev)
 {
        struct bus_type *bus = dev->bus;
-       int ret = 0;
+       int ret;
 
-       if (bus) {
-               if (bus->p->drivers_autoprobe)
-                       ret = device_attach(dev);
+       if (bus && bus->p->drivers_autoprobe) {
+               ret = device_attach(dev);
                WARN_ON(ret < 0);
-               if (ret >= 0)
-                       klist_add_tail(&dev->p->knode_bus,
-                                      &bus->p->klist_devices);
        }
 }
 
@@ -692,17 +689,23 @@ int bus_add_driver(struct device_driver *drv)
                printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n",
                        __func__, drv->name);
        }
-       error = add_bind_files(drv);
-       if (error) {
-               /* Ditto */
-               printk(KERN_ERR "%s: add_bind_files(%s) failed\n",
-                       __func__, drv->name);
+
+       if (!drv->suppress_bind_attrs) {
+               error = add_bind_files(drv);
+               if (error) {
+                       /* Ditto */
+                       printk(KERN_ERR "%s: add_bind_files(%s) failed\n",
+                               __func__, drv->name);
+               }
        }
 
        kobject_uevent(&priv->kobj, KOBJ_ADD);
-       return error;
+       return 0;
+
 out_unregister:
        kobject_put(&priv->kobj);
+       kfree(drv->p);
+       drv->p = NULL;
 out_put_bus:
        bus_put(bus);
        return error;
@@ -721,7 +724,8 @@ void bus_remove_driver(struct device_driver *drv)
        if (!drv->bus)
                return;
 
-       remove_bind_files(drv);
+       if (!drv->suppress_bind_attrs)
+               remove_bind_files(drv);
        driver_remove_attrs(drv->bus, drv);
        driver_remove_file(drv, &driver_attr_uevent);
        klist_remove(&drv->p->knode_bus);
@@ -942,6 +946,7 @@ bus_uevent_fail:
        kset_unregister(&bus->p->subsys);
        kfree(bus->p);
 out:
+       bus->p = NULL;
        return retval;
 }
 EXPORT_SYMBOL_GPL(bus_register);
@@ -963,6 +968,7 @@ void bus_unregister(struct bus_type *bus)
        bus_remove_file(bus, &bus_attr_uevent);
        kset_unregister(&bus->p->subsys);
        kfree(bus->p);
+       bus->p = NULL;
 }
 EXPORT_SYMBOL_GPL(bus_unregister);