lib: remove defining macros for strict_strto??
Open-code them rather than using defining macros. The function bodies are now next to their kerneldoc comments as a bonus. Add casts to the signed cases as they call into the unsigned versions. Avoids the sparse warnings: lib/vsprintf.c:249:1: warning: incorrect type in argument 3 (different signedness) lib/vsprintf.c:249:1: expected unsigned long *res lib/vsprintf.c:249:1: got long *res lib/vsprintf.c:249:1: warning: incorrect type in argument 3 (different signedness) lib/vsprintf.c:249:1: expected unsigned long *res lib/vsprintf.c:249:1: got long *res lib/vsprintf.c:251:1: warning: incorrect type in argument 3 (different signedness) lib/vsprintf.c:251:1: expected unsigned long long *res lib/vsprintf.c:251:1: got long long *res lib/vsprintf.c:251:1: warning: incorrect type in argument 3 (different signedness) lib/vsprintf.c:251:1: expected unsigned long long *res lib/vsprintf.c:251:1: got long long *res Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
22d27051b4
commit
9d85db2244
117
lib/vsprintf.c
117
lib/vsprintf.c
|
@ -135,7 +135,6 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base)
|
||||||
return simple_strtoull(cp, endp, base);
|
return simple_strtoull(cp, endp, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* strict_strtoul - convert a string to an unsigned long strictly
|
* strict_strtoul - convert a string to an unsigned long strictly
|
||||||
* @cp: The string to be converted
|
* @cp: The string to be converted
|
||||||
|
@ -158,7 +157,27 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base)
|
||||||
* simple_strtoul just ignores the successive invalid characters and
|
* simple_strtoul just ignores the successive invalid characters and
|
||||||
* return the converted value of prefix part of the string.
|
* return the converted value of prefix part of the string.
|
||||||
*/
|
*/
|
||||||
int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
|
int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
|
||||||
|
{
|
||||||
|
char *tail;
|
||||||
|
unsigned long val;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
*res = 0;
|
||||||
|
len = strlen(cp);
|
||||||
|
if (len == 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
val = simple_strtoul(cp, &tail, base);
|
||||||
|
if ((*tail == '\0') ||
|
||||||
|
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
|
||||||
|
*res = val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(strict_strtoul);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* strict_strtol - convert a string to a long strictly
|
* strict_strtol - convert a string to a long strictly
|
||||||
|
@ -172,7 +191,20 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
|
||||||
* It returns 0 if conversion is successful and *res is set to the converted
|
* It returns 0 if conversion is successful and *res is set to the converted
|
||||||
* value, otherwise it returns -EINVAL and *res is set to 0.
|
* value, otherwise it returns -EINVAL and *res is set to 0.
|
||||||
*/
|
*/
|
||||||
int strict_strtol(const char *cp, unsigned int base, long *res);
|
int strict_strtol(const char *cp, unsigned int base, long *res)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
if (*cp == '-') {
|
||||||
|
ret = strict_strtoul(cp + 1, base, (unsigned long *)res);
|
||||||
|
if (!ret)
|
||||||
|
*res = -(*res);
|
||||||
|
} else {
|
||||||
|
ret = strict_strtoul(cp, base, (unsigned long *)res);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(strict_strtol);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* strict_strtoull - convert a string to an unsigned long long strictly
|
* strict_strtoull - convert a string to an unsigned long long strictly
|
||||||
|
@ -196,7 +228,27 @@ int strict_strtol(const char *cp, unsigned int base, long *res);
|
||||||
* simple_strtoull just ignores the successive invalid characters and
|
* simple_strtoull just ignores the successive invalid characters and
|
||||||
* return the converted value of prefix part of the string.
|
* return the converted value of prefix part of the string.
|
||||||
*/
|
*/
|
||||||
int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res);
|
int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res)
|
||||||
|
{
|
||||||
|
char *tail;
|
||||||
|
unsigned long long val;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
*res = 0;
|
||||||
|
len = strlen(cp);
|
||||||
|
if (len == 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
val = simple_strtoull(cp, &tail, base);
|
||||||
|
if ((*tail == '\0') ||
|
||||||
|
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
|
||||||
|
*res = val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(strict_strtoull);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* strict_strtoll - convert a string to a long long strictly
|
* strict_strtoll - convert a string to a long long strictly
|
||||||
|
@ -210,53 +262,20 @@ int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res);
|
||||||
* It returns 0 if conversion is successful and *res is set to the converted
|
* It returns 0 if conversion is successful and *res is set to the converted
|
||||||
* value, otherwise it returns -EINVAL and *res is set to 0.
|
* value, otherwise it returns -EINVAL and *res is set to 0.
|
||||||
*/
|
*/
|
||||||
int strict_strtoll(const char *cp, unsigned int base, long long *res);
|
int strict_strtoll(const char *cp, unsigned int base, long long *res)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
if (*cp == '-') {
|
||||||
|
ret = strict_strtoull(cp + 1, base, (unsigned long long *)res);
|
||||||
|
if (!ret)
|
||||||
|
*res = -(*res);
|
||||||
|
} else {
|
||||||
|
ret = strict_strtoull(cp, base, (unsigned long long *)res);
|
||||||
|
}
|
||||||
|
|
||||||
#define define_strict_strtoux(type, valtype) \
|
return ret;
|
||||||
int strict_strtou##type(const char *cp, unsigned int base, valtype *res)\
|
}
|
||||||
{ \
|
|
||||||
char *tail; \
|
|
||||||
valtype val; \
|
|
||||||
size_t len; \
|
|
||||||
\
|
|
||||||
*res = 0; \
|
|
||||||
len = strlen(cp); \
|
|
||||||
if (len == 0) \
|
|
||||||
return -EINVAL; \
|
|
||||||
\
|
|
||||||
val = simple_strtou##type(cp, &tail, base); \
|
|
||||||
if ((*tail == '\0') || \
|
|
||||||
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {\
|
|
||||||
*res = val; \
|
|
||||||
return 0; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
return -EINVAL; \
|
|
||||||
} \
|
|
||||||
|
|
||||||
#define define_strict_strtox(type, valtype) \
|
|
||||||
int strict_strto##type(const char *cp, unsigned int base, valtype *res) \
|
|
||||||
{ \
|
|
||||||
int ret; \
|
|
||||||
if (*cp == '-') { \
|
|
||||||
ret = strict_strtou##type(cp+1, base, res); \
|
|
||||||
if (!ret) \
|
|
||||||
*res = -(*res); \
|
|
||||||
} else \
|
|
||||||
ret = strict_strtou##type(cp, base, res); \
|
|
||||||
\
|
|
||||||
return ret; \
|
|
||||||
} \
|
|
||||||
|
|
||||||
define_strict_strtoux(l, unsigned long)
|
|
||||||
define_strict_strtox(l, long)
|
|
||||||
define_strict_strtoux(ll, unsigned long long)
|
|
||||||
define_strict_strtox(ll, long long)
|
|
||||||
|
|
||||||
EXPORT_SYMBOL(strict_strtoul);
|
|
||||||
EXPORT_SYMBOL(strict_strtol);
|
|
||||||
EXPORT_SYMBOL(strict_strtoll);
|
EXPORT_SYMBOL(strict_strtoll);
|
||||||
EXPORT_SYMBOL(strict_strtoull);
|
|
||||||
|
|
||||||
static int skip_atoi(const char **s)
|
static int skip_atoi(const char **s)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue