Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Felipe Contreras and committed by
Rusty Russell
88a88b32 160e01ac

+9 -16
+9 -16
kernel/params.c
··· 227 227 } 228 228 229 229 /* Lazy bastard, eh? */ 230 - #define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn) \ 230 + #define STANDARD_PARAM_DEF(name, type, format, strtolfn) \ 231 231 int param_set_##name(const char *val, const struct kernel_param *kp) \ 232 232 { \ 233 - tmptype l; \ 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; \ 233 + return strtolfn(val, 0, (type *)kp->arg); \ 241 234 } \ 242 235 int param_get_##name(char *buffer, const struct kernel_param *kp) \ 243 236 { \ ··· 246 253 EXPORT_SYMBOL(param_ops_##name) 247 254 248 255 249 - STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", unsigned long, kstrtoul); 250 - STANDARD_PARAM_DEF(short, short, "%hi", long, kstrtol); 251 - STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, kstrtoul); 252 - STANDARD_PARAM_DEF(int, int, "%i", long, kstrtol); 253 - STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, kstrtoul); 254 - STANDARD_PARAM_DEF(long, long, "%li", long, kstrtol); 255 - STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, kstrtoul); 256 + STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", kstrtou8); 257 + STANDARD_PARAM_DEF(short, short, "%hi", kstrtos16); 258 + STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", kstrtou16); 259 + STANDARD_PARAM_DEF(int, int, "%i", kstrtoint); 260 + STANDARD_PARAM_DEF(uint, unsigned int, "%u", kstrtouint); 261 + STANDARD_PARAM_DEF(long, long, "%li", kstrtol); 262 + STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", kstrtoul); 256 263 257 264 int param_set_charp(const char *val, const struct kernel_param *kp) 258 265 {