aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2010-08-12 01:04:12 -0400
committerRusty Russell <rusty@rustcorp.com.au>2010-08-11 09:34:13 -0400
commit9bbb9e5a33109b2832e2e63dcc7a132924ab374b (patch)
tree87270ed3a61d0d0e654a61c8d44504cdef330192 /include
parenta14fe249a8f74269c9e636bcbaa78f5bdb354ce3 (diff)
param: use ops in struct kernel_param, rather than get and set fns directly
This is more kernel-ish, saves some space, and also allows us to expand the ops without breaking all the callers who are happy for the new members to be NULL. The few places which defined their own param types are changed to the new scheme (more which crept in recently fixed in following patches). Since we're touching them anyway, we change get() and set() to take a const struct kernel_param (which they really are). This causes some harmless warnings until we fix them (in following patches). To reduce churn, module_param_call creates the ops struct so the callers don't have to change (and casts the functions to reduce warnings). The modern version which takes an ops struct is called module_param_cb. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Reviewed-by: Takashi Iwai <tiwai@suse.de> Tested-by: Phil Carmody <ext-phil.2.carmody@nokia.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Ville Syrjala <syrjala@sci.fi> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: Alessandro Rubini <rubini@ipvvis.unipv.it> Cc: Michal Januszewski <spock@gentoo.org> Cc: Trond Myklebust <Trond.Myklebust@netapp.com> Cc: "J. Bruce Fields" <bfields@fieldses.org> Cc: Neil Brown <neilb@suse.de> Cc: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org Cc: linux-fbdev-devel@lists.sourceforge.net Cc: linux-nfs@vger.kernel.org Cc: netdev@vger.kernel.org
Diffstat (limited to 'include')
-rw-r--r--include/linux/moduleparam.h123
1 files changed, 75 insertions, 48 deletions
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 82a9124f7d75..02e5090ce32f 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -31,20 +31,21 @@ static const char __module_cat(name,__LINE__)[] \
31 31
32struct kernel_param; 32struct kernel_param;
33 33
34/* Returns 0, or -errno. arg is in kp->arg. */ 34struct kernel_param_ops {
35typedef int (*param_set_fn)(const char *val, struct kernel_param *kp); 35 /* Returns 0, or -errno. arg is in kp->arg. */
36/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ 36 int (*set)(const char *val, const struct kernel_param *kp);
37typedef int (*param_get_fn)(char *buffer, struct kernel_param *kp); 37 /* Returns length written or -errno. Buffer is 4k (ie. be short!) */
38 int (*get)(char *buffer, const struct kernel_param *kp);
39};
38 40
39/* Flag bits for kernel_param.flags */ 41/* Flag bits for kernel_param.flags */
40#define KPARAM_ISBOOL 2 42#define KPARAM_ISBOOL 2
41 43
42struct kernel_param { 44struct kernel_param {
43 const char *name; 45 const char *name;
46 const struct kernel_param_ops *ops;
44 u16 perm; 47 u16 perm;
45 u16 flags; 48 u16 flags;
46 param_set_fn set;
47 param_get_fn get;
48 union { 49 union {
49 void *arg; 50 void *arg;
50 const struct kparam_string *str; 51 const struct kparam_string *str;
@@ -63,8 +64,7 @@ struct kparam_array
63{ 64{
64 unsigned int max; 65 unsigned int max;
65 unsigned int *num; 66 unsigned int *num;
66 param_set_fn set; 67 const struct kernel_param_ops *ops;
67 param_get_fn get;
68 unsigned int elemsize; 68 unsigned int elemsize;
69 void *elem; 69 void *elem;
70}; 70};
@@ -83,7 +83,7 @@ struct kparam_array
83 parameters. perm sets the visibility in sysfs: 000 means it's 83 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 84 not there, read bits mean it's readable, write bits mean it's
85 writable. */ 85 writable. */
86#define __module_param_call(prefix, name, set, get, arg, isbool, perm) \ 86#define __module_param_call(prefix, name, ops, arg, isbool, perm) \
87 /* Default value instead of permissions? */ \ 87 /* Default value instead of permissions? */ \
88 static int __param_perm_check_##name __attribute__((unused)) = \ 88 static int __param_perm_check_##name __attribute__((unused)) = \
89 BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \ 89 BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)) \
@@ -92,20 +92,37 @@ struct kparam_array
92 static struct kernel_param __moduleparam_const __param_##name \ 92 static struct kernel_param __moduleparam_const __param_##name \
93 __used \ 93 __used \
94 __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \ 94 __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
95 = { __param_str_##name, perm, isbool ? KPARAM_ISBOOL : 0, \ 95 = { __param_str_##name, ops, perm, isbool ? KPARAM_ISBOOL : 0, \
96 set, get, { arg } } 96 { arg } }
97
98/* Obsolete - use module_param_cb() */
99#define module_param_call(name, set, get, arg, perm) \
100 static struct kernel_param_ops __param_ops_##name = \
101 { (void *)set, (void *)get }; \
102 __module_param_call(MODULE_PARAM_PREFIX, \
103 name, &__param_ops_##name, arg, \
104 __same_type(*(arg), bool), \
105 (perm) + sizeof(__check_old_set_param(set))*0)
106
107/* We don't get oldget: it's often a new-style param_get_uint, etc. */
108static inline int
109__check_old_set_param(int (*oldset)(const char *, struct kernel_param *))
110{
111 return 0;
112}
97 113
98#define module_param_call(name, set, get, arg, perm) \ 114#define module_param_cb(name, ops, arg, perm) \
99 __module_param_call(MODULE_PARAM_PREFIX, \ 115 __module_param_call(MODULE_PARAM_PREFIX, \
100 name, set, get, arg, \ 116 name, ops, arg, __same_type(*(arg), bool), perm)
101 __same_type(*(arg), bool), perm)
102 117
103/* Helper functions: type is byte, short, ushort, int, uint, long, 118/*
104 ulong, charp, bool or invbool, or XXX if you define param_get_XXX, 119 * Helper functions: type is byte, short, ushort, int, uint, long,
105 param_set_XXX and param_check_XXX. */ 120 * ulong, charp, bool or invbool, or XXX if you define param_ops_XXX
121 * and param_check_XXX.
122 */
106#define module_param_named(name, value, type, perm) \ 123#define module_param_named(name, value, type, perm) \
107 param_check_##type(name, &(value)); \ 124 param_check_##type(name, &(value)); \
108 module_param_call(name, param_set_##type, param_get_##type, &value, perm); \ 125 module_param_cb(name, &param_ops_##type, &value, perm); \
109 __MODULE_PARM_TYPE(name, #type) 126 __MODULE_PARM_TYPE(name, #type)
110 127
111#define module_param(name, type, perm) \ 128#define module_param(name, type, perm) \
@@ -126,7 +143,7 @@ struct kparam_array
126 */ 143 */
127#define core_param(name, var, type, perm) \ 144#define core_param(name, var, type, perm) \
128 param_check_##type(name, &(var)); \ 145 param_check_##type(name, &(var)); \
129 __module_param_call("", name, param_set_##type, param_get_##type, \ 146 __module_param_call("", name, &param_ops_##type, \
130 &var, __same_type(var, bool), perm) 147 &var, __same_type(var, bool), perm)
131#endif /* !MODULE */ 148#endif /* !MODULE */
132 149
@@ -135,7 +152,7 @@ struct kparam_array
135 static const struct kparam_string __param_string_##name \ 152 static const struct kparam_string __param_string_##name \
136 = { len, string }; \ 153 = { len, string }; \
137 __module_param_call(MODULE_PARAM_PREFIX, name, \ 154 __module_param_call(MODULE_PARAM_PREFIX, name, \
138 param_set_copystring, param_get_string, \ 155 &param_ops_string, \
139 .str = &__param_string_##name, 0, perm); \ 156 .str = &__param_string_##name, 0, perm); \
140 __MODULE_PARM_TYPE(name, "string") 157 __MODULE_PARM_TYPE(name, "string")
141 158
@@ -162,41 +179,50 @@ static inline void destroy_params(const struct kernel_param *params,
162#define __param_check(name, p, type) \ 179#define __param_check(name, p, type) \
163 static inline type *__check_##name(void) { return(p); } 180 static inline type *__check_##name(void) { return(p); }
164 181
165extern int param_set_byte(const char *val, struct kernel_param *kp); 182extern struct kernel_param_ops param_ops_byte;
166extern int param_get_byte(char *buffer, struct kernel_param *kp); 183extern int param_set_byte(const char *val, const struct kernel_param *kp);
184extern int param_get_byte(char *buffer, const struct kernel_param *kp);
167#define param_check_byte(name, p) __param_check(name, p, unsigned char) 185#define param_check_byte(name, p) __param_check(name, p, unsigned char)
168 186
169extern int param_set_short(const char *val, struct kernel_param *kp); 187extern struct kernel_param_ops param_ops_short;
170extern int param_get_short(char *buffer, struct kernel_param *kp); 188extern int param_set_short(const char *val, const struct kernel_param *kp);
189extern int param_get_short(char *buffer, const struct kernel_param *kp);
171#define param_check_short(name, p) __param_check(name, p, short) 190#define param_check_short(name, p) __param_check(name, p, short)
172 191
173extern int param_set_ushort(const char *val, struct kernel_param *kp); 192extern struct kernel_param_ops param_ops_ushort;
174extern int param_get_ushort(char *buffer, struct kernel_param *kp); 193extern int param_set_ushort(const char *val, const struct kernel_param *kp);
194extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
175#define param_check_ushort(name, p) __param_check(name, p, unsigned short) 195#define param_check_ushort(name, p) __param_check(name, p, unsigned short)
176 196
177extern int param_set_int(const char *val, struct kernel_param *kp); 197extern struct kernel_param_ops param_ops_int;
178extern int param_get_int(char *buffer, struct kernel_param *kp); 198extern int param_set_int(const char *val, const struct kernel_param *kp);
199extern int param_get_int(char *buffer, const struct kernel_param *kp);
179#define param_check_int(name, p) __param_check(name, p, int) 200#define param_check_int(name, p) __param_check(name, p, int)
180 201
181extern int param_set_uint(const char *val, struct kernel_param *kp); 202extern struct kernel_param_ops param_ops_uint;
182extern int param_get_uint(char *buffer, struct kernel_param *kp); 203extern int param_set_uint(const char *val, const struct kernel_param *kp);
204extern int param_get_uint(char *buffer, const struct kernel_param *kp);
183#define param_check_uint(name, p) __param_check(name, p, unsigned int) 205#define param_check_uint(name, p) __param_check(name, p, unsigned int)
184 206
185extern int param_set_long(const char *val, struct kernel_param *kp); 207extern struct kernel_param_ops param_ops_long;
186extern int param_get_long(char *buffer, struct kernel_param *kp); 208extern int param_set_long(const char *val, const struct kernel_param *kp);
209extern int param_get_long(char *buffer, const struct kernel_param *kp);
187#define param_check_long(name, p) __param_check(name, p, long) 210#define param_check_long(name, p) __param_check(name, p, long)
188 211
189extern int param_set_ulong(const char *val, struct kernel_param *kp); 212extern struct kernel_param_ops param_ops_ulong;
190extern int param_get_ulong(char *buffer, struct kernel_param *kp); 213extern int param_set_ulong(const char *val, const struct kernel_param *kp);
214extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
191#define param_check_ulong(name, p) __param_check(name, p, unsigned long) 215#define param_check_ulong(name, p) __param_check(name, p, unsigned long)
192 216
193extern int param_set_charp(const char *val, struct kernel_param *kp); 217extern struct kernel_param_ops param_ops_charp;
194extern int param_get_charp(char *buffer, struct kernel_param *kp); 218extern int param_set_charp(const char *val, const struct kernel_param *kp);
219extern int param_get_charp(char *buffer, const struct kernel_param *kp);
195#define param_check_charp(name, p) __param_check(name, p, char *) 220#define param_check_charp(name, p) __param_check(name, p, char *)
196 221
197/* For historical reasons "bool" parameters can be (unsigned) "int". */ 222/* For historical reasons "bool" parameters can be (unsigned) "int". */
198extern int param_set_bool(const char *val, struct kernel_param *kp); 223extern struct kernel_param_ops param_ops_bool;
199extern int param_get_bool(char *buffer, struct kernel_param *kp); 224extern int param_set_bool(const char *val, const struct kernel_param *kp);
225extern int param_get_bool(char *buffer, const struct kernel_param *kp);
200#define param_check_bool(name, p) \ 226#define param_check_bool(name, p) \
201 static inline void __check_##name(void) \ 227 static inline void __check_##name(void) \
202 { \ 228 { \
@@ -205,17 +231,18 @@ extern int param_get_bool(char *buffer, struct kernel_param *kp);
205 !__same_type(*(p), int)); \ 231 !__same_type(*(p), int)); \
206 } 232 }
207 233
208extern int param_set_invbool(const char *val, struct kernel_param *kp); 234extern struct kernel_param_ops param_ops_invbool;
209extern int param_get_invbool(char *buffer, struct kernel_param *kp); 235extern int param_set_invbool(const char *val, const struct kernel_param *kp);
236extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
210#define param_check_invbool(name, p) __param_check(name, p, bool) 237#define param_check_invbool(name, p) __param_check(name, p, bool)
211 238
212/* Comma-separated array: *nump is set to number they actually specified. */ 239/* Comma-separated array: *nump is set to number they actually specified. */
213#define module_param_array_named(name, array, type, nump, perm) \ 240#define module_param_array_named(name, array, type, nump, perm) \
214 static const struct kparam_array __param_arr_##name \ 241 static const struct kparam_array __param_arr_##name \
215 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\ 242 = { ARRAY_SIZE(array), nump, &param_ops_##type, \
216 sizeof(array[0]), array }; \ 243 sizeof(array[0]), array }; \
217 __module_param_call(MODULE_PARAM_PREFIX, name, \ 244 __module_param_call(MODULE_PARAM_PREFIX, name, \
218 param_array_set, param_array_get, \ 245 &param_array_ops, \
219 .arr = &__param_arr_##name, \ 246 .arr = &__param_arr_##name, \
220 __same_type(array[0], bool), perm); \ 247 __same_type(array[0], bool), perm); \
221 __MODULE_PARM_TYPE(name, "array of " #type) 248 __MODULE_PARM_TYPE(name, "array of " #type)
@@ -223,11 +250,11 @@ extern int param_get_invbool(char *buffer, struct kernel_param *kp);
223#define module_param_array(name, type, nump, perm) \ 250#define module_param_array(name, type, nump, perm) \
224 module_param_array_named(name, name, type, nump, perm) 251 module_param_array_named(name, name, type, nump, perm)
225 252
226extern int param_array_set(const char *val, struct kernel_param *kp); 253extern struct kernel_param_ops param_array_ops;
227extern int param_array_get(char *buffer, struct kernel_param *kp);
228 254
229extern int param_set_copystring(const char *val, struct kernel_param *kp); 255extern struct kernel_param_ops param_ops_string;
230extern int param_get_string(char *buffer, struct kernel_param *kp); 256extern int param_set_copystring(const char *val, const struct kernel_param *);
257extern int param_get_string(char *buffer, const struct kernel_param *kp);
231 258
232/* for exporting parameters in /sys/parameters */ 259/* for exporting parameters in /sys/parameters */
233 260
@@ -235,13 +262,13 @@ struct module;
235 262
236#if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES) 263#if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
237extern int module_param_sysfs_setup(struct module *mod, 264extern int module_param_sysfs_setup(struct module *mod,
238 struct kernel_param *kparam, 265 const struct kernel_param *kparam,
239 unsigned int num_params); 266 unsigned int num_params);
240 267
241extern void module_param_sysfs_remove(struct module *mod); 268extern void module_param_sysfs_remove(struct module *mod);
242#else 269#else
243static inline int module_param_sysfs_setup(struct module *mod, 270static inline int module_param_sysfs_setup(struct module *mod,
244 struct kernel_param *kparam, 271 const struct kernel_param *kparam,
245 unsigned int num_params) 272 unsigned int num_params)
246{ 273{
247 return 0; 274 return 0;