mirror of
https://github.com/adulau/aha.git
synced 2024-12-27 11:16:11 +00:00
vsprintf: give it some care to please checkpatch.pl
Most relevant complaints were addressed. Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
6c35663411
commit
7b9186f5eb
1 changed files with 98 additions and 86 deletions
|
@ -71,9 +71,9 @@ unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base)
|
|||
result = result * base + value;
|
||||
cp++;
|
||||
}
|
||||
|
||||
if (endp)
|
||||
*endp = (char *)cp;
|
||||
|
||||
return result;
|
||||
}
|
||||
EXPORT_SYMBOL(simple_strtoul);
|
||||
|
@ -88,6 +88,7 @@ long simple_strtol(const char *cp, char **endp, unsigned int base)
|
|||
{
|
||||
if (*cp == '-')
|
||||
return -simple_strtoul(cp + 1, endp, base);
|
||||
|
||||
return simple_strtoul(cp, endp, base);
|
||||
}
|
||||
EXPORT_SYMBOL(simple_strtol);
|
||||
|
@ -117,9 +118,9 @@ unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int bas
|
|||
result = result * base + value;
|
||||
cp++;
|
||||
}
|
||||
|
||||
if (endp)
|
||||
*endp = (char *)cp;
|
||||
|
||||
return result;
|
||||
}
|
||||
EXPORT_SYMBOL(simple_strtoull);
|
||||
|
@ -134,6 +135,7 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base)
|
|||
{
|
||||
if (*cp == '-')
|
||||
return -simple_strtoull(cp + 1, endp, base);
|
||||
|
||||
return simple_strtoull(cp, endp, base);
|
||||
}
|
||||
|
||||
|
@ -173,6 +175,7 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
|
|||
val = simple_strtoul(cp, &tail, base);
|
||||
if (tail == cp)
|
||||
return -EINVAL;
|
||||
|
||||
if ((*tail == '\0') ||
|
||||
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
|
||||
*res = val;
|
||||
|
@ -289,6 +292,7 @@ static int skip_atoi(const char **s)
|
|||
|
||||
while (isdigit(**s))
|
||||
i = i*10 + *((*s)++) - '0';
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -335,6 +339,7 @@ static char* put_dec_trunc(char *buf, unsigned q)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
/* Same with if's removed. Always emits five digits */
|
||||
|
@ -347,14 +352,15 @@ static char* put_dec_full(char *buf, unsigned q)
|
|||
d2 = (q>>8) & 0xf;
|
||||
d3 = (q>>12);
|
||||
|
||||
/* Possible ways to approx. divide by 10 */
|
||||
/* gcc -O2 replaces multiply with shifts and adds */
|
||||
// (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386)
|
||||
// (x * 0x67) >> 10: 1100111
|
||||
// (x * 0x34) >> 9: 110100 - same
|
||||
// (x * 0x1a) >> 8: 11010 - same
|
||||
// (x * 0x0d) >> 7: 1101 - same, shortest code (on i386)
|
||||
|
||||
/*
|
||||
* Possible ways to approx. divide by 10
|
||||
* gcc -O2 replaces multiply with shifts and adds
|
||||
* (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386)
|
||||
* (x * 0x67) >> 10: 1100111
|
||||
* (x * 0x34) >> 9: 110100 - same
|
||||
* (x * 0x1a) >> 8: 11010 - same
|
||||
* (x * 0x0d) >> 7: 1101 - same, shortest code (on i386)
|
||||
*/
|
||||
d0 = 6*(d3 + d2 + d1) + (q & 0xf);
|
||||
q = (d0 * 0xcd) >> 11;
|
||||
d0 = d0 - 10*q;
|
||||
|
@ -375,6 +381,7 @@ static char* put_dec_full(char *buf, unsigned q)
|
|||
d3 = d3 - 10*q;
|
||||
*buf++ = d3 + '0';
|
||||
*buf++ = q + '0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
/* No inlining helps gcc to use registers better */
|
||||
|
@ -478,7 +485,9 @@ static char *number(char *buf, char *end, unsigned long long num,
|
|||
else if (spec.base != 10) { /* 8 or 16 */
|
||||
int mask = spec.base - 1;
|
||||
int shift = 3;
|
||||
if (spec.base == 16) shift = 4;
|
||||
|
||||
if (spec.base == 16)
|
||||
shift = 4;
|
||||
do {
|
||||
tmp[i++] = (digits[((unsigned char)num) & mask] | locase);
|
||||
num >>= shift;
|
||||
|
@ -543,6 +552,7 @@ static char *number(char *buf, char *end, unsigned long long num,
|
|||
*buf = ' ';
|
||||
++buf;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -572,6 +582,7 @@ static char *string(char *buf, char *end, const char *s, struct printf_spec spec
|
|||
*buf = ' ';
|
||||
++buf;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -585,11 +596,13 @@ static char *symbol_string(char *buf, char *end, void *ptr,
|
|||
sprint_symbol(sym, value);
|
||||
else
|
||||
kallsyms_lookup(value, NULL, NULL, NULL, sym);
|
||||
|
||||
return string(buf, end, sym, spec);
|
||||
#else
|
||||
spec.field_width = 2 * sizeof(void *);
|
||||
spec.flags |= SPECIAL | SMALL | ZEROPAD;
|
||||
spec.base = 16;
|
||||
|
||||
return number(buf, end, value, spec);
|
||||
#endif
|
||||
}
|
||||
|
@ -718,22 +731,19 @@ static char *ip4_string(char *p, const u8 *addr, bool leading_zeros)
|
|||
if (i < 3)
|
||||
*p++ = '.';
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static char *ip6_compressed_string(char *p, const char *addr)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int range;
|
||||
int i, j, range;
|
||||
unsigned char zerolength[8];
|
||||
int longest = 1;
|
||||
int colonpos = -1;
|
||||
u16 word;
|
||||
u8 hi;
|
||||
u8 lo;
|
||||
u8 hi, lo;
|
||||
bool needcolon = false;
|
||||
bool useIPv4;
|
||||
struct in6_addr in6;
|
||||
|
@ -800,22 +810,23 @@ static char *ip6_compressed_string(char *p, const char *addr)
|
|||
*p++ = ':';
|
||||
p = ip4_string(p, &in6.s6_addr[12], false);
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static char *ip6_string(char *p, const char *addr, const char *fmt)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
p = pack_hex_byte(p, *addr++);
|
||||
p = pack_hex_byte(p, *addr++);
|
||||
if (fmt[0] == 'I' && i != 7)
|
||||
*p++ = ':';
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -1323,6 +1334,7 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
|
|||
int i;
|
||||
|
||||
i = vsnprintf(buf, size, fmt, args);
|
||||
|
||||
return (i >= size) ? (size - 1) : i;
|
||||
}
|
||||
EXPORT_SYMBOL(vscnprintf);
|
||||
|
@ -1349,6 +1361,7 @@ int snprintf(char * buf, size_t size, const char *fmt, ...)
|
|||
va_start(args, fmt);
|
||||
i = vsnprintf(buf, size, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return i;
|
||||
}
|
||||
EXPORT_SYMBOL(snprintf);
|
||||
|
@ -1372,6 +1385,7 @@ int scnprintf(char * buf, size_t size, const char *fmt, ...)
|
|||
va_start(args, fmt);
|
||||
i = vsnprintf(buf, size, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return (i >= size) ? (size - 1) : i;
|
||||
}
|
||||
EXPORT_SYMBOL(scnprintf);
|
||||
|
@ -1417,6 +1431,7 @@ int sprintf(char * buf, const char *fmt, ...)
|
|||
va_start(args, fmt);
|
||||
i = vsnprintf(buf, INT_MAX, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return i;
|
||||
}
|
||||
EXPORT_SYMBOL(sprintf);
|
||||
|
@ -1474,7 +1489,6 @@ do { \
|
|||
str += sizeof(type); \
|
||||
} while (0)
|
||||
|
||||
|
||||
while (*fmt) {
|
||||
read = format_decode(fmt, &spec);
|
||||
|
||||
|
@ -1562,8 +1576,8 @@ do { \
|
|||
}
|
||||
}
|
||||
}
|
||||
return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf;
|
||||
|
||||
return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf;
|
||||
#undef save_arg
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(vbin_printf);
|
||||
|
@ -1595,7 +1609,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
|
|||
unsigned long long num;
|
||||
char *str, *end, c;
|
||||
const char *args = (const char *)bin_buf;
|
||||
|
||||
struct printf_spec spec = {0};
|
||||
|
||||
if (WARN_ON_ONCE((int) size < 0))
|
||||
|
@ -1775,6 +1788,7 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...)
|
|||
va_start(args, fmt);
|
||||
ret = vbin_printf(bin_buf, size, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(bprintf);
|
||||
|
@ -1793,9 +1807,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
|
|||
char *next;
|
||||
char digit;
|
||||
int num = 0;
|
||||
int qualifier;
|
||||
int base;
|
||||
int field_width;
|
||||
int qualifier, base, field_width;
|
||||
int is_sign = 0;
|
||||
|
||||
while (*fmt && *str) {
|
||||
|
@ -1880,9 +1892,8 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
|
|||
str++;
|
||||
|
||||
/* now copy until next white space */
|
||||
while (*str && !isspace(*str) && field_width--) {
|
||||
while (*str && !isspace(*str) && field_width--)
|
||||
*s++ = *str++;
|
||||
}
|
||||
*s = '\0';
|
||||
num++;
|
||||
}
|
||||
|
@ -2023,6 +2034,7 @@ int sscanf(const char * buf, const char * fmt, ...)
|
|||
va_start(args, fmt);
|
||||
i = vsscanf(buf, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return i;
|
||||
}
|
||||
EXPORT_SYMBOL(sscanf);
|
||||
|
|
Loading…
Reference in a new issue