Skip to content

Commit 88a88b3

Browse files
felipecrustyrussell
authored andcommitted
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>
1 parent 160e01a commit 88a88b3

1 file changed

Lines changed: 9 additions & 16 deletions

File tree

‎kernel/params.c‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,10 @@ int parse_args(const char *doing,
227227
}
228228

229229
/* Lazy bastard, eh? */
230-
#define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn) \
230+
#define STANDARD_PARAM_DEF(name, type, format, strtolfn) \
231231
int param_set_##name(const char *val, const struct kernel_param *kp) \
232232
{ \
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); \
241234
} \
242235
int param_get_##name(char *buffer, const struct kernel_param *kp) \
243236
{ \
@@ -253,13 +246,13 @@ int parse_args(const char *doing,
253246
EXPORT_SYMBOL(param_ops_##name)
254247

255248

256-
STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", unsigned long, kstrtoul);
257-
STANDARD_PARAM_DEF(short, short, "%hi", long, kstrtol);
258-
STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, kstrtoul);
259-
STANDARD_PARAM_DEF(int, int, "%i", long, kstrtol);
260-
STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, kstrtoul);
261-
STANDARD_PARAM_DEF(long, long, "%li", long, kstrtol);
262-
STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, kstrtoul);
249+
STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", kstrtou8);
250+
STANDARD_PARAM_DEF(short, short, "%hi", kstrtos16);
251+
STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", kstrtou16);
252+
STANDARD_PARAM_DEF(int, int, "%i", kstrtoint);
253+
STANDARD_PARAM_DEF(uint, unsigned int, "%u", kstrtouint);
254+
STANDARD_PARAM_DEF(long, long, "%li", kstrtol);
255+
STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", kstrtoul);
263256

264257
int param_set_charp(const char *val, const struct kernel_param *kp)
265258
{

0 commit comments

Comments
 (0)