]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/base/sys.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
[linux-2.6-omap-h63xx.git] / drivers / base / sys.c
index dc7dace14e1ccf785398f182cf11d56074416ef4..75dd6e22faff531cf8d136223bdf379102c299f6 100644 (file)
@@ -168,19 +168,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 +191,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;
@@ -479,3 +475,52 @@ int __init system_bus_init(void)
 
 EXPORT_SYMBOL_GPL(sysdev_register);
 EXPORT_SYMBOL_GPL(sysdev_unregister);
+
+#define to_ext_attr(x) container_of(x, struct sysdev_ext_attribute, attr)
+
+ssize_t sysdev_store_ulong(struct sys_device *sysdev,
+                          struct sysdev_attribute *attr,
+                          const char *buf, size_t size)
+{
+       struct sysdev_ext_attribute *ea = to_ext_attr(attr);
+       char *end;
+       unsigned long new = simple_strtoul(buf, &end, 0);
+       if (end == buf)
+               return -EINVAL;
+       *(unsigned long *)(ea->var) = new;
+       return end - buf;
+}
+EXPORT_SYMBOL_GPL(sysdev_store_ulong);
+
+ssize_t sysdev_show_ulong(struct sys_device *sysdev,
+                         struct sysdev_attribute *attr,
+                         char *buf)
+{
+       struct sysdev_ext_attribute *ea = to_ext_attr(attr);
+       return snprintf(buf, PAGE_SIZE, "%lx\n", *(unsigned long *)(ea->var));
+}
+EXPORT_SYMBOL_GPL(sysdev_show_ulong);
+
+ssize_t sysdev_store_int(struct sys_device *sysdev,
+                          struct sysdev_attribute *attr,
+                          const char *buf, size_t size)
+{
+       struct sysdev_ext_attribute *ea = to_ext_attr(attr);
+       char *end;
+       long new = simple_strtol(buf, &end, 0);
+       if (end == buf || new > INT_MAX || new < INT_MIN)
+               return -EINVAL;
+       *(int *)(ea->var) = new;
+       return end - buf;
+}
+EXPORT_SYMBOL_GPL(sysdev_store_int);
+
+ssize_t sysdev_show_int(struct sys_device *sysdev,
+                         struct sysdev_attribute *attr,
+                         char *buf)
+{
+       struct sysdev_ext_attribute *ea = to_ext_attr(attr);
+       return snprintf(buf, PAGE_SIZE, "%d\n", *(int *)(ea->var));
+}
+EXPORT_SYMBOL_GPL(sysdev_show_int);
+