diff mbox

[v2,4/8] moduleparam.h: add module_param_config_*() helpers

Message ID 1429739711-9415-5-git-send-email-mcgrof@do-not-panic.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Luis R. Rodriguez April 22, 2015, 9:55 p.m. UTC
From: "Luis R. Rodriguez" <mcgrof@suse.com>

This adds a couple of bool module_param_config_*() helpers
which are designed to let us easily associate a boolean
module parameter with an associated kernel configuration
option. Folks can use this to avoid what typically would
be #ifdef eyesores around module parameter declarations.

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>
---
 include/linux/moduleparam.h | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

Comments

Rusty Russell April 23, 2015, 2:15 a.m. UTC | #1
"Luis R. Rodriguez" <mcgrof@do-not-panic.com> writes:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
>
> This adds a couple of bool module_param_config_*() helpers
> which are designed to let us easily associate a boolean
> module parameter with an associated kernel configuration
> option.

OK.

> Folks can use this to avoid what typically would
> be #ifdef eyesores around module parameter declarations.

Really?  So you use this in two patches:

  /* see the comment above the definition of WQ_POWER_EFFICIENT */
 -static bool wq_power_efficient = IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT);
 -module_param_named(power_efficient, wq_power_efficient, bool, 0444);
 +module_param_config_on_off(power_efficient, wq_power_efficient, 0444, CONFIG_WQ_POWER_EFFICIENT_DEFAULT);

And:

  static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE);
  #ifndef CONFIG_MODULE_SIG_FORCE
 -module_param(sig_enforce, bool_enable_only, 0644);
 +module_param_config_on(sig_enforce, sig_enforce, 0644, CONFIG_MODULE_SIG_FORCE);
  #endif /* !CONFIG_MODULE_SIG_FORCE */

But neither actually, y'know, cleans up any #ifdefs.

Simplicity is a major virtue.  Readability is a major virtue.  Brevity
is only a minor virtue.

So I have applied the following patches:

[PATCH v2 1/8] kernel/params: constify struct kernel_param_ops uses
[PATCH v2 2/8] kernel/module.c: use generic module param operaters for sig_enforce
[PATCH v2 3/8] kernel/params.c: generalize bool_enable_only
[PATCH v2 5/8] kernel/workqueue.c: remove ifdefs over wq_power_efficient
[PATCH v2 7/8] kernel/module.c: avoid ifdefs for sig_enforce declaration

Thanks,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Luis Chamberlain April 23, 2015, 7:33 p.m. UTC | #2
On Thu, Apr 23, 2015 at 11:45:09AM +0930, Rusty Russell wrote:
> "Luis R. Rodriguez" <mcgrof@do-not-panic.com> writes:
> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> >
> > This adds a couple of bool module_param_config_*() helpers
> > which are designed to let us easily associate a boolean
> > module parameter with an associated kernel configuration
> > option.
> 
> OK.

So this is really the main gain.

> > Folks can use this to avoid what typically would
> > be #ifdef eyesores around module parameter declarations.
> 
> Really?  So you use this in two patches:
> 
>   /* see the comment above the definition of WQ_POWER_EFFICIENT */
>  -static bool wq_power_efficient = IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT);
>  -module_param_named(power_efficient, wq_power_efficient, bool, 0444);
>  +module_param_config_on_off(power_efficient, wq_power_efficient, 0444, CONFIG_WQ_POWER_EFFICIENT_DEFAULT);
> 
> And:
> 
>   static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE);
>   #ifndef CONFIG_MODULE_SIG_FORCE
>  -module_param(sig_enforce, bool_enable_only, 0644);
>  +module_param_config_on(sig_enforce, sig_enforce, 0644, CONFIG_MODULE_SIG_FORCE);
>   #endif /* !CONFIG_MODULE_SIG_FORCE */
> 
> But neither actually, y'know, cleans up any #ifdefs.

OK, sure, its the use of IS_ENABLED() that does that as a first step.

> Simplicity is a major virtue.  Readability is a major virtue.  Brevity
> is only a minor virtue.

I was not shooting for brevity but instead aiming at the possible
grammatical gain of direct and immediate association between a bool, behaviour
(on_off, or just on), and a config. I don't have a need for the grammatical
association now so will drop this.

  Luis
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 7e00799..5416372 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -155,6 +155,43 @@  struct kparam_array
 	__MODULE_PARM_TYPE(name, #type)
 
 /**
+ * module_param_config_on_off - bool parameter with run time override
+ * @name: a valid C identifier which is the parameter name.
+ * @value: the actual lvalue to alter.
+ * @perm: visibility in sysfs.
+ * @config: kernel parameter which will enable this option if this
+ * 	kernel configuration option has been enabled.
+ *
+ * This lets you define a bool module parameter which by default will be
+ * set to true if the config option has been set on your kernel's
+ * configuration, otherwise it is set to false.
+ */
+#define module_param_config_on_off(name, var, perm, config) 		\
+	static bool var = IS_ENABLED(config);				\
+	module_param_named(name, var, bool, perm);
+
+/**
+ * module_param_config_on - bool parameter with run time enablement override
+ * @name: a valid C identifier which is the parameter name.
+ * @value: the actual lvalue to alter.
+ * @perm: visibility in sysfs.
+ * @config: kernel parameter which will enable this option if this
+ * 	kernel configuration option has been enabled.
+ *
+ * This lets you define a bool module parameter which by default will be
+ * set to true if the config option has been set on your kernel's
+ * configuration, otherwise it is set to false. This particular helper
+ * will ensure that if the kernel configuration has been set you will not
+ * be able to disable this kernel parameter. You can only use this to let
+ * the an option that was disabled on your kernel configuration be enabled
+ * at run time.
+ */
+#define module_param_config_on(name, var, perm, config) 		\
+	static bool var = IS_ENABLED(config);				\
+	module_param_named(name, var, bool_enable_only, perm);
+
+
+/**
  * module_param_cb - general callback for a module/cmdline parameter
  * @name: a valid C identifier which is the parameter name.
  * @ops: the set & get operations for this parameter.