diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2009-06-12 23:46:57 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2009-06-12 08:16:58 -0400 |
commit | fddd520122953550ec2c8b60e7ca0d0f0d115d97 (patch) | |
tree | d0c45f94bc0054661ee9af41b607815c24a36cff /include/linux/moduleparam.h | |
parent | d2c123c27db841c6c11a63de9c144823d2b1ba76 (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 'include/linux/moduleparam.h')
-rw-r--r-- | include/linux/moduleparam.h | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h index 009a5f768768..6547c3cdbc4c 100644 --- a/include/linux/moduleparam.h +++ b/include/linux/moduleparam.h | |||
@@ -38,6 +38,7 @@ typedef int (*param_get_fn)(char *buffer, struct kernel_param *kp); | |||
38 | 38 | ||
39 | /* Flag bits for kernel_param.flags */ | 39 | /* Flag bits for kernel_param.flags */ |
40 | #define KPARAM_KMALLOCED 1 | 40 | #define KPARAM_KMALLOCED 1 |
41 | #define KPARAM_ISBOOL 2 | ||
41 | 42 | ||
42 | struct kernel_param { | 43 | struct kernel_param { |
43 | const char *name; | 44 | const char *name; |
@@ -83,7 +84,7 @@ struct kparam_array | |||
83 | parameters. perm sets the visibility in sysfs: 000 means it's | 84 | parameters. perm sets the visibility in sysfs: 000 means it's |
84 | not there, read bits mean it's readable, write bits mean it's | 85 | not there, read bits mean it's readable, write bits mean it's |
85 | writable. */ | 86 | writable. */ |
86 | #define __module_param_call(prefix, name, set, get, arg, perm) \ | 87 | #define __module_param_call(prefix, name, set, get, arg, isbool, perm) \ |
87 | /* Default value instead of permissions? */ \ | 88 | /* Default value instead of permissions? */ \ |
88 | static int __param_perm_check_##name __attribute__((unused)) = \ | 89 | static int __param_perm_check_##name __attribute__((unused)) = \ |
89 | BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \ | 90 | BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \ |
@@ -92,10 +93,13 @@ struct kparam_array | |||
92 | static struct kernel_param __moduleparam_const __param_##name \ | 93 | static struct kernel_param __moduleparam_const __param_##name \ |
93 | __used \ | 94 | __used \ |
94 | __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ | 95 | __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ |
95 | = { __param_str_##name, perm, 0, set, get, { arg } } | 96 | = { __param_str_##name, perm, isbool ? KPARAM_ISBOOL : 0, \ |
97 | set, get, { arg } } | ||
96 | 98 | ||
97 | #define module_param_call(name, set, get, arg, perm) \ | 99 | #define module_param_call(name, set, get, arg, perm) \ |
98 | __module_param_call(MODULE_PARAM_PREFIX, name, set, get, arg, perm) | 100 | __module_param_call(MODULE_PARAM_PREFIX, \ |
101 | name, set, get, arg, \ | ||
102 | __same_type(*(arg), bool), perm) | ||
99 | 103 | ||
100 | /* Helper functions: type is byte, short, ushort, int, uint, long, | 104 | /* Helper functions: type is byte, short, ushort, int, uint, long, |
101 | ulong, charp, bool or invbool, or XXX if you define param_get_XXX, | 105 | ulong, charp, bool or invbool, or XXX if you define param_get_XXX, |
@@ -124,15 +128,16 @@ struct kparam_array | |||
124 | #define core_param(name, var, type, perm) \ | 128 | #define core_param(name, var, type, perm) \ |
125 | param_check_##type(name, &(var)); \ | 129 | param_check_##type(name, &(var)); \ |
126 | __module_param_call("", name, param_set_##type, param_get_##type, \ | 130 | __module_param_call("", name, param_set_##type, param_get_##type, \ |
127 | &var, perm) | 131 | &var, __same_type(var, bool), perm) |
128 | #endif /* !MODULE */ | 132 | #endif /* !MODULE */ |
129 | 133 | ||
130 | /* Actually copy string: maxlen param is usually sizeof(string). */ | 134 | /* Actually copy string: maxlen param is usually sizeof(string). */ |
131 | #define module_param_string(name, string, len, perm) \ | 135 | #define module_param_string(name, string, len, perm) \ |
132 | static const struct kparam_string __param_string_##name \ | 136 | static const struct kparam_string __param_string_##name \ |
133 | = { len, string }; \ | 137 | = { len, string }; \ |
134 | module_param_call(name, param_set_copystring, param_get_string, \ | 138 | __module_param_call(MODULE_PARAM_PREFIX, name, \ |
135 | .str = &__param_string_##name, perm); \ | 139 | param_set_copystring, param_get_string, \ |
140 | .str = &__param_string_##name, 0, perm); \ | ||
136 | __MODULE_PARM_TYPE(name, "string") | 141 | __MODULE_PARM_TYPE(name, "string") |
137 | 142 | ||
138 | /* Called on module insert or kernel boot */ | 143 | /* Called on module insert or kernel boot */ |
@@ -190,9 +195,16 @@ extern int param_set_charp(const char *val, struct kernel_param *kp); | |||
190 | extern int param_get_charp(char *buffer, struct kernel_param *kp); | 195 | extern int param_get_charp(char *buffer, struct kernel_param *kp); |
191 | #define param_check_charp(name, p) __param_check(name, p, char *) | 196 | #define param_check_charp(name, p) __param_check(name, p, char *) |
192 | 197 | ||
198 | /* For historical reasons "bool" parameters can be (unsigned) "int". */ | ||
193 | extern int param_set_bool(const char *val, struct kernel_param *kp); | 199 | extern int param_set_bool(const char *val, struct kernel_param *kp); |
194 | extern int param_get_bool(char *buffer, struct kernel_param *kp); | 200 | extern int param_get_bool(char *buffer, struct kernel_param *kp); |
195 | #define param_check_bool(name, p) __param_check(name, p, int) | 201 | #define param_check_bool(name, p) \ |
202 | static inline void __check_##name(void) \ | ||
203 | { \ | ||
204 | BUILD_BUG_ON(!__same_type(*(p), bool) && \ | ||
205 | !__same_type(*(p), unsigned int) && \ | ||
206 | !__same_type(*(p), int)); \ | ||
207 | } | ||
196 | 208 | ||
197 | extern int param_set_invbool(const char *val, struct kernel_param *kp); | 209 | extern int param_set_invbool(const char *val, struct kernel_param *kp); |
198 | extern int param_get_invbool(char *buffer, struct kernel_param *kp); | 210 | extern int param_get_invbool(char *buffer, struct kernel_param *kp); |
@@ -203,8 +215,10 @@ extern int param_get_invbool(char *buffer, struct kernel_param *kp); | |||
203 | static const struct kparam_array __param_arr_##name \ | 215 | static const struct kparam_array __param_arr_##name \ |
204 | = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\ | 216 | = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\ |
205 | sizeof(array[0]), array }; \ | 217 | sizeof(array[0]), array }; \ |
206 | module_param_call(name, param_array_set, param_array_get, \ | 218 | __module_param_call(MODULE_PARAM_PREFIX, name, \ |
207 | .arr = &__param_arr_##name, perm); \ | 219 | param_array_set, param_array_get, \ |
220 | .arr = &__param_arr_##name, \ | ||
221 | __same_type(array[0], bool), perm); \ | ||
208 | __MODULE_PARM_TYPE(name, "array of " #type) | 222 | __MODULE_PARM_TYPE(name, "array of " #type) |
209 | 223 | ||
210 | #define module_param_array(name, type, nump, perm) \ | 224 | #define module_param_array(name, type, nump, perm) \ |