]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/base/core.c
[PATCH] m68k: cleanup generic irq names
[linux-2.6-omap-h63xx.git] / drivers / base / core.c
index 252cf403f891216831bee67923abbc4cef9423a3..27c2176895dee0ccb5efd195d008f8a0333a0904 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);
@@ -319,10 +336,17 @@ int device_add(struct device *dev)
                dev->devt_attr = attr;
        }
 
-       if (dev->class)
+       if (dev->class) {
+               sysfs_create_link(&dev->kobj, &dev->class->subsys.kset.kobj,
+                                 "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)))
                goto PMError;
        if ((error = bus_add_device(dev)))
@@ -332,10 +356,18 @@ int device_add(struct device *dev)
        if (parent)
                klist_add_tail(&dev->knode_parent, &parent->klist_children);
 
+       if (dev->class) {
+               /* tie the class to the device */
+               down(&dev->class->sem);
+               list_add_tail(&dev->node, &dev->class->devices);
+               up(&dev->class->sem);
+       }
+
        /* notify platform of device entry */
        if (platform_notify)
                platform_notify(dev);
  Done:
+       kfree(class_name);
        put_device(dev);
        return error;
  BusError:
@@ -417,13 +449,23 @@ 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);
        if (dev->devt_attr)
                device_remove_file(dev, dev->devt_attr);
-       if (dev->class)
+       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);
+               down(&dev->class->sem);
+               list_del_init(&dev->node);
+               up(&dev->class->sem);
+       }
        device_remove_file(dev, &dev->uevent_attr);
 
        /* Notify the platform of the removal, in case they
@@ -569,11 +611,6 @@ struct device *device_create(struct class *class, struct device *parent,
        if (retval)
                goto error;
 
-       /* tie the class to the device */
-       down(&class->sem);
-       list_add_tail(&dev->node, &class->devices);
-       up(&class->sem);
-
        return dev;
 
 error:
@@ -604,9 +641,7 @@ void device_destroy(struct class *class, dev_t devt)
        }
        up(&class->sem);
 
-       if (dev) {
-               list_del_init(&dev->node);
+       if (dev)
                device_unregister(dev);
-       }
 }
 EXPORT_SYMBOL_GPL(device_destroy);