diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2010-08-12 01:04:12 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2010-08-11 09:34:13 -0400 |
commit | 9bbb9e5a33109b2832e2e63dcc7a132924ab374b (patch) | |
tree | 87270ed3a61d0d0e654a61c8d44504cdef330192 /include/linux | |
parent | a14fe249a8f74269c9e636bcbaa78f5bdb354ce3 (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/linux')
-rw-r--r-- | include/linux/moduleparam.h | 123 |
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 | ||
32 | struct kernel_param; | 32 | struct kernel_param; |
33 | 33 | ||
34 | /* Returns 0, or -errno. arg is in kp->arg. */ | 34 | struct kernel_param_ops { |
35 | typedef 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); |
37 | typedef 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 | ||
42 | struct kernel_param { | 44 | struct 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. */ | ||
108 | static 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, ¶m_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, ¶m_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 | ¶m_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 | ||
165 | extern int param_set_byte(const char *val, struct kernel_param *kp); | 182 | extern struct kernel_param_ops param_ops_byte; |
166 | extern int param_get_byte(char *buffer, struct kernel_param *kp); | 183 | extern int param_set_byte(const char *val, const struct kernel_param *kp); |
184 | extern 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 | ||
169 | extern int param_set_short(const char *val, struct kernel_param *kp); | 187 | extern struct kernel_param_ops param_ops_short; |
170 | extern int param_get_short(char *buffer, struct kernel_param *kp); | 188 | extern int param_set_short(const char *val, const struct kernel_param *kp); |
189 | extern 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 | ||
173 | extern int param_set_ushort(const char *val, struct kernel_param *kp); | 192 | extern struct kernel_param_ops param_ops_ushort; |
174 | extern int param_get_ushort(char *buffer, struct kernel_param *kp); | 193 | extern int param_set_ushort(const char *val, const struct kernel_param *kp); |
194 | extern 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 | ||
177 | extern int param_set_int(const char *val, struct kernel_param *kp); | 197 | extern struct kernel_param_ops param_ops_int; |
178 | extern int param_get_int(char *buffer, struct kernel_param *kp); | 198 | extern int param_set_int(const char *val, const struct kernel_param *kp); |
199 | extern 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 | ||
181 | extern int param_set_uint(const char *val, struct kernel_param *kp); | 202 | extern struct kernel_param_ops param_ops_uint; |
182 | extern int param_get_uint(char *buffer, struct kernel_param *kp); | 203 | extern int param_set_uint(const char *val, const struct kernel_param *kp); |
204 | extern 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 | ||
185 | extern int param_set_long(const char *val, struct kernel_param *kp); | 207 | extern struct kernel_param_ops param_ops_long; |
186 | extern int param_get_long(char *buffer, struct kernel_param *kp); | 208 | extern int param_set_long(const char *val, const struct kernel_param *kp); |
209 | extern 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 | ||
189 | extern int param_set_ulong(const char *val, struct kernel_param *kp); | 212 | extern struct kernel_param_ops param_ops_ulong; |
190 | extern int param_get_ulong(char *buffer, struct kernel_param *kp); | 213 | extern int param_set_ulong(const char *val, const struct kernel_param *kp); |
214 | extern 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 | ||
193 | extern int param_set_charp(const char *val, struct kernel_param *kp); | 217 | extern struct kernel_param_ops param_ops_charp; |
194 | extern int param_get_charp(char *buffer, struct kernel_param *kp); | 218 | extern int param_set_charp(const char *val, const struct kernel_param *kp); |
219 | extern 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". */ |
198 | extern int param_set_bool(const char *val, struct kernel_param *kp); | 223 | extern struct kernel_param_ops param_ops_bool; |
199 | extern int param_get_bool(char *buffer, struct kernel_param *kp); | 224 | extern int param_set_bool(const char *val, const struct kernel_param *kp); |
225 | extern 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 | ||
208 | extern int param_set_invbool(const char *val, struct kernel_param *kp); | 234 | extern struct kernel_param_ops param_ops_invbool; |
209 | extern int param_get_invbool(char *buffer, struct kernel_param *kp); | 235 | extern int param_set_invbool(const char *val, const struct kernel_param *kp); |
236 | extern 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, ¶m_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 | ¶m_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 | ||
226 | extern int param_array_set(const char *val, struct kernel_param *kp); | 253 | extern struct kernel_param_ops param_array_ops; |
227 | extern int param_array_get(char *buffer, struct kernel_param *kp); | ||
228 | 254 | ||
229 | extern int param_set_copystring(const char *val, struct kernel_param *kp); | 255 | extern struct kernel_param_ops param_ops_string; |
230 | extern int param_get_string(char *buffer, struct kernel_param *kp); | 256 | extern int param_set_copystring(const char *val, const struct kernel_param *); |
257 | extern 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) |
237 | extern int module_param_sysfs_setup(struct module *mod, | 264 | extern 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 | ||
241 | extern void module_param_sysfs_remove(struct module *mod); | 268 | extern void module_param_sysfs_remove(struct module *mod); |
242 | #else | 269 | #else |
243 | static inline int module_param_sysfs_setup(struct module *mod, | 270 | static 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; |