Commit ab013c5f authored by Steven Rostedt's avatar Steven Rostedt Committed by Rusty Russell

module: Add flag to allow mod params to have no arguments

Currently the params.c code allows only two "set" functions to have
no arguments. If a parameter does not have an argument, then it
looks at the set function and tests if it is either param_set_bool()
or param_set_bint(). If it is not one of these functions, then it
fails the loading of the module.

But there may be module parameters that have different set functions
and still allow no arguments. But unless each of these cases adds
their function to the if statement, it wont be allowed to have no
arguments. This method gets rather messing and does not scale.

Instead, introduce a flags field to the kernel_param_ops, where if
the flag KERNEL_PARAM_FL_NOARG is set, the parameter will not fail
if it does not contain an argument. It will be expected that the
corresponding set function can handle a NULL pointer as "val".
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 7cb14ba7
...@@ -36,7 +36,18 @@ static const char __UNIQUE_ID(name)[] \ ...@@ -36,7 +36,18 @@ static const char __UNIQUE_ID(name)[] \
struct kernel_param; struct kernel_param;
/*
* Flags available for kernel_param_ops
*
* NOARG - the parameter allows for no argument (foo instead of foo=1)
*/
enum {
KERNEL_PARAM_FL_NOARG = (1 << 0)
};
struct kernel_param_ops { struct kernel_param_ops {
/* How the ops should behave */
unsigned int flags;
/* Returns 0, or -errno. arg is in kp->arg. */ /* Returns 0, or -errno. arg is in kp->arg. */
int (*set)(const char *val, const struct kernel_param *kp); int (*set)(const char *val, const struct kernel_param *kp);
/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ /* Returns length written or -errno. Buffer is 4k (ie. be short!) */
...@@ -187,7 +198,7 @@ struct kparam_array ...@@ -187,7 +198,7 @@ struct kparam_array
/* Obsolete - use module_param_cb() */ /* Obsolete - use module_param_cb() */
#define module_param_call(name, set, get, arg, perm) \ #define module_param_call(name, set, get, arg, perm) \
static struct kernel_param_ops __param_ops_##name = \ static struct kernel_param_ops __param_ops_##name = \
{ (void *)set, (void *)get }; \ { 0, (void *)set, (void *)get }; \
__module_param_call(MODULE_PARAM_PREFIX, \ __module_param_call(MODULE_PARAM_PREFIX, \
name, &__param_ops_##name, arg, \ name, &__param_ops_##name, arg, \
(perm) + sizeof(__check_old_set_param(set))*0, -1) (perm) + sizeof(__check_old_set_param(set))*0, -1)
......
...@@ -103,8 +103,8 @@ static int parse_one(char *param, ...@@ -103,8 +103,8 @@ static int parse_one(char *param,
|| params[i].level > max_level) || params[i].level > max_level)
return 0; return 0;
/* No one handled NULL, so do it here. */ /* No one handled NULL, so do it here. */
if (!val && params[i].ops->set != param_set_bool if (!val &&
&& params[i].ops->set != param_set_bint) !(params[i].ops->flags & KERNEL_PARAM_FL_NOARG))
return -EINVAL; return -EINVAL;
pr_debug("handling %s with %p\n", param, pr_debug("handling %s with %p\n", param,
params[i].ops->set); params[i].ops->set);
...@@ -320,6 +320,7 @@ int param_get_bool(char *buffer, const struct kernel_param *kp) ...@@ -320,6 +320,7 @@ int param_get_bool(char *buffer, const struct kernel_param *kp)
EXPORT_SYMBOL(param_get_bool); EXPORT_SYMBOL(param_get_bool);
struct kernel_param_ops param_ops_bool = { struct kernel_param_ops param_ops_bool = {
.flags = KERNEL_PARAM_FL_NOARG,
.set = param_set_bool, .set = param_set_bool,
.get = param_get_bool, .get = param_get_bool,
}; };
...@@ -370,6 +371,7 @@ int param_set_bint(const char *val, const struct kernel_param *kp) ...@@ -370,6 +371,7 @@ int param_set_bint(const char *val, const struct kernel_param *kp)
EXPORT_SYMBOL(param_set_bint); EXPORT_SYMBOL(param_set_bint);
struct kernel_param_ops param_ops_bint = { struct kernel_param_ops param_ops_bint = {
.flags = KERNEL_PARAM_FL_NOARG,
.set = param_set_bint, .set = param_set_bint,
.get = param_get_int, .get = param_get_int,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment