]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/base/core.c
PM: Remove destroy_suspended_device()
[linux-2.6-omap-h63xx.git] / drivers / base / core.c
index f09dde3b1e27398339f85d045567fc685c2b18bc..0262fc7c45fcbc2673d3a3d687973228aa9ee538 100644 (file)
 #include <linux/kdev_t.h>
 #include <linux/notifier.h>
 #include <linux/genhd.h>
+#include <linux/kallsyms.h>
 #include <asm/semaphore.h>
 
 #include "base.h"
 #include "power/power.h"
 
-int (*platform_notify)(struct device * dev) = NULL;
-int (*platform_notify_remove)(struct device * dev) = NULL;
+int (*platform_notify)(struct device *dev) = NULL;
+int (*platform_notify_remove)(struct device *dev) = NULL;
 
-/*
- * sysfs bindings for devices.
- */
+#ifdef CONFIG_BLOCK
+static inline int device_is_not_partition(struct device *dev)
+{
+       return !(dev->type == &part_type);
+}
+#else
+static inline int device_is_not_partition(struct device *dev)
+{
+       return 1;
+}
+#endif
 
 /**
  * dev_driver_string - Return a device's driver name, if at all possible
@@ -51,24 +60,27 @@ EXPORT_SYMBOL(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)
 
-static ssize_t
-dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
+static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
+                            char *buf)
 {
-       struct device_attribute * dev_attr = to_dev_attr(attr);
-       struct device * dev = to_dev(kobj);
+       struct device_attribute *dev_attr = to_dev_attr(attr);
+       struct device *dev = to_dev(kobj);
        ssize_t ret = -EIO;
 
        if (dev_attr->show)
                ret = dev_attr->show(dev, dev_attr, buf);
+       if (ret >= (ssize_t)PAGE_SIZE) {
+               print_symbol("dev_attr_show: %s returned bad count\n",
+                               (unsigned long)dev_attr->show);
+       }
        return ret;
 }
 
-static ssize_t
-dev_attr_store(struct kobject * kobj, struct attribute * attr,
-              const char * buf, size_t count)
+static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
+                             const char *buf, size_t count)
 {
-       struct device_attribute * dev_attr = to_dev_attr(attr);
-       struct device * dev = to_dev(kobj);
+       struct device_attribute *dev_attr = to_dev_attr(attr);
+       struct device *dev = to_dev(kobj);
        ssize_t ret = -EIO;
 
        if (dev_attr->store)
@@ -90,9 +102,9 @@ static struct sysfs_ops dev_sysfs_ops = {
  *     reaches 0. We forward the call to the device's release
  *     method, which should handle actually freeing the structure.
  */
-static void device_release(struct kobject * kobj)
+static void device_release(struct kobject *kobj)
 {
-       struct device * dev = to_dev(kobj);
+       struct device *dev = to_dev(kobj);
 
        if (dev->release)
                dev->release(dev);
@@ -101,8 +113,8 @@ static void device_release(struct kobject * kobj)
        else if (dev->class && dev->class->dev_release)
                dev->class->dev_release(dev);
        else {
-               printk(KERN_ERR "Device '%s' does not have a release() function, "
-                       "it is broken and must be fixed.\n",
+               printk(KERN_ERR "Device '%s' does not have a release() "
+                       "function, it is broken and must be fixed.\n",
                        dev->bus_id);
                WARN_ON(1);
        }
@@ -185,7 +197,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
                add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name);
 
                if (dev->driver)
-                       add_uevent_var(env, "PHYSDEVDRIVER=%s", dev->driver->name);
+                       add_uevent_var(env, "PHYSDEVDRIVER=%s",
+                                      dev->driver->name);
        }
 #endif
 
@@ -327,7 +340,8 @@ static int device_add_groups(struct device *dev,
                        error = sysfs_create_group(&dev->kobj, groups[i]);
                        if (error) {
                                while (--i >= 0)
-                                       sysfs_remove_group(&dev->kobj, groups[i]);
+                                       sysfs_remove_group(&dev->kobj,
+                                                          groups[i]);
                                break;
                        }
                }
@@ -406,35 +420,28 @@ static struct device_attribute devt_attr =
 /* kset to create /sys/devices/  */
 struct kset *devices_kset;
 
-
 /**
- *     device_create_file - create sysfs attribute file for device.
- *     @dev:   device.
- *     @attr:  device attribute descriptor.
+ * device_create_file - create sysfs attribute file for device.
+ * @dev: device.
+ * @attr: device attribute descriptor.
  */
-
-int device_create_file(struct device * dev, struct device_attribute * attr)
+int device_create_file(struct device *dev, struct device_attribute *attr)
 {
        int error = 0;
-       if (get_device(dev)) {
+       if (dev)
                error = sysfs_create_file(&dev->kobj, &attr->attr);
-               put_device(dev);
-       }
        return error;
 }
 
 /**
- *     device_remove_file - remove sysfs attribute file.
- *     @dev:   device.
- *     @attr:  device attribute descriptor.
+ * device_remove_file - remove sysfs attribute file.
+ * @dev: device.
+ * @attr: device attribute descriptor.
  */
-
-void device_remove_file(struct device * dev, struct device_attribute * attr)
+void device_remove_file(struct device *dev, struct device_attribute *attr)
 {
-       if (get_device(dev)) {
+       if (dev)
                sysfs_remove_file(&dev->kobj, &attr->attr);
-               put_device(dev);
-       }
 }
 
 /**
@@ -510,18 +517,16 @@ static void klist_children_put(struct klist_node *n)
        put_device(dev);
 }
 
-
 /**
- *     device_initialize - init device structure.
- *     @dev:   device.
+ * device_initialize - init device structure.
+ * @dev: device.
  *
- *     This prepares the device for use by other layers,
- *     including adding it to the device hierarchy.
- *     It is the first half of device_register(), if called by
- *     that, though it can also be called separately, so one
- *     may use @dev's fields (e.g. the refcount).
+ * This prepares the device for use by other layers,
+ * including adding it to the device hierarchy.
+ * It is the first half of device_register(), if called by
+ * that, though it can also be called separately, so one
+ * may use @dev's fields (e.g. the refcount).
  */
-
 void device_initialize(struct device *dev)
 {
        dev->kobj.kset = devices_kset;
@@ -621,7 +626,8 @@ static struct kobject *get_device_parent(struct device *dev,
 static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
 {
        /* see if we live in a "glue" directory */
-       if (!dev->class || glue_dir->kset != &dev->class->class_dirs)
+       if (!glue_dir || !dev->class ||
+           glue_dir->kset != &dev->class->class_dirs)
                return;
 
        kobject_put(glue_dir);
@@ -656,14 +662,14 @@ static int device_add_class_symlinks(struct device *dev)
 #ifdef CONFIG_SYSFS_DEPRECATED
        /* stacked class devices need a symlink in the class directory */
        if (dev->kobj.parent != &dev->class->subsys.kobj &&
-           dev->type != &part_type) {
+           device_is_not_partition(dev)) {
                error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
                                          dev->bus_id);
                if (error)
                        goto out_subsys;
        }
 
-       if (dev->parent && dev->type != &part_type) {
+       if (dev->parent && device_is_not_partition(dev)) {
                struct device *parent = dev->parent;
                char *class_name;
 
@@ -692,11 +698,11 @@ static int device_add_class_symlinks(struct device *dev)
        return 0;
 
 out_device:
-       if (dev->parent && dev->type != &part_type)
+       if (dev->parent && device_is_not_partition(dev))
                sysfs_remove_link(&dev->kobj, "device");
 out_busid:
        if (dev->kobj.parent != &dev->class->subsys.kobj &&
-           dev->type != &part_type)
+           device_is_not_partition(dev))
                sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
 #else
        /* link in the class directory pointing to the device */
@@ -705,7 +711,7 @@ out_busid:
        if (error)
                goto out_subsys;
 
-       if (dev->parent && dev->type != &part_type) {
+       if (dev->parent && device_is_not_partition(dev)) {
                error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
                                          "device");
                if (error)
@@ -729,7 +735,7 @@ static void device_remove_class_symlinks(struct device *dev)
                return;
 
 #ifdef CONFIG_SYSFS_DEPRECATED
-       if (dev->parent && dev->type != &part_type) {
+       if (dev->parent && device_is_not_partition(dev)) {
                char *class_name;
 
                class_name = make_class_name(dev->class->name, &dev->kobj);
@@ -741,10 +747,10 @@ static void device_remove_class_symlinks(struct device *dev)
        }
 
        if (dev->kobj.parent != &dev->class->subsys.kobj &&
-           dev->type != &part_type)
+           device_is_not_partition(dev))
                sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
 #else
-       if (dev->parent && dev->type != &part_type)
+       if (dev->parent && device_is_not_partition(dev))
                sysfs_remove_link(&dev->kobj, "device");
 
        sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
@@ -754,15 +760,15 @@ static void device_remove_class_symlinks(struct device *dev)
 }
 
 /**
- *     device_add - add device to device hierarchy.
- *     @dev:   device.
+ * device_add - add device to device hierarchy.
+ * @dev: device.
  *
- *     This is part 2 of device_register(), though may be called
- *     separately _iff_ device_initialize() has been called separately.
+ * This is part 2 of device_register(), though may be called
+ * separately _iff_ device_initialize() has been called separately.
  *
- *     This adds it to the kobject hierarchy via kobject_add(), adds it
- *     to the global and sibling lists for the device, then
- *     adds it to the other relevant subsystems of the driver model.
+ * This adds it to the kobject hierarchy via kobject_add(), adds it
+ * to the global and sibling lists for the device, then
+ * adds it to the other relevant subsystems of the driver model.
  */
 int device_add(struct device *dev)
 {
@@ -770,17 +776,10 @@ int device_add(struct device *dev)
        struct class_interface *class_intf;
        int error;
 
-       error = pm_sleep_lock();
-       if (error) {
-               dev_warn(dev, "Suspicious %s during suspend\n", __FUNCTION__);
-               dump_stack();
-               return error;
-       }
-
        dev = get_device(dev);
        if (!dev || !strlen(dev->bus_id)) {
                error = -EINVAL;
-               goto Error;
+               goto Done;
        }
 
        pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
@@ -818,13 +817,12 @@ int device_add(struct device *dev)
        error = device_add_attrs(dev);
        if (error)
                goto AttrsError;
-       error = dpm_sysfs_add(dev);
-       if (error)
-               goto PMError;
-       device_pm_add(dev);
        error = bus_add_device(dev);
        if (error)
                goto BusError;
+       error = device_pm_add(dev);
+       if (error)
+               goto PMError;
        kobject_uevent(&dev->kobj, KOBJ_ADD);
        bus_attach_device(dev);
        if (parent)
@@ -843,12 +841,10 @@ int device_add(struct device *dev)
        }
  Done:
        put_device(dev);
-       pm_sleep_unlock();
        return error;
- BusError:
-       device_pm_remove(dev);
-       dpm_sysfs_remove(dev);
  PMError:
+       bus_remove_device(dev);
+ BusError:
        if (dev->bus)
                blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
                                             BUS_NOTIFY_DEL_DEVICE, dev);
@@ -870,70 +866,63 @@ int device_add(struct device *dev)
        goto Done;
 }
 
-
 /**
- *     device_register - register a device with the system.
- *     @dev:   pointer to the device structure
+ * device_register - register a device with the system.
+ * @dev: pointer to the device structure
  *
- *     This happens in two clean steps - initialize the device
- *     and add it to the system. The two steps can be called
- *     separately, but this is the easiest and most common.
- *     I.e. you should only call the two helpers separately if
- *     have a clearly defined need to use and refcount the device
- *     before it is added to the hierarchy.
+ * This happens in two clean steps - initialize the device
+ * and add it to the system. The two steps can be called
+ * separately, but this is the easiest and most common.
+ * I.e. you should only call the two helpers separately if
+ * have a clearly defined need to use and refcount the device
+ * before it is added to the hierarchy.
  */
-
 int device_register(struct device *dev)
 {
        device_initialize(dev);
        return device_add(dev);
 }
 
-
 /**
- *     get_device - increment reference count for device.
- *     @dev:   device.
+ * get_device - increment reference count for device.
+ * @dev: device.
  *
- *     This simply forwards the call to kobject_get(), though
- *     we do take care to provide for the case that we get a NULL
- *     pointer passed in.
+ * This simply forwards the call to kobject_get(), though
+ * we do take care to provide for the case that we get a NULL
+ * pointer passed in.
  */
-
-struct device * get_device(struct device * dev)
+struct device *get_device(struct device *dev)
 {
        return dev ? to_dev(kobject_get(&dev->kobj)) : NULL;
 }
 
-
 /**
- *     put_device - decrement reference count.
- *     @dev:   device in question.
+ * put_device - decrement reference count.
+ * @dev: device in question.
  */
-void put_device(struct device * dev)
+void put_device(struct device *dev)
 {
        /* might_sleep(); */
        if (dev)
                kobject_put(&dev->kobj);
 }
 
-
 /**
- *     device_del - delete device from system.
- *     @dev:   device.
+ * device_del - delete device from system.
+ * @dev: device.
  *
- *     This is the first part of the device unregistration
- *     sequence. This removes the device from the lists we control
- *     from here, has it removed from the other driver model
- *     subsystems it was added to in device_add(), and removes it
- *     from the kobject hierarchy.
+ * This is the first part of the device unregistration
+ * sequence. This removes the device from the lists we control
+ * from here, has it removed from the other driver model
+ * subsystems it was added to in device_add(), and removes it
+ * from the kobject hierarchy.
  *
- *     NOTE: this should be called manually _iff_ device_add() was
- *     also called manually.
+ * NOTE: this should be called manually _iff_ device_add() was
+ * also called manually.
  */
-
-void device_del(struct device * dev)
+void device_del(struct device *dev)
 {
-       struct device * parent = dev->parent;
+       struct device *parent = dev->parent;
        struct class_interface *class_intf;
 
        device_pm_remove(dev);
@@ -979,47 +968,46 @@ void device_del(struct device * dev)
 }
 
 /**
- *     device_unregister - unregister device from system.
- *     @dev:   device going away.
+ * device_unregister - unregister device from system.
+ * @dev: device going away.
  *
- *     We do this in two parts, like we do device_register(). First,
- *     we remove it from all the subsystems with device_del(), then
- *     we decrement the reference count via put_device(). If that
- *     is the final reference count, the device will be cleaned up
- *     via device_release() above. Otherwise, the structure will
- *     stick around until the final reference to the device is dropped.
+ * We do this in two parts, like we do device_register(). First,
+ * we remove it from all the subsystems with device_del(), then
+ * we decrement the reference count via put_device(). If that
+ * is the final reference count, the device will be cleaned up
+ * via device_release() above. Otherwise, the structure will
+ * stick around until the final reference to the device is dropped.
  */
-void device_unregister(struct device * dev)
+void device_unregister(struct device *dev)
 {
        pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
        device_del(dev);
        put_device(dev);
 }
 
-
-static struct device * next_device(struct klist_iter * i)
+static struct device *next_device(struct klist_iter *i)
 {
-       struct klist_node * n = klist_next(i);
+       struct klist_node *n = klist_next(i);
        return n ? container_of(n, struct device, knode_parent) : NULL;
 }
 
 /**
- *     device_for_each_child - device child iterator.
- *     @parent: parent struct device.
- *     @data:  data for the callback.
- *     @fn:    function to be called for each device.
+ * device_for_each_child - device child iterator.
+ * @parent: parent struct device.
+ * @data: data for the callback.
+ * @fn: function to be called for each device.
  *
- *     Iterate over @parent's child devices, and call @fn for each,
- *     passing it @data.
+ * Iterate over @parent's child devices, and call @fn for each,
+ * passing it @data.
  *
- *     We check the return of @fn each time. If it returns anything
- *     other than 0, we break out and return that value.
+ * We check the return of @fn each time. If it returns anything
+ * other than 0, we break out and return that value.
  */
-int device_for_each_child(struct device * parent, void * data,
-                    int (*fn)(struct device *, void *))
+int device_for_each_child(struct device *parent, void *data,
+                         int (*fn)(struct device *dev, void *data))
 {
        struct klist_iter i;
-       struct device * child;
+       struct device *child;
        int error = 0;
 
        klist_iter_init(&parent->klist_children, &i);
@@ -1044,8 +1032,8 @@ int device_for_each_child(struct device * parent, void * data,
  * current device can be obtained, this function will return to the caller
  * and not iterate over any more devices.
  */
-struct device * device_find_child(struct device *parent, void *data,
-                                 int (*match)(struct device *, void *))
+struct device *device_find_child(struct device *parent, void *data,
+                                int (*match)(struct device *dev, void *data))
 {
        struct klist_iter i;
        struct device *child;
@@ -1148,25 +1136,11 @@ error:
 }
 EXPORT_SYMBOL_GPL(device_create);
 
-/**
- * find_device - finds a device that was created with device_create()
- * @class: pointer to the struct class that this device was registered with
- * @devt: the dev_t of the device that was previously registered
- */
-static struct device *find_device(struct class *class, dev_t devt)
+static int __match_devt(struct device *dev, void *data)
 {
-       struct device *dev = NULL;
-       struct device *dev_tmp;
+       dev_t *devt = data;
 
-       down(&class->sem);
-       list_for_each_entry(dev_tmp, &class->devices, node) {
-               if (dev_tmp->devt == devt) {
-                       dev = dev_tmp;
-                       break;
-               }
-       }
-       up(&class->sem);
-       return dev;
+       return dev->devt == *devt;
 }
 
 /**
@@ -1181,39 +1155,14 @@ void device_destroy(struct class *class, dev_t devt)
 {
        struct device *dev;
 
-       dev = find_device(class, devt);
-       if (dev)
+       dev = class_find_device(class, &devt, __match_devt);
+       if (dev) {
+               put_device(dev);
                device_unregister(dev);
+       }
 }
 EXPORT_SYMBOL_GPL(device_destroy);
 
-#ifdef CONFIG_PM_SLEEP
-/**
- * destroy_suspended_device - asks the PM core to remove a suspended device
- * @class: pointer to the struct class that this device was registered with
- * @devt: the dev_t of the device that was previously registered
- *
- * This call notifies the PM core of the necessity to unregister a suspended
- * device created with a call to device_create() (devices cannot be
- * unregistered directly while suspended, since the PM core holds their
- * semaphores at that time).
- *
- * It can only be called within the scope of a system sleep transition.  In
- * practice this means it has to be directly or indirectly invoked either by
- * a suspend or resume method, or by the PM core (e.g. via
- * disable_nonboot_cpus() or enable_nonboot_cpus()).
- */
-void destroy_suspended_device(struct class *class, dev_t devt)
-{
-       struct device *dev;
-
-       dev = find_device(class, devt);
-       if (dev)
-               device_pm_schedule_removal(dev);
-}
-EXPORT_SYMBOL_GPL(destroy_suspended_device);
-#endif /* CONFIG_PM_SLEEP */
-
 /**
  * device_rename - renames a device
  * @dev: the pointer to the struct device to be renamed
@@ -1312,8 +1261,7 @@ static int device_move_class_links(struct device *dev,
                                          class_name);
                if (error)
                        sysfs_remove_link(&dev->kobj, "device");
-       }
-       else
+       } else
                error = 0;
 out:
        kfree(class_name);
@@ -1344,7 +1292,7 @@ int device_move(struct device *dev, struct device *new_parent)
                return -EINVAL;
 
        new_parent = get_device(new_parent);
-       new_parent_kobj = get_device_parent (dev, new_parent);
+       new_parent_kobj = get_device_parent(dev, new_parent);
 
        pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id,
                 __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>");
@@ -1390,7 +1338,7 @@ EXPORT_SYMBOL_GPL(device_move);
  */
 void device_shutdown(void)
 {
-       struct device * dev, *devn;
+       struct device *dev, *devn;
 
        list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
                                kobj.entry) {