Skip to content

Commit ab013c5

Browse files
rostedtrustyrussell
authored andcommitted
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: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 7cb14ba commit ab013c5

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

include/linux/moduleparam.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,18 @@ static const char __UNIQUE_ID(name)[] \
3636

3737
struct kernel_param;
3838

39+
/*
40+
* Flags available for kernel_param_ops
41+
*
42+
* NOARG - the parameter allows for no argument (foo instead of foo=1)
43+
*/
44+
enum {
45+
KERNEL_PARAM_FL_NOARG = (1 << 0)
46+
};
47+
3948
struct kernel_param_ops {
49+
/* How the ops should behave */
50+
unsigned int flags;
4051
/* Returns 0, or -errno. arg is in kp->arg. */
4152
int (*set)(const char *val, const struct kernel_param *kp);
4253
/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
@@ -187,7 +198,7 @@ struct kparam_array
187198
/* Obsolete - use module_param_cb() */
188199
#define module_param_call(name, set, get, arg, perm) \
189200
static struct kernel_param_ops __param_ops_##name = \
190-
{ (void *)set, (void *)get }; \
201+
{ 0, (void *)set, (void *)get }; \
191202
__module_param_call(MODULE_PARAM_PREFIX, \
192203
name, &__param_ops_##name, arg, \
193204
(perm) + sizeof(__check_old_set_param(set))*0, -1)

kernel/params.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ static int parse_one(char *param,
103103
|| params[i].level > max_level)
104104
return 0;
105105
/* No one handled NULL, so do it here. */
106-
if (!val && params[i].ops->set != param_set_bool
107-
&& params[i].ops->set != param_set_bint)
106+
if (!val &&
107+
!(params[i].ops->flags & KERNEL_PARAM_FL_NOARG))
108108
return -EINVAL;
109109
pr_debug("handling %s with %p\n", param,
110110
params[i].ops->set);
@@ -320,6 +320,7 @@ int param_get_bool(char *buffer, const struct kernel_param *kp)
320320
EXPORT_SYMBOL(param_get_bool);
321321

322322
struct kernel_param_ops param_ops_bool = {
323+
.flags = KERNEL_PARAM_FL_NOARG,
323324
.set = param_set_bool,
324325
.get = param_get_bool,
325326
};
@@ -370,6 +371,7 @@ int param_set_bint(const char *val, const struct kernel_param *kp)
370371
EXPORT_SYMBOL(param_set_bint);
371372

372373
struct kernel_param_ops param_ops_bint = {
374+
.flags = KERNEL_PARAM_FL_NOARG,
373375
.set = param_set_bint,
374376
.get = param_get_int,
375377
};

0 commit comments

Comments
 (0)