aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/params.c
diff options
context:
space:
mode:
authorFelipe Contreras <felipe.contreras@gmail.com>2013-12-03 22:39:38 -0500
committerRusty Russell <rusty@rustcorp.com.au>2013-12-03 22:39:46 -0500
commit88a88b320a9068294aaa2841464e4809af2ff454 (patch)
tree0b7406095ad04d44e787b0349ab517bdfa79facf /kernel/params.c
parent160e01aca3daa7c09da86748b08914cdfaca539f (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.c25
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
256STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", unsigned long, kstrtoul); 249STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", kstrtou8);
257STANDARD_PARAM_DEF(short, short, "%hi", long, kstrtol); 250STANDARD_PARAM_DEF(short, short, "%hi", kstrtos16);
258STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, kstrtoul); 251STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", kstrtou16);
259STANDARD_PARAM_DEF(int, int, "%i", long, kstrtol); 252STANDARD_PARAM_DEF(int, int, "%i", kstrtoint);
260STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, kstrtoul); 253STANDARD_PARAM_DEF(uint, unsigned int, "%u", kstrtouint);
261STANDARD_PARAM_DEF(long, long, "%li", long, kstrtol); 254STANDARD_PARAM_DEF(long, long, "%li", kstrtol);
262STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, kstrtoul); 255STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", kstrtoul);
263 256
264int param_set_charp(const char *val, const struct kernel_param *kp) 257int param_set_charp(const char *val, const struct kernel_param *kp)
265{ 258{