summaryrefslogtreecommitdiffstats
path: root/kernel/params.c
diff options
context:
space:
mode:
authorLuis R. Rodriguez <mcgrof@suse.com>2015-05-26 21:39:38 -0400
committerRusty Russell <rusty@rustcorp.com.au>2015-05-27 22:02:11 -0400
commitd19f05d8a8fa221e5d5f4eaca0f3ca5874c990d3 (patch)
treeaf7ed11bef82faa0e7a33b6ec8739a32ec50f00f /kernel/params.c
parent05f408dddb013168759cdb4cbd0ba4e189a9504d (diff)
kernel/params.c: generalize bool_enable_only
This takes out the bool_enable_only implementation from the module loading code and generalizes it so that others can make use of it. Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Jani Nikula <jani.nikula@intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Kees Cook <keescook@chromium.org> Cc: Tejun Heo <tj@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: linux-kernel@vger.kernel.org Cc: cocci@systeme.lip6.fr Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'kernel/params.c')
-rw-r--r--kernel/params.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/kernel/params.c b/kernel/params.c
index b7635c025e9b..324624ed620f 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -335,6 +335,36 @@ const struct kernel_param_ops param_ops_bool = {
335}; 335};
336EXPORT_SYMBOL(param_ops_bool); 336EXPORT_SYMBOL(param_ops_bool);
337 337
338int param_set_bool_enable_only(const char *val, const struct kernel_param *kp)
339{
340 int err = 0;
341 bool new_value;
342 bool orig_value = *(bool *)kp->arg;
343 struct kernel_param dummy_kp = *kp;
344
345 dummy_kp.arg = &new_value;
346
347 err = param_set_bool(val, &dummy_kp);
348 if (err)
349 return err;
350
351 /* Don't let them unset it once it's set! */
352 if (!new_value && orig_value)
353 return -EROFS;
354
355 if (new_value)
356 err = param_set_bool(val, kp);
357
358 return err;
359}
360EXPORT_SYMBOL_GPL(param_set_bool_enable_only);
361
362const struct kernel_param_ops param_ops_bool_enable_only = {
363 .flags = KERNEL_PARAM_OPS_FL_NOARG,
364 .set = param_set_bool_enable_only,
365 .get = param_get_bool,
366};
367
338/* This one must be bool. */ 368/* This one must be bool. */
339int param_set_invbool(const char *val, const struct kernel_param *kp) 369int param_set_invbool(const char *val, const struct kernel_param *kp)
340{ 370{