diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/params.c | 33 |
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. */ | ||
241 | int param_set_bool(const char *val, struct kernel_param *kp) | 242 | int 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 | ||
258 | int param_get_bool(char *buffer, struct kernel_param *kp) | 268 | int 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. */ | ||
264 | int param_set_invbool(const char *val, struct kernel_param *kp) | 281 | int 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; |