X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=drivers%2Fbase%2Fsys.c;h=0d903909af7e5366126baaa049d35c5ea26fe6b5;hb=cfed440997f2d02900022a3a97600f78b3b18e5b;hp=40fc14f035402ec70de718977e309932dce7b576;hpb=9800794ac11d4646384b3a310dfd1fe2eed577bf;p=safe%2Fjmp%2Flinux-2.6 diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 40fc14f..0d90390 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "base.h" @@ -30,10 +31,10 @@ static ssize_t -sysdev_show(struct kobject * kobj, struct attribute * attr, char * buffer) +sysdev_show(struct kobject *kobj, struct attribute *attr, char *buffer) { - struct sys_device * sysdev = to_sysdev(kobj); - struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); + struct sys_device *sysdev = to_sysdev(kobj); + struct sysdev_attribute *sysdev_attr = to_sysdev_attr(attr); if (sysdev_attr->show) return sysdev_attr->show(sysdev, sysdev_attr, buffer); @@ -42,11 +43,11 @@ sysdev_show(struct kobject * kobj, struct attribute * attr, char * buffer) static ssize_t -sysdev_store(struct kobject * kobj, struct attribute * attr, - const char * buffer, size_t count) +sysdev_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count) { - struct sys_device * sysdev = to_sysdev(kobj); - struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); + struct sys_device *sysdev = to_sysdev(kobj); + struct sysdev_attribute *sysdev_attr = to_sysdev_attr(attr); if (sysdev_attr->store) return sysdev_attr->store(sysdev, sysdev_attr, buffer, count); @@ -63,13 +64,13 @@ static struct kobj_type ktype_sysdev = { }; -int sysdev_create_file(struct sys_device * s, struct sysdev_attribute * a) +int sysdev_create_file(struct sys_device *s, struct sysdev_attribute *a) { return sysfs_create_file(&s->kobj, &a->attr); } -void sysdev_remove_file(struct sys_device * s, struct sysdev_attribute * a) +void sysdev_remove_file(struct sys_device *s, struct sysdev_attribute *a) { sysfs_remove_file(&s->kobj, &a->attr); } @@ -84,7 +85,7 @@ EXPORT_SYMBOL_GPL(sysdev_remove_file); static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr, char *buffer) { - struct sysdev_class * class = to_sysdev_class(kobj); + struct sysdev_class *class = to_sysdev_class(kobj); struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr); if (class_attr->show) @@ -95,8 +96,8 @@ static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr, static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr, const char *buffer, size_t count) { - struct sysdev_class * class = to_sysdev_class(kobj); - struct sysdev_class_attribute * class_attr = to_sysdev_class_attr(attr); + struct sysdev_class *class = to_sysdev_class(kobj); + struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr); if (class_attr->store) return class_attr->store(class, buffer, count); @@ -128,8 +129,10 @@ EXPORT_SYMBOL_GPL(sysdev_class_remove_file); static struct kset *system_kset; -int sysdev_class_register(struct sysdev_class * cls) +int sysdev_class_register(struct sysdev_class *cls) { + int retval; + pr_debug("Registering sysdev class '%s'\n", cls->name); INIT_LIST_HEAD(&cls->drivers); @@ -137,11 +140,15 @@ int sysdev_class_register(struct sysdev_class * cls) cls->kset.kobj.parent = &system_kset->kobj; cls->kset.kobj.ktype = &ktype_sysdev_class; cls->kset.kobj.kset = system_kset; - kobject_set_name(&cls->kset.kobj, cls->name); + + retval = kobject_set_name(&cls->kset.kobj, "%s", cls->name); + if (retval) + return retval; + return kset_register(&cls->kset); } -void sysdev_class_unregister(struct sysdev_class * cls) +void sysdev_class_unregister(struct sysdev_class *cls) { pr_debug("Unregistering sysdev class '%s'\n", kobject_name(&cls->kset.kobj)); @@ -168,19 +175,16 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) int err = 0; if (!cls) { - printk(KERN_WARNING "sysdev: invalid class passed to " + WARN(1, KERN_WARNING "sysdev: invalid class passed to " "sysdev_driver_register!\n"); - WARN_ON(1); return -EINVAL; } /* Check whether this driver has already been added to a class. */ - if (drv->entry.next && !list_empty(&drv->entry)) { - printk(KERN_WARNING "sysdev: class %s: driver (%p) has already" + if (drv->entry.next && !list_empty(&drv->entry)) + WARN(1, KERN_WARNING "sysdev: class %s: driver (%p) has already" " been registered to a class, something is wrong, but " "will forge on!\n", cls->name, drv); - WARN_ON(1); - } mutex_lock(&sysdev_drivers_lock); if (cls && kset_get(&cls->kset)) { @@ -194,8 +198,7 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) } } else { err = -EINVAL; - printk(KERN_ERR "%s: invalid device class\n", __func__); - WARN_ON(1); + WARN(1, KERN_ERR "%s: invalid device class\n", __func__); } mutex_unlock(&sysdev_drivers_lock); return err; @@ -207,8 +210,8 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) * @cls: Class driver belongs to. * @drv: Driver. */ -void sysdev_driver_unregister(struct sysdev_class * cls, - struct sysdev_driver * drv) +void sysdev_driver_unregister(struct sysdev_class *cls, + struct sysdev_driver *drv) { mutex_lock(&sysdev_drivers_lock); list_del_init(&drv->entry); @@ -233,10 +236,10 @@ EXPORT_SYMBOL_GPL(sysdev_driver_unregister); * @sysdev: device in question * */ -int sysdev_register(struct sys_device * sysdev) +int sysdev_register(struct sys_device *sysdev) { int error; - struct sysdev_class * cls = sysdev->cls; + struct sysdev_class *cls = sysdev->cls; if (!cls) return -EINVAL; @@ -256,7 +259,7 @@ int sysdev_register(struct sys_device * sysdev) sysdev->id); if (!error) { - struct sysdev_driver * drv; + struct sysdev_driver *drv; pr_debug("Registering sys device '%s'\n", kobject_name(&sysdev->kobj)); @@ -272,15 +275,15 @@ int sysdev_register(struct sys_device * sysdev) drv->add(sysdev); } mutex_unlock(&sysdev_drivers_lock); + kobject_uevent(&sysdev->kobj, KOBJ_ADD); } - kobject_uevent(&sysdev->kobj, KOBJ_ADD); return error; } -void sysdev_unregister(struct sys_device * sysdev) +void sysdev_unregister(struct sys_device *sysdev) { - struct sysdev_driver * drv; + struct sysdev_driver *drv; mutex_lock(&sysdev_drivers_lock); list_for_each_entry(drv, &sysdev->cls->drivers, entry) { @@ -303,26 +306,25 @@ void sysdev_unregister(struct sys_device * sysdev) * and the class driver. * * Note: The list is iterated in reverse order, so that we shut down - * child devices before we shut down thier parents. The list ordering + * child devices before we shut down their parents. The list ordering * is guaranteed by virtue of the fact that child devices are registered * after their parents. */ - void sysdev_shutdown(void) { - struct sysdev_class * cls; + struct sysdev_class *cls; pr_debug("Shutting Down System Devices\n"); mutex_lock(&sysdev_drivers_lock); list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) { - struct sys_device * sysdev; + struct sys_device *sysdev; pr_debug("Shutting down type '%s':\n", kobject_name(&cls->kset.kobj)); list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { - struct sysdev_driver * drv; + struct sysdev_driver *drv; pr_debug(" %s\n", kobject_name(&sysdev->kobj)); /* Call auxillary drivers first */ @@ -347,11 +349,15 @@ static void __sysdev_resume(struct sys_device *dev) /* First, call the class-specific one */ if (cls->resume) cls->resume(dev); + WARN_ONCE(!irqs_disabled(), + "Interrupts enabled after %pF\n", cls->resume); /* Call auxillary drivers next. */ list_for_each_entry(drv, &cls->drivers, entry) { if (drv->resume) drv->resume(dev); + WARN_ONCE(!irqs_disabled(), + "Interrupts enabled after %pF\n", drv->resume); } } @@ -359,7 +365,7 @@ static void __sysdev_resume(struct sys_device *dev) * sysdev_suspend - Suspend all system devices. * @state: Power state to enter. * - * We perform an almost identical operation as sys_device_shutdown() + * We perform an almost identical operation as sysdev_shutdown() * above, though calling ->suspend() instead. Interrupts are disabled * when this called. Devices are responsible for both saving state and * quiescing or powering down the device. @@ -367,14 +373,23 @@ static void __sysdev_resume(struct sys_device *dev) * This is only called by the device PM core, so we let them handle * all synchronization. */ - int sysdev_suspend(pm_message_t state) { - struct sysdev_class * cls; + struct sysdev_class *cls; struct sys_device *sysdev, *err_dev; struct sysdev_driver *drv, *err_drv; int ret; + pr_debug("Checking wake-up interrupts\n"); + + /* Return error code if there are any wake-up interrupts pending */ + ret = check_wakeup_irqs(); + if (ret) + return ret; + + WARN_ONCE(!irqs_disabled(), + "Interrupts enabled while suspending system devices\n"); + pr_debug("Suspending System Devices\n"); list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) { @@ -391,6 +406,9 @@ int sysdev_suspend(pm_message_t state) if (ret) goto aux_driver; } + WARN_ONCE(!irqs_disabled(), + "Interrupts enabled after %pF\n", + drv->suspend); } /* Now call the generic one */ @@ -398,6 +416,9 @@ int sysdev_suspend(pm_message_t state) ret = cls->suspend(sysdev, state); if (ret) goto cls_driver; + WARN_ONCE(!irqs_disabled(), + "Interrupts enabled after %pF\n", + cls->suspend); } } } @@ -436,25 +457,27 @@ aux_driver: } return ret; } - +EXPORT_SYMBOL_GPL(sysdev_suspend); /** * sysdev_resume - Bring system devices back to life. * - * Similar to sys_device_suspend(), but we iterate the list forwards + * Similar to sysdev_suspend(), but we iterate the list forwards * to guarantee that parent devices are resumed before their children. * * Note: Interrupts are disabled when called. */ - int sysdev_resume(void) { - struct sysdev_class * cls; + struct sysdev_class *cls; + + WARN_ONCE(!irqs_disabled(), + "Interrupts enabled while resuming system devices\n"); pr_debug("Resuming System Devices\n"); list_for_each_entry(cls, &system_kset->list, kset.kobj.entry) { - struct sys_device * sysdev; + struct sys_device *sysdev; pr_debug("Resuming type '%s':\n", kobject_name(&cls->kset.kobj)); @@ -467,7 +490,7 @@ int sysdev_resume(void) } return 0; } - +EXPORT_SYMBOL_GPL(sysdev_resume); int __init system_bus_init(void) { @@ -492,7 +515,8 @@ ssize_t sysdev_store_ulong(struct sys_device *sysdev, if (end == buf) return -EINVAL; *(unsigned long *)(ea->var) = new; - return end - buf; + /* Always return full write size even if we didn't consume all */ + return size; } EXPORT_SYMBOL_GPL(sysdev_store_ulong); @@ -515,7 +539,8 @@ ssize_t sysdev_store_int(struct sys_device *sysdev, if (end == buf || new > INT_MAX || new < INT_MIN) return -EINVAL; *(int *)(ea->var) = new; - return end - buf; + /* Always return full write size even if we didn't consume all */ + return size; } EXPORT_SYMBOL_GPL(sysdev_store_int);