module_param: allow 'bool' module_params to be bool, not just int.

Impact: API cleanup

For historical reasons, 'bool' parameters must be an int, not a bool.
But there are around 600 users, so a conversion seems like useless churn.

So we use __same_type() to distinguish, and handle both cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2009-06-12 21:46:57 -06:00
parent d2c123c27d
commit fddd520122
2 changed files with 49 additions and 16 deletions

View File

@@ -238,35 +238,54 @@ int param_get_charp(char *buffer, struct kernel_param *kp)
return sprintf(buffer, "%s", *((char **)kp->arg));
}
/* Actually could be a bool or an int, for historical reasons. */
int param_set_bool(const char *val, struct kernel_param *kp)
{
bool v;
/* No equals means "set"... */
if (!val) val = "1";
/* One of =[yYnN01] */
switch (val[0]) {
case 'y': case 'Y': case '1':
*(int *)kp->arg = 1;
return 0;
v = true;
break;
case 'n': case 'N': case '0':
*(int *)kp->arg = 0;
return 0;
v = false;
break;
default:
return -EINVAL;
}
return -EINVAL;
if (kp->flags & KPARAM_ISBOOL)
*(bool *)kp->arg = v;
else
*(int *)kp->arg = v;
return 0;
}
int param_get_bool(char *buffer, struct kernel_param *kp)
{
bool val;
if (kp->flags & KPARAM_ISBOOL)
val = *(bool *)kp->arg;
else
val = *(int *)kp->arg;
/* Y and N chosen as being relatively non-coder friendly */
return sprintf(buffer, "%c", (*(int *)kp->arg) ? 'Y' : 'N');
return sprintf(buffer, "%c", val ? 'Y' : 'N');
}
/* This one must be bool. */
int param_set_invbool(const char *val, struct kernel_param *kp)
{
int boolval, ret;
int ret;
bool boolval;
struct kernel_param dummy;
dummy.arg = &boolval;
dummy.flags = KPARAM_ISBOOL;
ret = param_set_bool(val, &dummy);
if (ret == 0)
*(bool *)kp->arg = !boolval;