]> err.no Git - linux-2.6/blobdiff - drivers/base/core.c
[PATCH] I2C: i2c-piix4: Document the IBM problem more clearly
[linux-2.6] / drivers / base / core.c
index cc8bb97427d018bfcf76a55522c71a9a9c6d68da..d0f84ff78776f6c6765ea297cdda587cbd1b238c 100644 (file)
@@ -29,6 +29,22 @@ int (*platform_notify_remove)(struct device * dev) = NULL;
  * sysfs bindings for devices.
  */
 
+/**
+ * dev_driver_string - Return a device's driver name, if at all possible
+ * @dev: struct device to get the name of
+ *
+ * Will return the device's driver's name if it is bound to a device.  If
+ * the device is not bound to a device, it will return the name of the bus
+ * it is attached to.  If it is not attached to a bus either, an empty
+ * string will be returned.
+ */
+const char *dev_driver_string(struct device *dev)
+{
+       return dev->driver ? dev->driver->name :
+                       (dev->bus ? dev->bus->name : "");
+}
+EXPORT_SYMBOL_GPL(dev_driver_string);
+
 #define to_dev(obj) container_of(obj, struct device, kobj)
 #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
 
@@ -273,6 +289,7 @@ void device_initialize(struct device *dev)
 int device_add(struct device *dev)
 {
        struct device *parent = NULL;
+       char *class_name = NULL;
        int error = -EINVAL;
 
        dev = get_device(dev);
@@ -324,6 +341,10 @@ int device_add(struct device *dev)
                                  "subsystem");
                sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
                                  dev->bus_id);
+
+               sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device");
+               class_name = make_class_name(dev->class->name, &dev->kobj);
+               sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name);
        }
 
        if ((error = device_pm_add(dev)))
@@ -339,6 +360,7 @@ int device_add(struct device *dev)
        if (platform_notify)
                platform_notify(dev);
  Done:
+       kfree(class_name);
        put_device(dev);
        return error;
  BusError:
@@ -420,6 +442,7 @@ void put_device(struct device * dev)
 void device_del(struct device * dev)
 {
        struct device * parent = dev->parent;
+       char *class_name = NULL;
 
        if (parent)
                klist_del(&dev->knode_parent);
@@ -428,6 +451,10 @@ void device_del(struct device * dev)
        if (dev->class) {
                sysfs_remove_link(&dev->kobj, "subsystem");
                sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);
+               class_name = make_class_name(dev->class->name, &dev->kobj);
+               sysfs_remove_link(&dev->kobj, "device");
+               sysfs_remove_link(&dev->parent->kobj, class_name);
+               kfree(class_name);
        }
        device_remove_file(dev, &dev->uevent_attr);