diff options
-rw-r--r-- | include/linux/moduleparam.h | 18 | ||||
-rw-r--r-- | kernel/params.c | 17 |
2 files changed, 18 insertions, 17 deletions
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h index c83588c8d08b..13410b20600f 100644 --- a/include/linux/moduleparam.h +++ b/include/linux/moduleparam.h | |||
@@ -38,7 +38,11 @@ struct kernel_param { | |||
38 | unsigned int perm; | 38 | unsigned int perm; |
39 | param_set_fn set; | 39 | param_set_fn set; |
40 | param_get_fn get; | 40 | param_get_fn get; |
41 | void *arg; | 41 | union { |
42 | void *arg; | ||
43 | const struct kparam_string *str; | ||
44 | const struct kparam_array *arr; | ||
45 | }; | ||
42 | }; | 46 | }; |
43 | 47 | ||
44 | /* Special one for strings we want to copy into */ | 48 | /* Special one for strings we want to copy into */ |
@@ -66,11 +70,11 @@ struct kparam_array | |||
66 | /* Default value instead of permissions? */ \ | 70 | /* Default value instead of permissions? */ \ |
67 | static int __param_perm_check_##name __attribute__((unused)) = \ | 71 | static int __param_perm_check_##name __attribute__((unused)) = \ |
68 | BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)); \ | 72 | BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)); \ |
69 | static char __param_str_##name[] = prefix #name; \ | 73 | static const char __param_str_##name[] = prefix #name; \ |
70 | static struct kernel_param const __param_##name \ | 74 | static struct kernel_param const __param_##name \ |
71 | __attribute_used__ \ | 75 | __attribute_used__ \ |
72 | __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ | 76 | __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ |
73 | = { __param_str_##name, perm, set, get, arg } | 77 | = { __param_str_##name, perm, set, get, { arg } } |
74 | 78 | ||
75 | #define module_param_call(name, set, get, arg, perm) \ | 79 | #define module_param_call(name, set, get, arg, perm) \ |
76 | __module_param_call(MODULE_PARAM_PREFIX, name, set, get, arg, perm) | 80 | __module_param_call(MODULE_PARAM_PREFIX, name, set, get, arg, perm) |
@@ -88,10 +92,10 @@ struct kparam_array | |||
88 | 92 | ||
89 | /* Actually copy string: maxlen param is usually sizeof(string). */ | 93 | /* Actually copy string: maxlen param is usually sizeof(string). */ |
90 | #define module_param_string(name, string, len, perm) \ | 94 | #define module_param_string(name, string, len, perm) \ |
91 | static struct kparam_string __param_string_##name \ | 95 | static const struct kparam_string __param_string_##name \ |
92 | = { len, string }; \ | 96 | = { len, string }; \ |
93 | module_param_call(name, param_set_copystring, param_get_string, \ | 97 | module_param_call(name, param_set_copystring, param_get_string, \ |
94 | &__param_string_##name, perm); \ | 98 | .str = &__param_string_##name, perm); \ |
95 | __MODULE_PARM_TYPE(name, "string") | 99 | __MODULE_PARM_TYPE(name, "string") |
96 | 100 | ||
97 | /* Called on module insert or kernel boot */ | 101 | /* Called on module insert or kernel boot */ |
@@ -149,11 +153,11 @@ extern int param_get_invbool(char *buffer, struct kernel_param *kp); | |||
149 | 153 | ||
150 | /* Comma-separated array: *nump is set to number they actually specified. */ | 154 | /* Comma-separated array: *nump is set to number they actually specified. */ |
151 | #define module_param_array_named(name, array, type, nump, perm) \ | 155 | #define module_param_array_named(name, array, type, nump, perm) \ |
152 | static struct kparam_array __param_arr_##name \ | 156 | static const struct kparam_array __param_arr_##name \ |
153 | = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\ | 157 | = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\ |
154 | sizeof(array[0]), array }; \ | 158 | sizeof(array[0]), array }; \ |
155 | module_param_call(name, param_array_set, param_array_get, \ | 159 | module_param_call(name, param_array_set, param_array_get, \ |
156 | &__param_arr_##name, perm); \ | 160 | .arr = &__param_arr_##name, perm); \ |
157 | __MODULE_PARM_TYPE(name, "array of " #type) | 161 | __MODULE_PARM_TYPE(name, "array of " #type) |
158 | 162 | ||
159 | #define module_param_array(name, type, nump, perm) \ | 163 | #define module_param_array(name, type, nump, perm) \ |
diff --git a/kernel/params.c b/kernel/params.c index 4e57732fcfb4..1d6aca288cdc 100644 --- a/kernel/params.c +++ b/kernel/params.c | |||
@@ -252,8 +252,9 @@ int param_get_bool(char *buffer, struct kernel_param *kp) | |||
252 | int param_set_invbool(const char *val, struct kernel_param *kp) | 252 | int param_set_invbool(const char *val, struct kernel_param *kp) |
253 | { | 253 | { |
254 | int boolval, ret; | 254 | int boolval, ret; |
255 | struct kernel_param dummy = { .arg = &boolval }; | 255 | struct kernel_param dummy; |
256 | 256 | ||
257 | dummy.arg = &boolval; | ||
257 | ret = param_set_bool(val, &dummy); | 258 | ret = param_set_bool(val, &dummy); |
258 | if (ret == 0) | 259 | if (ret == 0) |
259 | *(int *)kp->arg = !boolval; | 260 | *(int *)kp->arg = !boolval; |
@@ -262,11 +263,7 @@ int param_set_invbool(const char *val, struct kernel_param *kp) | |||
262 | 263 | ||
263 | int param_get_invbool(char *buffer, struct kernel_param *kp) | 264 | int param_get_invbool(char *buffer, struct kernel_param *kp) |
264 | { | 265 | { |
265 | int val; | 266 | return sprintf(buffer, "%c", (*(int *)kp->arg) ? 'N' : 'Y'); |
266 | struct kernel_param dummy = { .arg = &val }; | ||
267 | |||
268 | val = !*(int *)kp->arg; | ||
269 | return param_get_bool(buffer, &dummy); | ||
270 | } | 267 | } |
271 | 268 | ||
272 | /* We break the rule and mangle the string. */ | 269 | /* We break the rule and mangle the string. */ |
@@ -325,7 +322,7 @@ static int param_array(const char *name, | |||
325 | 322 | ||
326 | int param_array_set(const char *val, struct kernel_param *kp) | 323 | int param_array_set(const char *val, struct kernel_param *kp) |
327 | { | 324 | { |
328 | struct kparam_array *arr = kp->arg; | 325 | const struct kparam_array *arr = kp->arr; |
329 | unsigned int temp_num; | 326 | unsigned int temp_num; |
330 | 327 | ||
331 | return param_array(kp->name, val, 1, arr->max, arr->elem, | 328 | return param_array(kp->name, val, 1, arr->max, arr->elem, |
@@ -335,7 +332,7 @@ int param_array_set(const char *val, struct kernel_param *kp) | |||
335 | int param_array_get(char *buffer, struct kernel_param *kp) | 332 | int param_array_get(char *buffer, struct kernel_param *kp) |
336 | { | 333 | { |
337 | int i, off, ret; | 334 | int i, off, ret; |
338 | struct kparam_array *arr = kp->arg; | 335 | const struct kparam_array *arr = kp->arr; |
339 | struct kernel_param p; | 336 | struct kernel_param p; |
340 | 337 | ||
341 | p = *kp; | 338 | p = *kp; |
@@ -354,7 +351,7 @@ int param_array_get(char *buffer, struct kernel_param *kp) | |||
354 | 351 | ||
355 | int param_set_copystring(const char *val, struct kernel_param *kp) | 352 | int param_set_copystring(const char *val, struct kernel_param *kp) |
356 | { | 353 | { |
357 | struct kparam_string *kps = kp->arg; | 354 | const struct kparam_string *kps = kp->str; |
358 | 355 | ||
359 | if (!val) { | 356 | if (!val) { |
360 | printk(KERN_ERR "%s: missing param set value\n", kp->name); | 357 | printk(KERN_ERR "%s: missing param set value\n", kp->name); |
@@ -371,7 +368,7 @@ int param_set_copystring(const char *val, struct kernel_param *kp) | |||
371 | 368 | ||
372 | int param_get_string(char *buffer, struct kernel_param *kp) | 369 | int param_get_string(char *buffer, struct kernel_param *kp) |
373 | { | 370 | { |
374 | struct kparam_string *kps = kp->arg; | 371 | const struct kparam_string *kps = kp->str; |
375 | return strlcpy(buffer, kps->string, kps->maxlen); | 372 | return strlcpy(buffer, kps->string, kps->maxlen); |
376 | } | 373 | } |
377 | 374 | ||