diff options
author | Felipe Contreras <felipe.contreras@gmail.com> | 2013-12-03 22:39:38 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2013-12-03 22:39:46 -0500 |
commit | 88a88b320a9068294aaa2841464e4809af2ff454 (patch) | |
tree | 0b7406095ad04d44e787b0349ab517bdfa79facf /kernel/params.c | |
parent | 160e01aca3daa7c09da86748b08914cdfaca539f (diff) |
params: improve standard definitions
We are repeating the functionality of kstrtol in param_set_long, and the
same for kstrtoint. We can get rid of the extra code by using the right
functions.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'kernel/params.c')
-rw-r--r-- | kernel/params.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/kernel/params.c b/kernel/params.c index c00d5b502aa4..b00142e7f3ba 100644 --- a/kernel/params.c +++ b/kernel/params.c | |||
@@ -227,17 +227,10 @@ int parse_args(const char *doing, | |||
227 | } | 227 | } |
228 | 228 | ||
229 | /* Lazy bastard, eh? */ | 229 | /* Lazy bastard, eh? */ |
230 | #define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn) \ | 230 | #define STANDARD_PARAM_DEF(name, type, format, strtolfn) \ |
231 | int param_set_##name(const char *val, const struct kernel_param *kp) \ | 231 | int param_set_##name(const char *val, const struct kernel_param *kp) \ |
232 | { \ | 232 | { \ |
233 | tmptype l; \ | 233 | return strtolfn(val, 0, (type *)kp->arg); \ |
234 | int ret; \ | ||
235 | \ | ||
236 | ret = strtolfn(val, 0, &l); \ | ||
237 | if (ret < 0 || ((type)l != l)) \ | ||
238 | return ret < 0 ? ret : -EINVAL; \ | ||
239 | *((type *)kp->arg) = l; \ | ||
240 | return 0; \ | ||
241 | } \ | 234 | } \ |
242 | int param_get_##name(char *buffer, const struct kernel_param *kp) \ | 235 | int param_get_##name(char *buffer, const struct kernel_param *kp) \ |
243 | { \ | 236 | { \ |
@@ -253,13 +246,13 @@ int parse_args(const char *doing, | |||
253 | EXPORT_SYMBOL(param_ops_##name) | 246 | EXPORT_SYMBOL(param_ops_##name) |
254 | 247 | ||
255 | 248 | ||
256 | STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", unsigned long, kstrtoul); | 249 | STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", kstrtou8); |
257 | STANDARD_PARAM_DEF(short, short, "%hi", long, kstrtol); | 250 | STANDARD_PARAM_DEF(short, short, "%hi", kstrtos16); |
258 | STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, kstrtoul); | 251 | STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", kstrtou16); |
259 | STANDARD_PARAM_DEF(int, int, "%i", long, kstrtol); | 252 | STANDARD_PARAM_DEF(int, int, "%i", kstrtoint); |
260 | STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, kstrtoul); | 253 | STANDARD_PARAM_DEF(uint, unsigned int, "%u", kstrtouint); |
261 | STANDARD_PARAM_DEF(long, long, "%li", long, kstrtol); | 254 | STANDARD_PARAM_DEF(long, long, "%li", kstrtol); |
262 | STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, kstrtoul); | 255 | STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", kstrtoul); |
263 | 256 | ||
264 | int param_set_charp(const char *val, const struct kernel_param *kp) | 257 | int param_set_charp(const char *val, const struct kernel_param *kp) |
265 | { | 258 | { |