aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2009-06-12 23:46:57 -0400
committerRusty Russell <rusty@rustcorp.com.au>2009-06-12 08:16:58 -0400
commitfddd520122953550ec2c8b60e7ca0d0f0d115d97 (patch)
treed0c45f94bc0054661ee9af41b607815c24a36cff /kernel
parentd2c123c27db841c6c11a63de9c144823d2b1ba76 (diff)
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>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/params.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/kernel/params.c b/kernel/params.c
index b4660dc13dbc..7f6912ced2ba 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -238,35 +238,54 @@ int param_get_charp(char *buffer, struct kernel_param *kp)
238 return sprintf(buffer, "%s", *((char **)kp->arg)); 238 return sprintf(buffer, "%s", *((char **)kp->arg));
239} 239}
240 240
241/* Actually could be a bool or an int, for historical reasons. */
241int param_set_bool(const char *val, struct kernel_param *kp) 242int param_set_bool(const char *val, struct kernel_param *kp)
242{ 243{
244 bool v;
245
243 /* No equals means "set"... */ 246 /* No equals means "set"... */
244 if (!val) val = "1"; 247 if (!val) val = "1";
245 248
246 /* One of =[yYnN01] */ 249 /* One of =[yYnN01] */
247 switch (val[0]) { 250 switch (val[0]) {
248 case 'y': case 'Y': case '1': 251 case 'y': case 'Y': case '1':
249 *(int *)kp->arg = 1; 252 v = true;
250 return 0; 253 break;
251 case 'n': case 'N': case '0': 254 case 'n': case 'N': case '0':
252 *(int *)kp->arg = 0; 255 v = false;
253 return 0; 256 break;
257 default:
258 return -EINVAL;
254 } 259 }
255 return -EINVAL; 260
261 if (kp->flags & KPARAM_ISBOOL)
262 *(bool *)kp->arg = v;
263 else
264 *(int *)kp->arg = v;
265 return 0;
256} 266}
257 267
258int param_get_bool(char *buffer, struct kernel_param *kp) 268int param_get_bool(char *buffer, struct kernel_param *kp)
259{ 269{
270 bool val;
271 if (kp->flags & KPARAM_ISBOOL)
272 val = *(bool *)kp->arg;
273 else
274 val = *(int *)kp->arg;
275
260 /* Y and N chosen as being relatively non-coder friendly */ 276 /* Y and N chosen as being relatively non-coder friendly */
261 return sprintf(buffer, "%c", (*(int *)kp->arg) ? 'Y' : 'N'); 277 return sprintf(buffer, "%c", val ? 'Y' : 'N');
262} 278}
263 279
280/* This one must be bool. */
264int param_set_invbool(const char *val, struct kernel_param *kp) 281int param_set_invbool(const char *val, struct kernel_param *kp)
265{ 282{
266 int boolval, ret; 283 int ret;
284 bool boolval;
267 struct kernel_param dummy; 285 struct kernel_param dummy;
268 286
269 dummy.arg = &boolval; 287 dummy.arg = &boolval;
288 dummy.flags = KPARAM_ISBOOL;
270 ret = param_set_bool(val, &dummy); 289 ret = param_set_bool(val, &dummy);
271 if (ret == 0) 290 if (ret == 0)
272 *(bool *)kp->arg = !boolval; 291 *(bool *)kp->arg = !boolval;