Return-path: Received: from mail-pd0-f175.google.com ([209.85.192.175]:32942 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758150AbbDVWBw (ORCPT ); Wed, 22 Apr 2015 18:01:52 -0400 From: "Luis R. Rodriguez" To: rusty@rustcorp.com.au Cc: akpm@linux-foundation.org, mingo@kernel.org, tj@kernel.org, linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, keescook@chromium.org, casey@schaufler-ca.com, cocci@systeme.lip6.fr, "Luis R. Rodriguez" , Jani Nikula Subject: [PATCH v2 2/8] kernel/module.c: use generic module param operaters for sig_enforce Date: Wed, 22 Apr 2015 14:55:05 -0700 Message-Id: <1429739711-9415-3-git-send-email-mcgrof@do-not-panic.com> (sfid-20150423_000211_481821_1D9EFE08) In-Reply-To: <1429739711-9415-1-git-send-email-mcgrof@do-not-panic.com> References: <1429739711-9415-1-git-send-email-mcgrof@do-not-panic.com> Sender: linux-wireless-owner@vger.kernel.org List-ID: From: "Luis R. Rodriguez" We're directly checking and modifying sig_enforce when needed instead of using the generic helpers. This prevents us from generalizing this helper so that others can use it. Use indirect helpers to allow us to generalize this code a bit and to make it a bit more clear what this is doing. Cc: Rusty Russell Cc: Jani Nikula Cc: Andrew Morton Cc: Kees Cook Cc: Tejun Heo Cc: Ingo Molnar Cc: linux-kernel@vger.kernel.org Cc: cocci@systeme.lip6.fr Signed-off-by: Luis R. Rodriguez --- kernel/module.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 42a1d2a..de12c4a 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -114,23 +114,25 @@ static bool sig_enforce = false; static int param_set_bool_enable_only(const char *val, const struct kernel_param *kp) { - int err; - bool test; + int err = 0; + bool new_value; + bool orig_value = *(bool *)kp->arg; struct kernel_param dummy_kp = *kp; - dummy_kp.arg = &test; + dummy_kp.arg = &new_value; err = param_set_bool(val, &dummy_kp); if (err) return err; /* Don't let them unset it once it's set! */ - if (!test && sig_enforce) + if (!new_value && orig_value) return -EROFS; - if (test) - sig_enforce = true; - return 0; + if (new_value) + err = param_set_bool(val, kp); + + return err; } static const struct kernel_param_ops param_ops_bool_enable_only = { -- 2.3.2.209.gd67f9d5.dirty