aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--include/linux/moduleparam.h32
-rw-r--r--kernel/params.c33
2 files changed, 49 insertions, 16 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
42struct kernel_param { 43struct 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);
190extern int param_get_charp(char *buffer, struct kernel_param *kp); 195extern 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". */
193extern int param_set_bool(const char *val, struct kernel_param *kp); 199extern int param_set_bool(const char *val, struct kernel_param *kp);
194extern int param_get_bool(char *buffer, struct kernel_param *kp); 200extern 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
197extern int param_set_invbool(const char *val, struct kernel_param *kp); 209extern int param_set_invbool(const char *val, struct kernel_param *kp);
198extern int param_get_invbool(char *buffer, struct kernel_param *kp); 210extern 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) \
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;