audit: seperate audit inode watches into a subfile
[safe/jmp/linux-2.6] / kernel / params.c
index f27c992..7f6912c 100644 (file)
@@ -217,7 +217,19 @@ int param_set_charp(const char *val, struct kernel_param *kp)
                return -ENOSPC;
        }
 
-       *(char **)kp->arg = (char *)val;
+       if (kp->flags & 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->flags |= KPARAM_KMALLOCED;
+               *(char **)kp->arg = kstrdup(val, GFP_KERNEL);
+               if (!kp->arg)
+                       return -ENOMEM;
+       } else
+               *(const char **)kp->arg = val;
+
        return 0;
 }
 
@@ -226,44 +238,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. */
@@ -510,6 +541,7 @@ fail:
        return err;
 }
 
+#ifdef CONFIG_MODULES
 static void free_module_param_attrs(struct module_kobject *mk)
 {
        kfree(mk->mp->grp.attrs);
@@ -517,7 +549,6 @@ static void free_module_param_attrs(struct module_kobject *mk)
        mk->mp = NULL;
 }
 
-#ifdef CONFIG_MODULES
 /*
  * module_param_sysfs_setup - setup sysfs support for one module
  * @mod: module
@@ -571,6 +602,15 @@ void module_param_sysfs_remove(struct module *mod)
 }
 #endif
 
+void destroy_params(const struct kernel_param *params, unsigned num)
+{
+       unsigned int i;
+
+       for (i = 0; i < num; i++)
+               if (params[i].flags & KPARAM_KMALLOCED)
+                       kfree(*(char **)params[i].arg);
+}
+
 static void __init kernel_add_sysfs_param(const char *name,
                                          struct kernel_param *kparam,
                                          unsigned int name_skip)
@@ -637,14 +677,14 @@ static void __init param_sysfs_builtin(void)
 
                dot = strchr(kp->name, '.');
                if (!dot) {
-                       DEBUGP("couldn't find period in first %d characters "
-                              "of %s\n", MODULE_NAME_LEN, kp->name);
-                       continue;
+                       /* This happens for core_param() */
+                       strcpy(modname, "kernel");
+                       name_len = 0;
+               } else {
+                       name_len = dot - kp->name + 1;
+                       strlcpy(modname, kp->name, name_len);
                }
-               name_len = dot - kp->name;
-               strncpy(modname, kp->name, name_len);
-               modname[name_len] = '\0';
-               kernel_add_sysfs_param(modname, kp, name_len+1);
+               kernel_add_sysfs_param(modname, kp, name_len);
        }
 }