xfs: remove nr_to_write writeback windup.
[safe/jmp/linux-2.6] / kernel / params.c
index de273ec..0b30ecd 100644 (file)
@@ -23,9 +23,7 @@
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/slab.h>
-
-/* We abuse the high bits of "perm" to record whether we kmalloc'ed. */
-#define KPARAM_KMALLOCED       0x80000000
+#include <linux/ctype.h>
 
 #if 0
 #define DEBUGP printk
@@ -90,7 +88,7 @@ static char *next_arg(char *args, char **param, char **val)
        }
 
        for (i = 0; args[i]; i++) {
-               if (args[i] == ' ' && !in_quote)
+               if (isspace(args[i]) && !in_quote)
                        break;
                if (equals == 0) {
                        if (args[i] == '=')
@@ -124,9 +122,7 @@ static char *next_arg(char *args, char **param, char **val)
                next = args + i;
 
        /* Chew up trailing spaces. */
-       while (*next == ' ')
-               next++;
-       return next;
+       return skip_spaces(next);
 }
 
 /* Args looks like "foo=bar,bar2 baz=fuz wiz". */
@@ -141,8 +137,7 @@ int parse_args(const char *name,
        DEBUGP("Parsing ARGS: %s\n", args);
 
        /* Chew leading spaces */
-       while (*args == ' ')
-               args++;
+       args = skip_spaces(args);
 
        while (*args) {
                int ret;
@@ -220,15 +215,11 @@ int param_set_charp(const char *val, struct kernel_param *kp)
                return -ENOSPC;
        }
 
-       if (kp->perm & KPARAM_KMALLOCED)
-               kfree(*(char **)kp->arg);
-
        /* This is a hack.  We can't need to strdup in early boot, and we
         * don't need to; this mangled commandline is preserved. */
        if (slab_is_available()) {
-               kp->perm |= KPARAM_KMALLOCED;
                *(char **)kp->arg = kstrdup(val, GFP_KERNEL);
-               if (!kp->arg)
+               if (!*(char **)kp->arg)
                        return -ENOMEM;
        } else
                *(const char **)kp->arg = val;
@@ -241,44 +232,63 @@ int param_get_charp(char *buffer, struct kernel_param *kp)
        return sprintf(buffer, "%s", *((char **)kp->arg));
 }
 
+/* Actually could be a bool or an int, for historical reasons. */
 int param_set_bool(const char *val, struct kernel_param *kp)
 {
+       bool v;
+
        /* No equals means "set"... */
        if (!val) val = "1";
 
        /* One of =[yYnN01] */
        switch (val[0]) {
        case 'y': case 'Y': case '1':
-               *(int *)kp->arg = 1;
-               return 0;
+               v = true;
+               break;
        case 'n': case 'N': case '0':
-               *(int *)kp->arg = 0;
-               return 0;
+               v = false;
+               break;
+       default:
+               return -EINVAL;
        }
-       return -EINVAL;
+
+       if (kp->flags & KPARAM_ISBOOL)
+               *(bool *)kp->arg = v;
+       else
+               *(int *)kp->arg = v;
+       return 0;
 }
 
 int param_get_bool(char *buffer, struct kernel_param *kp)
 {
+       bool val;
+       if (kp->flags & KPARAM_ISBOOL)
+               val = *(bool *)kp->arg;
+       else
+               val = *(int *)kp->arg;
+
        /* Y and N chosen as being relatively non-coder friendly */
-       return sprintf(buffer, "%c", (*(int *)kp->arg) ? 'Y' : 'N');
+       return sprintf(buffer, "%c", val ? 'Y' : 'N');
 }
 
+/* This one must be bool. */
 int param_set_invbool(const char *val, struct kernel_param *kp)
 {
-       int boolval, ret;
+       int ret;
+       bool boolval;
        struct kernel_param dummy;
 
        dummy.arg = &boolval;
+       dummy.flags = KPARAM_ISBOOL;
        ret = param_set_bool(val, &dummy);
        if (ret == 0)
-               *(int *)kp->arg = !boolval;
+               *(bool *)kp->arg = !boolval;
        return ret;
 }
 
 int param_get_invbool(char *buffer, struct kernel_param *kp)
 {
-       return sprintf(buffer, "%c", (*(int *)kp->arg) ? 'N' : 'Y');
+       return sprintf(buffer, "%c", (*(bool *)kp->arg) ? 'N' : 'Y');
 }
 
 /* We break the rule and mangle the string. */
@@ -287,6 +297,7 @@ static int param_array(const char *name,
                       unsigned int min, unsigned int max,
                       void *elem, int elemsize,
                       int (*set)(const char *, struct kernel_param *kp),
+                      u16 flags,
                       unsigned int *num)
 {
        int ret;
@@ -296,6 +307,7 @@ static int param_array(const char *name,
        /* Get the name right for errors. */
        kp.name = name;
        kp.arg = elem;
+       kp.flags = flags;
 
        /* No equals sign? */
        if (!val) {
@@ -341,7 +353,8 @@ int param_array_set(const char *val, struct kernel_param *kp)
        unsigned int temp_num;
 
        return param_array(kp->name, val, 1, arr->max, arr->elem,
-                          arr->elemsize, arr->set, arr->num ?: &temp_num);
+                          arr->elemsize, arr->set, kp->flags,
+                          arr->num ?: &temp_num);
 }
 
 int param_array_get(char *buffer, struct kernel_param *kp)
@@ -388,8 +401,8 @@ int param_get_string(char *buffer, struct kernel_param *kp)
 }
 
 /* sysfs output in /sys/modules/XYZ/parameters/ */
-#define to_module_attr(n) container_of(n, struct module_attribute, attr);
-#define to_module_kobject(n) container_of(n, struct module_kobject, kobj);
+#define to_module_attr(n) container_of(n, struct module_attribute, attr)
+#define to_module_kobject(n) container_of(n, struct module_kobject, kobj)
 
 extern struct kernel_param __start___param[], __stop___param[];
 
@@ -407,7 +420,7 @@ struct module_param_attrs
 };
 
 #ifdef CONFIG_SYSFS
-#define to_param_attr(n) container_of(n, struct param_attribute, mattr);
+#define to_param_attr(n) container_of(n, struct param_attribute, mattr)
 
 static ssize_t param_attr_show(struct module_attribute *mattr,
                               struct module *mod, char *buf)
@@ -503,6 +516,7 @@ static __modinit int add_sysfs_param(struct module_kobject *mk,
        new->grp.attrs = attrs;
 
        /* Tack new one on the end. */
+       sysfs_attr_init(&new->attrs[num].mattr.attr);
        new->attrs[num].param = kp;
        new->attrs[num].mattr.show = param_attr_show;
        new->attrs[num].mattr.store = param_attr_store;
@@ -588,11 +602,7 @@ void module_param_sysfs_remove(struct module *mod)
 
 void destroy_params(const struct kernel_param *params, unsigned num)
 {
-       unsigned int i;
-
-       for (i = 0; i < num; i++)
-               if (params[i].perm & KPARAM_KMALLOCED)
-                       kfree(*(char **)params[i].arg);
+       /* FIXME: This should free kmalloced charp parameters.  It doesn't. */
 }
 
 static void __init kernel_add_sysfs_param(const char *name,
@@ -713,7 +723,7 @@ static ssize_t module_attr_store(struct kobject *kobj,
        return ret;
 }
 
-static struct sysfs_ops module_sysfs_ops = {
+static const struct sysfs_ops module_sysfs_ops = {
        .show = module_attr_show,
        .store = module_attr_store,
 };
@@ -727,7 +737,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
        return 0;
 }
 
-static struct kset_uevent_ops module_uevent_ops = {
+static const struct kset_uevent_ops module_uevent_ops = {
        .filter = uevent_filter,
 };