2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* linux/lib/vsprintf.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
|
|
|
|
/*
|
|
|
|
* Wirzenius wrote this portably, Torvalds fucked it up :-)
|
|
|
|
*/
|
|
|
|
|
2009-12-15 03:00:57 +01:00
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Fri Jul 13 2001 Crutcher Dunnavant <crutcher+kernel@datastacks.com>
|
|
|
|
* - changed to provide snprintf and vsnprintf functions
|
|
|
|
* So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de>
|
|
|
|
* - scnprintf and vscnprintf
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/kernel.h>
|
2008-07-07 01:43:12 +02:00
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
#include <linux/uaccess.h>
|
2008-10-20 06:07:34 +02:00
|
|
|
#include <linux/ioport.h>
|
2009-08-17 14:29:44 +02:00
|
|
|
#include <net/addrconf.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-10-31 00:03:48 +01:00
|
|
|
#include <asm/page.h> /* for PAGE_SIZE */
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <asm/div64.h>
|
2008-09-04 03:43:36 +02:00
|
|
|
#include <asm/sections.h> /* for dereference_function_descriptor() */
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-02-09 23:24:09 +01:00
|
|
|
/* Works only for digits and letters, but small and fast */
|
|
|
|
#define TOLOWER(x) ((x) | 0x20)
|
|
|
|
|
2008-10-16 22:40:34 +02:00
|
|
|
static unsigned int simple_guess_base(const char *cp)
|
|
|
|
{
|
|
|
|
if (cp[0] == '0') {
|
|
|
|
if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2]))
|
|
|
|
return 16;
|
|
|
|
else
|
|
|
|
return 8;
|
|
|
|
} else {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/**
|
2009-12-15 03:01:01 +01:00
|
|
|
* simple_strtoull - convert a string to an unsigned long long
|
2005-04-17 00:20:36 +02:00
|
|
|
* @cp: The start of the string
|
|
|
|
* @endp: A pointer to the end of the parsed string will be placed here
|
|
|
|
* @base: The number base to use
|
|
|
|
*/
|
2009-12-15 03:01:01 +01:00
|
|
|
unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2009-12-15 03:01:01 +01:00
|
|
|
unsigned long long result = 0;
|
2008-10-16 22:40:34 +02:00
|
|
|
|
|
|
|
if (!base)
|
|
|
|
base = simple_guess_base(cp);
|
|
|
|
|
|
|
|
if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x')
|
|
|
|
cp += 2;
|
|
|
|
|
|
|
|
while (isxdigit(*cp)) {
|
|
|
|
unsigned int value;
|
|
|
|
|
|
|
|
value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10;
|
|
|
|
if (value >= base)
|
|
|
|
break;
|
|
|
|
result = result * base + value;
|
2005-04-17 00:20:36 +02:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
if (endp)
|
|
|
|
*endp = (char *)cp;
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return result;
|
|
|
|
}
|
2009-12-15 03:01:01 +01:00
|
|
|
EXPORT_SYMBOL(simple_strtoull);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/**
|
2009-12-15 03:01:01 +01:00
|
|
|
* simple_strtoul - convert a string to an unsigned long
|
2005-04-17 00:20:36 +02:00
|
|
|
* @cp: The start of the string
|
|
|
|
* @endp: A pointer to the end of the parsed string will be placed here
|
|
|
|
* @base: The number base to use
|
|
|
|
*/
|
2009-12-15 03:01:01 +01:00
|
|
|
unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2009-12-15 03:01:01 +01:00
|
|
|
return simple_strtoull(cp, endp, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2009-12-15 03:01:01 +01:00
|
|
|
EXPORT_SYMBOL(simple_strtoul);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/**
|
2009-12-15 03:01:01 +01:00
|
|
|
* simple_strtol - convert a string to a signed long
|
2005-04-17 00:20:36 +02:00
|
|
|
* @cp: The start of the string
|
|
|
|
* @endp: A pointer to the end of the parsed string will be placed here
|
|
|
|
* @base: The number base to use
|
|
|
|
*/
|
2009-12-15 03:01:01 +01:00
|
|
|
long simple_strtol(const char *cp, char **endp, unsigned int base)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2009-12-15 03:01:01 +01:00
|
|
|
if (*cp == '-')
|
|
|
|
return -simple_strtoul(cp + 1, endp, base);
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2009-12-15 03:01:01 +01:00
|
|
|
return simple_strtoul(cp, endp, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2009-12-15 03:01:01 +01:00
|
|
|
EXPORT_SYMBOL(simple_strtol);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* simple_strtoll - convert a string to a signed long long
|
|
|
|
* @cp: The start of the string
|
|
|
|
* @endp: A pointer to the end of the parsed string will be placed here
|
|
|
|
* @base: The number base to use
|
|
|
|
*/
|
2008-10-16 22:40:35 +02:00
|
|
|
long long simple_strtoll(const char *cp, char **endp, unsigned int base)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2009-12-15 03:00:57 +01:00
|
|
|
if (*cp == '-')
|
2008-10-16 22:40:35 +02:00
|
|
|
return -simple_strtoull(cp + 1, endp, base);
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2008-10-16 22:40:35 +02:00
|
|
|
return simple_strtoull(cp, endp, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2010-04-23 19:18:04 +02:00
|
|
|
EXPORT_SYMBOL(simple_strtoll);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
Add new string functions strict_strto* and convert kernel params to use them
Currently, for every sysfs node, the callers will be responsible for
implementing store operation, so many many callers are doing duplicate
things to validate input, they have the same mistakes because they are
calling simple_strtol/ul/ll/uul, especially for module params, they are
just numeric, but you can echo such values as 0x1234xxx, 07777888 and
1234aaa, for these cases, module params store operation just ignores
succesive invalid char and converts prefix part to a numeric although input
is acctually invalid.
This patch tries to fix the aforementioned issues and implements
strict_strtox serial functions, kernel/params.c uses them to strictly
validate input, so module params will reject such values as 0x1234xxxx and
returns an error:
write error: Invalid argument
Any modules which export numeric sysfs node can use strict_strtox instead of
simple_strtox to reject any invalid input.
Here are some test results:
Before applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
After applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo -n 4096 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
[akpm@linux-foundation.org: fix compiler warnings]
[akpm@linux-foundation.org: fix off-by-one found by tiwai@suse.de]
Signed-off-by: Yi Yang <yi.y.yang@intel.com>
Cc: Greg KH <greg@kroah.com>
Cc: "Randy.Dunlap" <rdunlap@xenotime.net>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-02-08 13:21:57 +01:00
|
|
|
/**
|
|
|
|
* strict_strtoul - convert a string to an unsigned long strictly
|
|
|
|
* @cp: The string to be converted
|
|
|
|
* @base: The number base to use
|
|
|
|
* @res: The converted result value
|
|
|
|
*
|
|
|
|
* strict_strtoul converts a string to an unsigned long only if the
|
|
|
|
* string is really an unsigned long string, any string containing
|
|
|
|
* any invalid char at the tail will be rejected and -EINVAL is returned,
|
|
|
|
* only a newline char at the tail is acceptible because people generally
|
|
|
|
* change a module parameter in the following way:
|
|
|
|
*
|
|
|
|
* echo 1024 > /sys/module/e1000/parameters/copybreak
|
|
|
|
*
|
|
|
|
* echo will append a newline to the tail.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* simple_strtoul just ignores the successive invalid characters and
|
|
|
|
* return the converted value of prefix part of the string.
|
|
|
|
*/
|
2008-10-16 22:40:35 +02:00
|
|
|
int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
|
|
|
|
{
|
|
|
|
char *tail;
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
*res = 0;
|
2010-08-10 02:20:54 +02:00
|
|
|
if (!*cp)
|
2008-10-16 22:40:35 +02:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
val = simple_strtoul(cp, &tail, base);
|
2009-01-06 23:40:53 +01:00
|
|
|
if (tail == cp)
|
|
|
|
return -EINVAL;
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2010-08-10 02:20:54 +02:00
|
|
|
if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) {
|
2008-10-16 22:40:35 +02:00
|
|
|
*res = val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(strict_strtoul);
|
Add new string functions strict_strto* and convert kernel params to use them
Currently, for every sysfs node, the callers will be responsible for
implementing store operation, so many many callers are doing duplicate
things to validate input, they have the same mistakes because they are
calling simple_strtol/ul/ll/uul, especially for module params, they are
just numeric, but you can echo such values as 0x1234xxx, 07777888 and
1234aaa, for these cases, module params store operation just ignores
succesive invalid char and converts prefix part to a numeric although input
is acctually invalid.
This patch tries to fix the aforementioned issues and implements
strict_strtox serial functions, kernel/params.c uses them to strictly
validate input, so module params will reject such values as 0x1234xxxx and
returns an error:
write error: Invalid argument
Any modules which export numeric sysfs node can use strict_strtox instead of
simple_strtox to reject any invalid input.
Here are some test results:
Before applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
After applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo -n 4096 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
[akpm@linux-foundation.org: fix compiler warnings]
[akpm@linux-foundation.org: fix off-by-one found by tiwai@suse.de]
Signed-off-by: Yi Yang <yi.y.yang@intel.com>
Cc: Greg KH <greg@kroah.com>
Cc: "Randy.Dunlap" <rdunlap@xenotime.net>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-02-08 13:21:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* strict_strtol - convert a string to a long strictly
|
|
|
|
* @cp: The string to be converted
|
|
|
|
* @base: The number base to use
|
|
|
|
* @res: The converted result value
|
|
|
|
*
|
|
|
|
* strict_strtol is similiar to strict_strtoul, but it allows the first
|
|
|
|
* character of a string is '-'.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-10-16 22:40:35 +02:00
|
|
|
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);
|
Add new string functions strict_strto* and convert kernel params to use them
Currently, for every sysfs node, the callers will be responsible for
implementing store operation, so many many callers are doing duplicate
things to validate input, they have the same mistakes because they are
calling simple_strtol/ul/ll/uul, especially for module params, they are
just numeric, but you can echo such values as 0x1234xxx, 07777888 and
1234aaa, for these cases, module params store operation just ignores
succesive invalid char and converts prefix part to a numeric although input
is acctually invalid.
This patch tries to fix the aforementioned issues and implements
strict_strtox serial functions, kernel/params.c uses them to strictly
validate input, so module params will reject such values as 0x1234xxxx and
returns an error:
write error: Invalid argument
Any modules which export numeric sysfs node can use strict_strtox instead of
simple_strtox to reject any invalid input.
Here are some test results:
Before applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
After applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo -n 4096 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
[akpm@linux-foundation.org: fix compiler warnings]
[akpm@linux-foundation.org: fix off-by-one found by tiwai@suse.de]
Signed-off-by: Yi Yang <yi.y.yang@intel.com>
Cc: Greg KH <greg@kroah.com>
Cc: "Randy.Dunlap" <rdunlap@xenotime.net>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-02-08 13:21:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* strict_strtoull - convert a string to an unsigned long long strictly
|
|
|
|
* @cp: The string to be converted
|
|
|
|
* @base: The number base to use
|
|
|
|
* @res: The converted result value
|
|
|
|
*
|
|
|
|
* strict_strtoull converts a string to an unsigned long long only if the
|
|
|
|
* string is really an unsigned long long string, any string containing
|
|
|
|
* any invalid char at the tail will be rejected and -EINVAL is returned,
|
|
|
|
* only a newline char at the tail is acceptible because people generally
|
|
|
|
* change a module parameter in the following way:
|
|
|
|
*
|
|
|
|
* echo 1024 > /sys/module/e1000/parameters/copybreak
|
|
|
|
*
|
|
|
|
* echo will append a newline to the tail of the string.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* simple_strtoull just ignores the successive invalid characters and
|
|
|
|
* return the converted value of prefix part of the string.
|
|
|
|
*/
|
2008-10-16 22:40:35 +02:00
|
|
|
int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res)
|
|
|
|
{
|
|
|
|
char *tail;
|
|
|
|
unsigned long long val;
|
|
|
|
|
|
|
|
*res = 0;
|
2010-08-10 02:20:54 +02:00
|
|
|
if (!*cp)
|
2008-10-16 22:40:35 +02:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
val = simple_strtoull(cp, &tail, base);
|
2009-01-06 23:40:53 +01:00
|
|
|
if (tail == cp)
|
|
|
|
return -EINVAL;
|
2010-08-10 02:20:54 +02:00
|
|
|
if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) {
|
2008-10-16 22:40:35 +02:00
|
|
|
*res = val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(strict_strtoull);
|
Add new string functions strict_strto* and convert kernel params to use them
Currently, for every sysfs node, the callers will be responsible for
implementing store operation, so many many callers are doing duplicate
things to validate input, they have the same mistakes because they are
calling simple_strtol/ul/ll/uul, especially for module params, they are
just numeric, but you can echo such values as 0x1234xxx, 07777888 and
1234aaa, for these cases, module params store operation just ignores
succesive invalid char and converts prefix part to a numeric although input
is acctually invalid.
This patch tries to fix the aforementioned issues and implements
strict_strtox serial functions, kernel/params.c uses them to strictly
validate input, so module params will reject such values as 0x1234xxxx and
returns an error:
write error: Invalid argument
Any modules which export numeric sysfs node can use strict_strtox instead of
simple_strtox to reject any invalid input.
Here are some test results:
Before applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
After applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo -n 4096 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
[akpm@linux-foundation.org: fix compiler warnings]
[akpm@linux-foundation.org: fix off-by-one found by tiwai@suse.de]
Signed-off-by: Yi Yang <yi.y.yang@intel.com>
Cc: Greg KH <greg@kroah.com>
Cc: "Randy.Dunlap" <rdunlap@xenotime.net>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-02-08 13:21:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* strict_strtoll - convert a string to a long long strictly
|
|
|
|
* @cp: The string to be converted
|
|
|
|
* @base: The number base to use
|
|
|
|
* @res: The converted result value
|
|
|
|
*
|
|
|
|
* strict_strtoll is similiar to strict_strtoull, but it allows the first
|
|
|
|
* character of a string is '-'.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-10-16 22:40:35 +02:00
|
|
|
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);
|
|
|
|
}
|
Add new string functions strict_strto* and convert kernel params to use them
Currently, for every sysfs node, the callers will be responsible for
implementing store operation, so many many callers are doing duplicate
things to validate input, they have the same mistakes because they are
calling simple_strtol/ul/ll/uul, especially for module params, they are
just numeric, but you can echo such values as 0x1234xxx, 07777888 and
1234aaa, for these cases, module params store operation just ignores
succesive invalid char and converts prefix part to a numeric although input
is acctually invalid.
This patch tries to fix the aforementioned issues and implements
strict_strtox serial functions, kernel/params.c uses them to strictly
validate input, so module params will reject such values as 0x1234xxxx and
returns an error:
write error: Invalid argument
Any modules which export numeric sysfs node can use strict_strtox instead of
simple_strtox to reject any invalid input.
Here are some test results:
Before applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
After applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo -n 4096 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
[akpm@linux-foundation.org: fix compiler warnings]
[akpm@linux-foundation.org: fix off-by-one found by tiwai@suse.de]
Signed-off-by: Yi Yang <yi.y.yang@intel.com>
Cc: Greg KH <greg@kroah.com>
Cc: "Randy.Dunlap" <rdunlap@xenotime.net>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-02-08 13:21:57 +01:00
|
|
|
|
2008-10-16 22:40:35 +02:00
|
|
|
return ret;
|
|
|
|
}
|
Add new string functions strict_strto* and convert kernel params to use them
Currently, for every sysfs node, the callers will be responsible for
implementing store operation, so many many callers are doing duplicate
things to validate input, they have the same mistakes because they are
calling simple_strtol/ul/ll/uul, especially for module params, they are
just numeric, but you can echo such values as 0x1234xxx, 07777888 and
1234aaa, for these cases, module params store operation just ignores
succesive invalid char and converts prefix part to a numeric although input
is acctually invalid.
This patch tries to fix the aforementioned issues and implements
strict_strtox serial functions, kernel/params.c uses them to strictly
validate input, so module params will reject such values as 0x1234xxxx and
returns an error:
write error: Invalid argument
Any modules which export numeric sysfs node can use strict_strtox instead of
simple_strtox to reject any invalid input.
Here are some test results:
Before applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
After applying this patch:
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
-bash: echo: write error: Invalid argument
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]# echo -n 4096 > /sys/module/e1000/parameters/copybreak
[root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
4096
[root@yangyi-dev /]#
[akpm@linux-foundation.org: fix compiler warnings]
[akpm@linux-foundation.org: fix off-by-one found by tiwai@suse.de]
Signed-off-by: Yi Yang <yi.y.yang@intel.com>
Cc: Greg KH <greg@kroah.com>
Cc: "Randy.Dunlap" <rdunlap@xenotime.net>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-02-08 13:21:57 +01:00
|
|
|
EXPORT_SYMBOL(strict_strtoll);
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
int skip_atoi(const char **s)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2009-12-15 03:00:57 +01:00
|
|
|
int i = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
while (isdigit(**s))
|
|
|
|
i = i*10 + *((*s)++) - '0';
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2007-07-16 08:41:56 +02:00
|
|
|
/* Decimal conversion is by far the most typical, and is used
|
|
|
|
* for /proc and /sys data. This directly impacts e.g. top performance
|
|
|
|
* with many processes running. We optimize it for speed
|
|
|
|
* using code from
|
|
|
|
* http://www.cs.uiowa.edu/~jones/bcd/decimal.html
|
|
|
|
* (with permission from the author, Douglas W. Jones). */
|
|
|
|
|
|
|
|
/* Formats correctly any integer in [0,99999].
|
|
|
|
* Outputs from one to five digits depending on input.
|
|
|
|
* On i386 gcc 4.1.2 -O2: ~250 bytes of code. */
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *put_dec_trunc(char *buf, unsigned q)
|
2007-07-16 08:41:56 +02:00
|
|
|
{
|
|
|
|
unsigned d3, d2, d1, d0;
|
|
|
|
d1 = (q>>4) & 0xf;
|
|
|
|
d2 = (q>>8) & 0xf;
|
|
|
|
d3 = (q>>12);
|
|
|
|
|
|
|
|
d0 = 6*(d3 + d2 + d1) + (q & 0xf);
|
|
|
|
q = (d0 * 0xcd) >> 11;
|
|
|
|
d0 = d0 - 10*q;
|
|
|
|
*buf++ = d0 + '0'; /* least significant digit */
|
|
|
|
d1 = q + 9*d3 + 5*d2 + d1;
|
|
|
|
if (d1 != 0) {
|
|
|
|
q = (d1 * 0xcd) >> 11;
|
|
|
|
d1 = d1 - 10*q;
|
|
|
|
*buf++ = d1 + '0'; /* next digit */
|
|
|
|
|
|
|
|
d2 = q + 2*d2;
|
|
|
|
if ((d2 != 0) || (d3 != 0)) {
|
|
|
|
q = (d2 * 0xd) >> 7;
|
|
|
|
d2 = d2 - 10*q;
|
|
|
|
*buf++ = d2 + '0'; /* next digit */
|
|
|
|
|
|
|
|
d3 = q + 4*d3;
|
|
|
|
if (d3 != 0) {
|
|
|
|
q = (d3 * 0xcd) >> 11;
|
|
|
|
d3 = d3 - 10*q;
|
|
|
|
*buf++ = d3 + '0'; /* next digit */
|
|
|
|
if (q != 0)
|
2009-12-15 03:00:57 +01:00
|
|
|
*buf++ = q + '0'; /* most sign. digit */
|
2007-07-16 08:41:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2007-07-16 08:41:56 +02:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
/* Same with if's removed. Always emits five digits */
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *put_dec_full(char *buf, unsigned q)
|
2007-07-16 08:41:56 +02:00
|
|
|
{
|
|
|
|
/* BTW, if q is in [0,9999], 8-bit ints will be enough, */
|
|
|
|
/* but anyway, gcc produces better code with full-sized ints */
|
|
|
|
unsigned d3, d2, d1, d0;
|
|
|
|
d1 = (q>>4) & 0xf;
|
|
|
|
d2 = (q>>8) & 0xf;
|
|
|
|
d3 = (q>>12);
|
|
|
|
|
2009-12-15 03:00:57 +01:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
*/
|
2007-07-16 08:41:56 +02:00
|
|
|
d0 = 6*(d3 + d2 + d1) + (q & 0xf);
|
|
|
|
q = (d0 * 0xcd) >> 11;
|
|
|
|
d0 = d0 - 10*q;
|
|
|
|
*buf++ = d0 + '0';
|
|
|
|
d1 = q + 9*d3 + 5*d2 + d1;
|
|
|
|
q = (d1 * 0xcd) >> 11;
|
|
|
|
d1 = d1 - 10*q;
|
|
|
|
*buf++ = d1 + '0';
|
|
|
|
|
|
|
|
d2 = q + 2*d2;
|
|
|
|
q = (d2 * 0xd) >> 7;
|
|
|
|
d2 = d2 - 10*q;
|
|
|
|
*buf++ = d2 + '0';
|
|
|
|
|
|
|
|
d3 = q + 4*d3;
|
|
|
|
q = (d3 * 0xcd) >> 11; /* - shorter code */
|
|
|
|
/* q = (d3 * 0x67) >> 10; - would also work */
|
|
|
|
d3 = d3 - 10*q;
|
|
|
|
*buf++ = d3 + '0';
|
|
|
|
*buf++ = q + '0';
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2007-07-16 08:41:56 +02:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
/* No inlining helps gcc to use registers better */
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *put_dec(char *buf, unsigned long long num)
|
2007-07-16 08:41:56 +02:00
|
|
|
{
|
|
|
|
while (1) {
|
|
|
|
unsigned rem;
|
|
|
|
if (num < 100000)
|
|
|
|
return put_dec_trunc(buf, num);
|
|
|
|
rem = do_div(num, 100000);
|
|
|
|
buf = put_dec_full(buf, rem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#define ZEROPAD 1 /* pad with zero */
|
|
|
|
#define SIGN 2 /* unsigned/signed long */
|
|
|
|
#define PLUS 4 /* show plus */
|
|
|
|
#define SPACE 8 /* space if plus */
|
|
|
|
#define LEFT 16 /* left justified */
|
2010-03-05 18:47:31 +01:00
|
|
|
#define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */
|
|
|
|
#define SPECIAL 64 /* prefix hex with "0x", octal with "0" */
|
2005-04-17 00:20:36 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
enum format_type {
|
|
|
|
FORMAT_TYPE_NONE, /* Just a string part */
|
2009-03-14 12:08:50 +01:00
|
|
|
FORMAT_TYPE_WIDTH,
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
FORMAT_TYPE_PRECISION,
|
|
|
|
FORMAT_TYPE_CHAR,
|
|
|
|
FORMAT_TYPE_STR,
|
|
|
|
FORMAT_TYPE_PTR,
|
|
|
|
FORMAT_TYPE_PERCENT_CHAR,
|
|
|
|
FORMAT_TYPE_INVALID,
|
|
|
|
FORMAT_TYPE_LONG_LONG,
|
|
|
|
FORMAT_TYPE_ULONG,
|
|
|
|
FORMAT_TYPE_LONG,
|
2009-03-27 10:07:05 +01:00
|
|
|
FORMAT_TYPE_UBYTE,
|
|
|
|
FORMAT_TYPE_BYTE,
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
FORMAT_TYPE_USHORT,
|
|
|
|
FORMAT_TYPE_SHORT,
|
|
|
|
FORMAT_TYPE_UINT,
|
|
|
|
FORMAT_TYPE_INT,
|
|
|
|
FORMAT_TYPE_NRCHARS,
|
|
|
|
FORMAT_TYPE_SIZE_T,
|
|
|
|
FORMAT_TYPE_PTRDIFF
|
|
|
|
};
|
|
|
|
|
|
|
|
struct printf_spec {
|
2010-04-14 18:27:40 +02:00
|
|
|
u8 type; /* format_type enum */
|
2010-03-07 02:10:14 +01:00
|
|
|
u8 flags; /* flags to number() */
|
2010-04-14 18:27:40 +02:00
|
|
|
u8 base; /* number base, 8, 10 or 16 only */
|
|
|
|
u8 qualifier; /* number qualifier, one of 'hHlLtzZ' */
|
|
|
|
s16 field_width; /* width of output field */
|
|
|
|
s16 precision; /* # of digits/chars */
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
};
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *number(char *buf, char *end, unsigned long long num,
|
|
|
|
struct printf_spec spec)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-02-09 23:24:09 +01:00
|
|
|
/* we are called with base 8, 10 or 16, only, thus don't need "G..." */
|
|
|
|
static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */
|
|
|
|
|
|
|
|
char tmp[66];
|
|
|
|
char sign;
|
|
|
|
char locase;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10);
|
2005-04-17 00:20:36 +02:00
|
|
|
int i;
|
|
|
|
|
2008-02-09 23:24:09 +01:00
|
|
|
/* locase = 0 or 0x20. ORing digits or letters with 'locase'
|
|
|
|
* produces same digits or (maybe lowercased) letters */
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
locase = (spec.flags & SMALL);
|
|
|
|
if (spec.flags & LEFT)
|
|
|
|
spec.flags &= ~ZEROPAD;
|
2005-04-17 00:20:36 +02:00
|
|
|
sign = 0;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
if (spec.flags & SIGN) {
|
2009-12-15 03:00:57 +01:00
|
|
|
if ((signed long long)num < 0) {
|
2005-04-17 00:20:36 +02:00
|
|
|
sign = '-';
|
2009-12-15 03:00:57 +01:00
|
|
|
num = -(signed long long)num;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec.field_width--;
|
|
|
|
} else if (spec.flags & PLUS) {
|
2005-04-17 00:20:36 +02:00
|
|
|
sign = '+';
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec.field_width--;
|
|
|
|
} else if (spec.flags & SPACE) {
|
2005-04-17 00:20:36 +02:00
|
|
|
sign = ' ';
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec.field_width--;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-16 08:41:54 +02:00
|
|
|
if (need_pfx) {
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec.field_width--;
|
|
|
|
if (spec.base == 16)
|
|
|
|
spec.field_width--;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2007-07-16 08:41:54 +02:00
|
|
|
|
|
|
|
/* generate full string in tmp[], in reverse order */
|
2005-04-17 00:20:36 +02:00
|
|
|
i = 0;
|
|
|
|
if (num == 0)
|
2007-07-16 08:41:54 +02:00
|
|
|
tmp[i++] = '0';
|
2007-07-16 08:41:56 +02:00
|
|
|
/* Generic code, for any base:
|
|
|
|
else do {
|
2008-02-09 23:24:09 +01:00
|
|
|
tmp[i++] = (digits[do_div(num,base)] | locase);
|
2007-07-16 08:41:56 +02:00
|
|
|
} while (num != 0);
|
|
|
|
*/
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
else if (spec.base != 10) { /* 8 or 16 */
|
|
|
|
int mask = spec.base - 1;
|
2007-07-16 08:41:54 +02:00
|
|
|
int shift = 3;
|
2009-12-15 03:00:57 +01:00
|
|
|
|
|
|
|
if (spec.base == 16)
|
|
|
|
shift = 4;
|
2007-07-16 08:41:54 +02:00
|
|
|
do {
|
2008-02-09 23:24:09 +01:00
|
|
|
tmp[i++] = (digits[((unsigned char)num) & mask] | locase);
|
2007-07-16 08:41:54 +02:00
|
|
|
num >>= shift;
|
|
|
|
} while (num);
|
2007-07-16 08:41:56 +02:00
|
|
|
} else { /* base 10 */
|
|
|
|
i = put_dec(tmp, num) - tmp;
|
|
|
|
}
|
2007-07-16 08:41:54 +02:00
|
|
|
|
|
|
|
/* printing 100 using %2d gives "100", not "00" */
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
if (i > spec.precision)
|
|
|
|
spec.precision = i;
|
2007-07-16 08:41:54 +02:00
|
|
|
/* leading space padding */
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec.field_width -= spec.precision;
|
|
|
|
if (!(spec.flags & (ZEROPAD+LEFT))) {
|
2009-12-15 03:00:57 +01:00
|
|
|
while (--spec.field_width >= 0) {
|
2006-06-25 14:49:17 +02:00
|
|
|
if (buf < end)
|
2005-04-17 00:20:36 +02:00
|
|
|
*buf = ' ';
|
|
|
|
++buf;
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 08:41:54 +02:00
|
|
|
/* sign */
|
2005-04-17 00:20:36 +02:00
|
|
|
if (sign) {
|
2006-06-25 14:49:17 +02:00
|
|
|
if (buf < end)
|
2005-04-17 00:20:36 +02:00
|
|
|
*buf = sign;
|
|
|
|
++buf;
|
|
|
|
}
|
2007-07-16 08:41:54 +02:00
|
|
|
/* "0x" / "0" prefix */
|
|
|
|
if (need_pfx) {
|
|
|
|
if (buf < end)
|
|
|
|
*buf = '0';
|
|
|
|
++buf;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
if (spec.base == 16) {
|
2006-06-25 14:49:17 +02:00
|
|
|
if (buf < end)
|
2008-02-09 23:24:09 +01:00
|
|
|
*buf = ('X' | locase);
|
2005-04-17 00:20:36 +02:00
|
|
|
++buf;
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 08:41:54 +02:00
|
|
|
/* zero or space padding */
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
if (!(spec.flags & LEFT)) {
|
|
|
|
char c = (spec.flags & ZEROPAD) ? '0' : ' ';
|
|
|
|
while (--spec.field_width >= 0) {
|
2006-06-25 14:49:17 +02:00
|
|
|
if (buf < end)
|
2005-04-17 00:20:36 +02:00
|
|
|
*buf = c;
|
|
|
|
++buf;
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 08:41:54 +02:00
|
|
|
/* hmm even more zero padding? */
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
while (i <= --spec.precision) {
|
2006-06-25 14:49:17 +02:00
|
|
|
if (buf < end)
|
2005-04-17 00:20:36 +02:00
|
|
|
*buf = '0';
|
|
|
|
++buf;
|
|
|
|
}
|
2007-07-16 08:41:54 +02:00
|
|
|
/* actual digits of result */
|
|
|
|
while (--i >= 0) {
|
2006-06-25 14:49:17 +02:00
|
|
|
if (buf < end)
|
2005-04-17 00:20:36 +02:00
|
|
|
*buf = tmp[i];
|
|
|
|
++buf;
|
|
|
|
}
|
2007-07-16 08:41:54 +02:00
|
|
|
/* trailing space padding */
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
while (--spec.field_width >= 0) {
|
2006-06-25 14:49:17 +02:00
|
|
|
if (buf < end)
|
2005-04-17 00:20:36 +02:00
|
|
|
*buf = ' ';
|
|
|
|
++buf;
|
|
|
|
}
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *string(char *buf, char *end, const char *s, struct printf_spec spec)
|
2008-07-07 01:06:25 +02:00
|
|
|
{
|
|
|
|
int len, i;
|
|
|
|
|
|
|
|
if ((unsigned long)s < PAGE_SIZE)
|
2009-12-15 03:00:55 +01:00
|
|
|
s = "(null)";
|
2008-07-07 01:06:25 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
len = strnlen(s, spec.precision);
|
2008-07-07 01:06:25 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
if (!(spec.flags & LEFT)) {
|
|
|
|
while (len < spec.field_width--) {
|
2008-07-07 01:06:25 +02:00
|
|
|
if (buf < end)
|
|
|
|
*buf = ' ';
|
|
|
|
++buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
if (buf < end)
|
|
|
|
*buf = *s;
|
|
|
|
++buf; ++s;
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
while (len < spec.field_width--) {
|
2008-07-07 01:06:25 +02:00
|
|
|
if (buf < end)
|
|
|
|
*buf = ' ';
|
|
|
|
++buf;
|
|
|
|
}
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2008-07-07 01:06:25 +02:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *symbol_string(char *buf, char *end, void *ptr,
|
|
|
|
struct printf_spec spec, char ext)
|
2008-07-07 01:43:12 +02:00
|
|
|
{
|
|
|
|
unsigned long value = (unsigned long) ptr;
|
|
|
|
#ifdef CONFIG_KALLSYMS
|
|
|
|
char sym[KSYM_SYMBOL_LEN];
|
2009-09-17 02:03:06 +02:00
|
|
|
if (ext != 'f' && ext != 's')
|
vsprintf: introduce %pf format specifier
A printf format specifier which would allow us to print a pure
function name has been suggested by Andrew Morton a couple of
months ago.
The current %pF is very convenient to print a function symbol,
but often we only want to print the name of the function, without
its asm offset.
That's what %pf does in this patch. The lowecase f has been chosen
for its intuitive meaning of a 'weak kind of %pF'.
The support for this new format would be welcome by the tracing code
where the need to print pure function names is often needed. This is
also true for other parts of the kernel:
$ git-grep -E "kallsyms_lookup\(.+?\)"
arch/blackfin/kernel/traps.c: symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
arch/powerpc/xmon/xmon.c: name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
arch/sh/kernel/cpu/sh5/unwind.c: sym = kallsyms_lookup(pc, NULL, &offset, NULL, namebuf);
arch/x86/kernel/ftrace.c: kallsyms_lookup((unsigned long) syscall, NULL, NULL, NULL, str);
kernel/kprobes.c: sym = kallsyms_lookup((unsigned long)p->addr, NULL,
kernel/lockdep.c: return kallsyms_lookup((unsigned long)key, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup((unsigned long)rec->ops->func, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
kernel/trace/ftrace.c: kallsyms_lookup(*ptr, NULL, NULL, NULL, str);
kernel/trace/trace_functions.c: kallsyms_lookup(ip, NULL, NULL, NULL, str);
kernel/trace/trace_output.c: kallsyms_lookup(address, NULL, NULL, NULL, str);
Changes in v2:
- Add the explanation of the %pf role for vsnprintf() and bstr_printf()
- Change the comments by dropping the "asm offset" notion and only
define the %pf against the actual function offset notion.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090415154817.GC5989@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-15 17:48:18 +02:00
|
|
|
sprint_symbol(sym, value);
|
|
|
|
else
|
|
|
|
kallsyms_lookup(value, NULL, NULL, NULL, sym);
|
2009-12-15 03:00:57 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
return string(buf, end, sym, spec);
|
2008-07-07 01:43:12 +02:00
|
|
|
#else
|
2009-12-15 03:00:57 +01:00
|
|
|
spec.field_width = 2 * sizeof(void *);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec.flags |= SPECIAL | SMALL | ZEROPAD;
|
|
|
|
spec.base = 16;
|
2009-12-15 03:00:57 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
return number(buf, end, value, spec);
|
2008-07-07 01:43:12 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *resource_string(char *buf, char *end, struct resource *res,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
2008-10-20 06:07:34 +02:00
|
|
|
{
|
|
|
|
#ifndef IO_RSRC_PRINTK_SIZE
|
2009-10-06 23:33:29 +02:00
|
|
|
#define IO_RSRC_PRINTK_SIZE 6
|
2008-10-20 06:07:34 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MEM_RSRC_PRINTK_SIZE
|
2009-10-06 23:33:29 +02:00
|
|
|
#define MEM_RSRC_PRINTK_SIZE 10
|
2008-10-20 06:07:34 +02:00
|
|
|
#endif
|
2010-03-05 18:47:37 +01:00
|
|
|
static const struct printf_spec io_spec = {
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
.base = 16,
|
2010-03-05 18:47:37 +01:00
|
|
|
.field_width = IO_RSRC_PRINTK_SIZE,
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
.precision = -1,
|
|
|
|
.flags = SPECIAL | SMALL | ZEROPAD,
|
|
|
|
};
|
2010-03-05 18:47:37 +01:00
|
|
|
static const struct printf_spec mem_spec = {
|
|
|
|
.base = 16,
|
|
|
|
.field_width = MEM_RSRC_PRINTK_SIZE,
|
|
|
|
.precision = -1,
|
|
|
|
.flags = SPECIAL | SMALL | ZEROPAD,
|
|
|
|
};
|
2010-03-05 18:47:42 +01:00
|
|
|
static const struct printf_spec bus_spec = {
|
|
|
|
.base = 16,
|
|
|
|
.field_width = 2,
|
|
|
|
.precision = -1,
|
|
|
|
.flags = SMALL | ZEROPAD,
|
|
|
|
};
|
2010-03-05 18:47:37 +01:00
|
|
|
static const struct printf_spec dec_spec = {
|
2009-10-06 23:33:34 +02:00
|
|
|
.base = 10,
|
|
|
|
.precision = -1,
|
|
|
|
.flags = 0,
|
|
|
|
};
|
2010-03-05 18:47:37 +01:00
|
|
|
static const struct printf_spec str_spec = {
|
2009-10-06 23:33:39 +02:00
|
|
|
.field_width = -1,
|
|
|
|
.precision = 10,
|
|
|
|
.flags = LEFT,
|
|
|
|
};
|
2010-03-05 18:47:37 +01:00
|
|
|
static const struct printf_spec flag_spec = {
|
2009-10-06 23:33:39 +02:00
|
|
|
.base = 16,
|
|
|
|
.precision = -1,
|
|
|
|
.flags = SPECIAL | SMALL,
|
|
|
|
};
|
2009-10-27 20:26:47 +01:00
|
|
|
|
|
|
|
/* 32-bit res (sizeof==4): 10 chars in dec, 10 in hex ("0x" + 8)
|
|
|
|
* 64-bit res (sizeof==8): 20 chars in dec, 18 in hex ("0x" + 16) */
|
|
|
|
#define RSRC_BUF_SIZE ((2 * sizeof(resource_size_t)) + 4)
|
|
|
|
#define FLAG_BUF_SIZE (2 * sizeof(res->flags))
|
2010-03-05 18:47:47 +01:00
|
|
|
#define DECODED_BUF_SIZE sizeof("[mem - 64bit pref window disabled]")
|
2009-10-27 20:26:47 +01:00
|
|
|
#define RAW_BUF_SIZE sizeof("[mem - flags 0x]")
|
|
|
|
char sym[max(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE,
|
|
|
|
2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)];
|
|
|
|
|
2008-10-20 06:07:34 +02:00
|
|
|
char *p = sym, *pend = sym + sizeof(sym);
|
2009-10-27 20:26:47 +01:00
|
|
|
int decode = (fmt[0] == 'R') ? 1 : 0;
|
2010-03-05 18:47:37 +01:00
|
|
|
const struct printf_spec *specp;
|
2008-10-20 06:07:34 +02:00
|
|
|
|
|
|
|
*p++ = '[';
|
2010-03-05 18:47:37 +01:00
|
|
|
if (res->flags & IORESOURCE_IO) {
|
2009-10-27 20:26:47 +01:00
|
|
|
p = string(p, pend, "io ", str_spec);
|
2010-03-05 18:47:37 +01:00
|
|
|
specp = &io_spec;
|
|
|
|
} else if (res->flags & IORESOURCE_MEM) {
|
2009-10-27 20:26:47 +01:00
|
|
|
p = string(p, pend, "mem ", str_spec);
|
2010-03-05 18:47:37 +01:00
|
|
|
specp = &mem_spec;
|
|
|
|
} else if (res->flags & IORESOURCE_IRQ) {
|
2009-10-27 20:26:47 +01:00
|
|
|
p = string(p, pend, "irq ", str_spec);
|
2010-03-05 18:47:37 +01:00
|
|
|
specp = &dec_spec;
|
|
|
|
} else if (res->flags & IORESOURCE_DMA) {
|
2009-10-27 20:26:47 +01:00
|
|
|
p = string(p, pend, "dma ", str_spec);
|
2010-03-05 18:47:37 +01:00
|
|
|
specp = &dec_spec;
|
2010-03-05 18:47:42 +01:00
|
|
|
} else if (res->flags & IORESOURCE_BUS) {
|
|
|
|
p = string(p, pend, "bus ", str_spec);
|
|
|
|
specp = &bus_spec;
|
2010-03-05 18:47:37 +01:00
|
|
|
} else {
|
2009-10-27 20:26:47 +01:00
|
|
|
p = string(p, pend, "??? ", str_spec);
|
2010-03-05 18:47:37 +01:00
|
|
|
specp = &mem_spec;
|
2009-10-27 20:26:47 +01:00
|
|
|
decode = 0;
|
2009-10-06 23:33:39 +02:00
|
|
|
}
|
2010-03-05 18:47:37 +01:00
|
|
|
p = number(p, pend, res->start, *specp);
|
2009-10-06 23:33:34 +02:00
|
|
|
if (res->start != res->end) {
|
|
|
|
*p++ = '-';
|
2010-03-05 18:47:37 +01:00
|
|
|
p = number(p, pend, res->end, *specp);
|
2009-10-06 23:33:34 +02:00
|
|
|
}
|
2009-10-27 20:26:47 +01:00
|
|
|
if (decode) {
|
2009-10-06 23:33:39 +02:00
|
|
|
if (res->flags & IORESOURCE_MEM_64)
|
|
|
|
p = string(p, pend, " 64bit", str_spec);
|
|
|
|
if (res->flags & IORESOURCE_PREFETCH)
|
|
|
|
p = string(p, pend, " pref", str_spec);
|
2010-03-05 18:47:47 +01:00
|
|
|
if (res->flags & IORESOURCE_WINDOW)
|
|
|
|
p = string(p, pend, " window", str_spec);
|
2009-10-06 23:33:39 +02:00
|
|
|
if (res->flags & IORESOURCE_DISABLED)
|
|
|
|
p = string(p, pend, " disabled", str_spec);
|
2009-10-27 20:26:47 +01:00
|
|
|
} else {
|
|
|
|
p = string(p, pend, " flags ", str_spec);
|
|
|
|
p = number(p, pend, res->flags, flag_spec);
|
2009-10-06 23:33:39 +02:00
|
|
|
}
|
2008-10-20 06:07:34 +02:00
|
|
|
*p++ = ']';
|
2009-10-27 20:26:47 +01:00
|
|
|
*p = '\0';
|
2008-10-20 06:07:34 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
return string(buf, end, sym, spec);
|
2008-10-20 06:07:34 +02:00
|
|
|
}
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *mac_address_string(char *buf, char *end, u8 *addr,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
2008-10-27 23:47:12 +01:00
|
|
|
{
|
2009-08-17 14:29:44 +02:00
|
|
|
char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
|
2008-10-27 23:47:12 +01:00
|
|
|
char *p = mac_addr;
|
|
|
|
int i;
|
2010-01-07 12:43:50 +01:00
|
|
|
char separator;
|
|
|
|
|
|
|
|
if (fmt[1] == 'F') { /* FDDI canonical format */
|
|
|
|
separator = '-';
|
|
|
|
} else {
|
|
|
|
separator = ':';
|
|
|
|
}
|
2008-10-27 23:47:12 +01:00
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
2010-01-11 09:44:14 +01:00
|
|
|
p = pack_hex_byte(p, addr[i]);
|
2009-08-17 14:29:44 +02:00
|
|
|
if (fmt[0] == 'M' && i != 5)
|
2010-01-07 12:43:50 +01:00
|
|
|
*p++ = separator;
|
2008-10-27 23:47:12 +01:00
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
return string(buf, end, mac_addr, spec);
|
2008-10-27 23:47:12 +01:00
|
|
|
}
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip4_string(char *p, const u8 *addr, const char *fmt)
|
2009-08-17 14:29:44 +02:00
|
|
|
{
|
|
|
|
int i;
|
2010-01-14 05:23:30 +01:00
|
|
|
bool leading_zeros = (fmt[0] == 'i');
|
|
|
|
int index;
|
|
|
|
int step;
|
|
|
|
|
|
|
|
switch (fmt[2]) {
|
|
|
|
case 'h':
|
|
|
|
#ifdef __BIG_ENDIAN
|
|
|
|
index = 0;
|
|
|
|
step = 1;
|
|
|
|
#else
|
|
|
|
index = 3;
|
|
|
|
step = -1;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
index = 3;
|
|
|
|
step = -1;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
case 'b':
|
|
|
|
default:
|
|
|
|
index = 0;
|
|
|
|
step = 1;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-17 14:29:44 +02:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
char temp[3]; /* hold each IP quad in reverse order */
|
2010-01-14 05:23:30 +01:00
|
|
|
int digits = put_dec_trunc(temp, addr[index]) - temp;
|
2009-08-17 14:29:44 +02:00
|
|
|
if (leading_zeros) {
|
|
|
|
if (digits < 3)
|
|
|
|
*p++ = '0';
|
|
|
|
if (digits < 2)
|
|
|
|
*p++ = '0';
|
|
|
|
}
|
|
|
|
/* reverse the digits in the quad */
|
|
|
|
while (digits--)
|
|
|
|
*p++ = temp[digits];
|
|
|
|
if (i < 3)
|
|
|
|
*p++ = '.';
|
2010-01-14 05:23:30 +01:00
|
|
|
index += step;
|
2009-08-17 14:29:44 +02:00
|
|
|
}
|
|
|
|
*p = '\0';
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2009-08-17 14:29:44 +02:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip6_compressed_string(char *p, const char *addr)
|
2008-10-29 00:04:44 +01:00
|
|
|
{
|
2009-12-15 03:00:57 +01:00
|
|
|
int i, j, range;
|
2009-08-17 14:29:44 +02:00
|
|
|
unsigned char zerolength[8];
|
|
|
|
int longest = 1;
|
|
|
|
int colonpos = -1;
|
|
|
|
u16 word;
|
2009-12-15 03:00:57 +01:00
|
|
|
u8 hi, lo;
|
2009-08-17 14:29:44 +02:00
|
|
|
bool needcolon = false;
|
2009-09-18 15:04:06 +02:00
|
|
|
bool useIPv4;
|
|
|
|
struct in6_addr in6;
|
|
|
|
|
|
|
|
memcpy(&in6, addr, sizeof(struct in6_addr));
|
|
|
|
|
|
|
|
useIPv4 = ipv6_addr_v4mapped(&in6) || ipv6_addr_is_isatap(&in6);
|
2009-08-17 14:29:44 +02:00
|
|
|
|
|
|
|
memset(zerolength, 0, sizeof(zerolength));
|
|
|
|
|
|
|
|
if (useIPv4)
|
|
|
|
range = 6;
|
|
|
|
else
|
|
|
|
range = 8;
|
|
|
|
|
|
|
|
/* find position of longest 0 run */
|
|
|
|
for (i = 0; i < range; i++) {
|
|
|
|
for (j = i; j < range; j++) {
|
2009-09-18 15:04:06 +02:00
|
|
|
if (in6.s6_addr16[j] != 0)
|
2009-08-17 14:29:44 +02:00
|
|
|
break;
|
|
|
|
zerolength[i]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < range; i++) {
|
|
|
|
if (zerolength[i] > longest) {
|
|
|
|
longest = zerolength[i];
|
|
|
|
colonpos = i;
|
|
|
|
}
|
|
|
|
}
|
2008-10-29 00:04:44 +01:00
|
|
|
|
2009-08-17 14:29:44 +02:00
|
|
|
/* emit address */
|
|
|
|
for (i = 0; i < range; i++) {
|
|
|
|
if (i == colonpos) {
|
|
|
|
if (needcolon || i == 0)
|
|
|
|
*p++ = ':';
|
|
|
|
*p++ = ':';
|
|
|
|
needcolon = false;
|
|
|
|
i += longest - 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (needcolon) {
|
|
|
|
*p++ = ':';
|
|
|
|
needcolon = false;
|
|
|
|
}
|
|
|
|
/* hex u16 without leading 0s */
|
2009-09-18 15:04:06 +02:00
|
|
|
word = ntohs(in6.s6_addr16[i]);
|
2009-08-17 14:29:44 +02:00
|
|
|
hi = word >> 8;
|
|
|
|
lo = word & 0xff;
|
|
|
|
if (hi) {
|
|
|
|
if (hi > 0x0f)
|
|
|
|
p = pack_hex_byte(p, hi);
|
|
|
|
else
|
|
|
|
*p++ = hex_asc_lo(hi);
|
2009-12-15 03:00:59 +01:00
|
|
|
p = pack_hex_byte(p, lo);
|
2009-08-17 14:29:44 +02:00
|
|
|
}
|
2009-12-15 03:00:59 +01:00
|
|
|
else if (lo > 0x0f)
|
2009-08-17 14:29:44 +02:00
|
|
|
p = pack_hex_byte(p, lo);
|
|
|
|
else
|
|
|
|
*p++ = hex_asc_lo(lo);
|
|
|
|
needcolon = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useIPv4) {
|
|
|
|
if (needcolon)
|
|
|
|
*p++ = ':';
|
2010-01-14 05:23:30 +01:00
|
|
|
p = ip4_string(p, &in6.s6_addr[12], "I4");
|
2009-08-17 14:29:44 +02:00
|
|
|
}
|
|
|
|
*p = '\0';
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2009-08-17 14:29:44 +02:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip6_string(char *p, const char *addr, const char *fmt)
|
2009-08-17 14:29:44 +02:00
|
|
|
{
|
|
|
|
int i;
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2008-10-29 00:04:44 +01:00
|
|
|
for (i = 0; i < 8; i++) {
|
2009-09-18 15:04:06 +02:00
|
|
|
p = pack_hex_byte(p, *addr++);
|
|
|
|
p = pack_hex_byte(p, *addr++);
|
2009-08-17 14:29:44 +02:00
|
|
|
if (fmt[0] == 'I' && i != 7)
|
2008-10-29 00:04:44 +01:00
|
|
|
*p++ = ':';
|
|
|
|
}
|
|
|
|
*p = '\0';
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2009-08-17 14:29:44 +02:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip6_addr_string(char *buf, char *end, const u8 *addr,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
2009-08-17 14:29:44 +02:00
|
|
|
{
|
|
|
|
char ip6_addr[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")];
|
|
|
|
|
|
|
|
if (fmt[0] == 'I' && fmt[2] == 'c')
|
2009-09-18 15:04:06 +02:00
|
|
|
ip6_compressed_string(ip6_addr, addr);
|
2009-08-17 14:29:44 +02:00
|
|
|
else
|
2009-09-18 15:04:06 +02:00
|
|
|
ip6_string(ip6_addr, addr, fmt);
|
2008-10-29 00:04:44 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
return string(buf, end, ip6_addr, spec);
|
2008-10-29 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *ip4_addr_string(char *buf, char *end, const u8 *addr,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
2008-10-29 20:49:58 +01:00
|
|
|
{
|
2009-08-17 14:29:44 +02:00
|
|
|
char ip4_addr[sizeof("255.255.255.255")];
|
2008-10-29 20:49:58 +01:00
|
|
|
|
2010-01-14 05:23:30 +01:00
|
|
|
ip4_string(ip4_addr, addr, fmt);
|
2008-10-29 20:49:58 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
return string(buf, end, ip4_addr, spec);
|
2008-10-29 20:49:58 +01:00
|
|
|
}
|
|
|
|
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *uuid_string(char *buf, char *end, const u8 *addr,
|
|
|
|
struct printf_spec spec, const char *fmt)
|
2009-12-15 03:01:09 +01:00
|
|
|
{
|
|
|
|
char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
|
|
|
|
char *p = uuid;
|
|
|
|
int i;
|
|
|
|
static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
|
|
|
|
static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
|
|
|
|
const u8 *index = be;
|
|
|
|
bool uc = false;
|
|
|
|
|
|
|
|
switch (*(++fmt)) {
|
|
|
|
case 'L':
|
|
|
|
uc = true; /* fall-through */
|
|
|
|
case 'l':
|
|
|
|
index = le;
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
uc = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
p = pack_hex_byte(p, addr[index[i]]);
|
|
|
|
switch (i) {
|
|
|
|
case 3:
|
|
|
|
case 5:
|
|
|
|
case 7:
|
|
|
|
case 9:
|
|
|
|
*p++ = '-';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
if (uc) {
|
|
|
|
p = uuid;
|
|
|
|
do {
|
|
|
|
*p = toupper(*p);
|
|
|
|
} while (*(++p));
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(buf, end, uuid, spec);
|
|
|
|
}
|
|
|
|
|
kptr_restrict for hiding kernel pointers from unprivileged users
Add the %pK printk format specifier and the /proc/sys/kernel/kptr_restrict
sysctl.
The %pK format specifier is designed to hide exposed kernel pointers,
specifically via /proc interfaces. Exposing these pointers provides an
easy target for kernel write vulnerabilities, since they reveal the
locations of writable structures containing easily triggerable function
pointers. The behavior of %pK depends on the kptr_restrict sysctl.
If kptr_restrict is set to 0, no deviation from the standard %p behavior
occurs. If kptr_restrict is set to 1, the default, if the current user
(intended to be a reader via seq_printf(), etc.) does not have CAP_SYSLOG
(currently in the LSM tree), kernel pointers using %pK are printed as 0's.
If kptr_restrict is set to 2, kernel pointers using %pK are printed as
0's regardless of privileges. Replacing with 0's was chosen over the
default "(null)", which cannot be parsed by userland %p, which expects
"(nil)".
[akpm@linux-foundation.org: check for IRQ context when !kptr_restrict, save an indent level, s/WARN/WARN_ONCE/]
[akpm@linux-foundation.org: coding-style fixup]
[randy.dunlap@oracle.com: fix kernel/sysctl.c warning]
Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Cc: James Morris <jmorris@namei.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Thomas Graf <tgraf@infradead.org>
Cc: Eugene Teo <eugeneteo@kernel.org>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 01:59:41 +01:00
|
|
|
int kptr_restrict = 1;
|
|
|
|
|
2008-07-07 01:24:57 +02:00
|
|
|
/*
|
|
|
|
* Show a '%p' thing. A kernel extension is that the '%p' is followed
|
|
|
|
* by an extra set of alphanumeric characters that are extended format
|
|
|
|
* specifiers.
|
|
|
|
*
|
2008-10-20 06:07:34 +02:00
|
|
|
* Right now we handle:
|
|
|
|
*
|
vsprintf: introduce %pf format specifier
A printf format specifier which would allow us to print a pure
function name has been suggested by Andrew Morton a couple of
months ago.
The current %pF is very convenient to print a function symbol,
but often we only want to print the name of the function, without
its asm offset.
That's what %pf does in this patch. The lowecase f has been chosen
for its intuitive meaning of a 'weak kind of %pF'.
The support for this new format would be welcome by the tracing code
where the need to print pure function names is often needed. This is
also true for other parts of the kernel:
$ git-grep -E "kallsyms_lookup\(.+?\)"
arch/blackfin/kernel/traps.c: symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
arch/powerpc/xmon/xmon.c: name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
arch/sh/kernel/cpu/sh5/unwind.c: sym = kallsyms_lookup(pc, NULL, &offset, NULL, namebuf);
arch/x86/kernel/ftrace.c: kallsyms_lookup((unsigned long) syscall, NULL, NULL, NULL, str);
kernel/kprobes.c: sym = kallsyms_lookup((unsigned long)p->addr, NULL,
kernel/lockdep.c: return kallsyms_lookup((unsigned long)key, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup((unsigned long)rec->ops->func, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
kernel/trace/ftrace.c: kallsyms_lookup(*ptr, NULL, NULL, NULL, str);
kernel/trace/trace_functions.c: kallsyms_lookup(ip, NULL, NULL, NULL, str);
kernel/trace/trace_output.c: kallsyms_lookup(address, NULL, NULL, NULL, str);
Changes in v2:
- Add the explanation of the %pf role for vsnprintf() and bstr_printf()
- Change the comments by dropping the "asm offset" notion and only
define the %pf against the actual function offset notion.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090415154817.GC5989@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-15 17:48:18 +02:00
|
|
|
* - 'F' For symbolic function descriptor pointers with offset
|
|
|
|
* - 'f' For simple symbolic function names without offset
|
2009-09-17 15:27:29 +02:00
|
|
|
* - 'S' For symbolic direct pointers with offset
|
|
|
|
* - 's' For symbolic direct pointers without offset
|
2009-10-27 20:26:47 +01:00
|
|
|
* - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
|
|
|
|
* - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
|
2008-10-27 23:47:12 +01:00
|
|
|
* - 'M' For a 6-byte MAC address, it prints the address in the
|
|
|
|
* usual colon-separated hex notation
|
2009-08-17 14:29:44 +02:00
|
|
|
* - 'm' For a 6-byte MAC address, it prints the hex address without colons
|
2010-01-07 12:43:50 +01:00
|
|
|
* - 'MF' For a 6-byte MAC FDDI address, it prints the address
|
2010-01-11 09:44:14 +01:00
|
|
|
* with a dash-separated hex notation
|
2009-08-17 14:29:44 +02:00
|
|
|
* - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
|
|
|
|
* IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
|
|
|
|
* IPv6 uses colon separated network-order 16 bit hex with leading 0's
|
|
|
|
* - 'i' [46] for 'raw' IPv4/IPv6 addresses
|
|
|
|
* IPv6 omits the colons (01020304...0f)
|
|
|
|
* IPv4 uses dot-separated decimal with leading 0's (010.123.045.006)
|
2010-01-14 05:23:30 +01:00
|
|
|
* - '[Ii]4[hnbl]' IPv4 addresses in host, network, big or little endian order
|
2009-08-17 14:29:44 +02:00
|
|
|
* - 'I6c' for IPv6 addresses printed as specified by
|
2010-01-08 23:43:02 +01:00
|
|
|
* http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00
|
2009-12-15 03:01:09 +01:00
|
|
|
* - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form
|
|
|
|
* "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
|
|
* Options for %pU are:
|
|
|
|
* b big endian lower case hex (default)
|
|
|
|
* B big endian UPPER case hex
|
|
|
|
* l little endian lower case hex
|
|
|
|
* L little endian UPPER case hex
|
|
|
|
* big endian output byte order is:
|
|
|
|
* [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15]
|
|
|
|
* little endian output byte order is:
|
|
|
|
* [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15]
|
2010-06-27 03:02:33 +02:00
|
|
|
* - 'V' For a struct va_format which contains a format string * and va_list *,
|
|
|
|
* call vsnprintf(->format, *->va_list).
|
|
|
|
* Implements a "recursive vsnprintf".
|
|
|
|
* Do not use this feature without some mechanism to verify the
|
|
|
|
* correctness of the format string and va_list arguments.
|
kptr_restrict for hiding kernel pointers from unprivileged users
Add the %pK printk format specifier and the /proc/sys/kernel/kptr_restrict
sysctl.
The %pK format specifier is designed to hide exposed kernel pointers,
specifically via /proc interfaces. Exposing these pointers provides an
easy target for kernel write vulnerabilities, since they reveal the
locations of writable structures containing easily triggerable function
pointers. The behavior of %pK depends on the kptr_restrict sysctl.
If kptr_restrict is set to 0, no deviation from the standard %p behavior
occurs. If kptr_restrict is set to 1, the default, if the current user
(intended to be a reader via seq_printf(), etc.) does not have CAP_SYSLOG
(currently in the LSM tree), kernel pointers using %pK are printed as 0's.
If kptr_restrict is set to 2, kernel pointers using %pK are printed as
0's regardless of privileges. Replacing with 0's was chosen over the
default "(null)", which cannot be parsed by userland %p, which expects
"(nil)".
[akpm@linux-foundation.org: check for IRQ context when !kptr_restrict, save an indent level, s/WARN/WARN_ONCE/]
[akpm@linux-foundation.org: coding-style fixup]
[randy.dunlap@oracle.com: fix kernel/sysctl.c warning]
Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Cc: James Morris <jmorris@namei.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Thomas Graf <tgraf@infradead.org>
Cc: Eugene Teo <eugeneteo@kernel.org>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 01:59:41 +01:00
|
|
|
* - 'K' For a kernel pointer that should be hidden from unprivileged users
|
2009-12-15 03:01:09 +01:00
|
|
|
*
|
2008-10-20 06:07:34 +02:00
|
|
|
* Note: The difference between 'S' and 'F' is that on ia64 and ppc64
|
|
|
|
* function pointers are really function descriptors, which contain a
|
|
|
|
* pointer to the real address.
|
2008-07-07 01:24:57 +02:00
|
|
|
*/
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
char *pointer(const char *fmt, char *buf, char *end, void *ptr,
|
|
|
|
struct printf_spec spec)
|
2008-07-07 01:16:15 +02:00
|
|
|
{
|
2010-10-26 23:22:50 +02:00
|
|
|
if (!ptr) {
|
|
|
|
/*
|
|
|
|
* Print (null) with the same width as a pointer so it makes
|
|
|
|
* tabular output look nice.
|
|
|
|
*/
|
|
|
|
if (spec.field_width == -1)
|
|
|
|
spec.field_width = 2 * sizeof(void *);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
return string(buf, end, "(null)", spec);
|
2010-10-26 23:22:50 +02:00
|
|
|
}
|
2009-01-03 20:46:17 +01:00
|
|
|
|
2008-07-07 01:43:12 +02:00
|
|
|
switch (*fmt) {
|
|
|
|
case 'F':
|
vsprintf: introduce %pf format specifier
A printf format specifier which would allow us to print a pure
function name has been suggested by Andrew Morton a couple of
months ago.
The current %pF is very convenient to print a function symbol,
but often we only want to print the name of the function, without
its asm offset.
That's what %pf does in this patch. The lowecase f has been chosen
for its intuitive meaning of a 'weak kind of %pF'.
The support for this new format would be welcome by the tracing code
where the need to print pure function names is often needed. This is
also true for other parts of the kernel:
$ git-grep -E "kallsyms_lookup\(.+?\)"
arch/blackfin/kernel/traps.c: symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
arch/powerpc/xmon/xmon.c: name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
arch/sh/kernel/cpu/sh5/unwind.c: sym = kallsyms_lookup(pc, NULL, &offset, NULL, namebuf);
arch/x86/kernel/ftrace.c: kallsyms_lookup((unsigned long) syscall, NULL, NULL, NULL, str);
kernel/kprobes.c: sym = kallsyms_lookup((unsigned long)p->addr, NULL,
kernel/lockdep.c: return kallsyms_lookup((unsigned long)key, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup((unsigned long)rec->ops->func, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
kernel/trace/ftrace.c: kallsyms_lookup(*ptr, NULL, NULL, NULL, str);
kernel/trace/trace_functions.c: kallsyms_lookup(ip, NULL, NULL, NULL, str);
kernel/trace/trace_output.c: kallsyms_lookup(address, NULL, NULL, NULL, str);
Changes in v2:
- Add the explanation of the %pf role for vsnprintf() and bstr_printf()
- Change the comments by dropping the "asm offset" notion and only
define the %pf against the actual function offset notion.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090415154817.GC5989@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-15 17:48:18 +02:00
|
|
|
case 'f':
|
2008-07-07 01:43:12 +02:00
|
|
|
ptr = dereference_function_descriptor(ptr);
|
|
|
|
/* Fallthrough */
|
|
|
|
case 'S':
|
2009-12-15 03:01:09 +01:00
|
|
|
case 's':
|
vsprintf: introduce %pf format specifier
A printf format specifier which would allow us to print a pure
function name has been suggested by Andrew Morton a couple of
months ago.
The current %pF is very convenient to print a function symbol,
but often we only want to print the name of the function, without
its asm offset.
That's what %pf does in this patch. The lowecase f has been chosen
for its intuitive meaning of a 'weak kind of %pF'.
The support for this new format would be welcome by the tracing code
where the need to print pure function names is often needed. This is
also true for other parts of the kernel:
$ git-grep -E "kallsyms_lookup\(.+?\)"
arch/blackfin/kernel/traps.c: symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
arch/powerpc/xmon/xmon.c: name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
arch/sh/kernel/cpu/sh5/unwind.c: sym = kallsyms_lookup(pc, NULL, &offset, NULL, namebuf);
arch/x86/kernel/ftrace.c: kallsyms_lookup((unsigned long) syscall, NULL, NULL, NULL, str);
kernel/kprobes.c: sym = kallsyms_lookup((unsigned long)p->addr, NULL,
kernel/lockdep.c: return kallsyms_lookup((unsigned long)key, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup((unsigned long)rec->ops->func, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
kernel/trace/ftrace.c: kallsyms_lookup(*ptr, NULL, NULL, NULL, str);
kernel/trace/trace_functions.c: kallsyms_lookup(ip, NULL, NULL, NULL, str);
kernel/trace/trace_output.c: kallsyms_lookup(address, NULL, NULL, NULL, str);
Changes in v2:
- Add the explanation of the %pf role for vsnprintf() and bstr_printf()
- Change the comments by dropping the "asm offset" notion and only
define the %pf against the actual function offset notion.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090415154817.GC5989@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-15 17:48:18 +02:00
|
|
|
return symbol_string(buf, end, ptr, spec, *fmt);
|
2008-10-20 06:07:34 +02:00
|
|
|
case 'R':
|
2009-10-27 20:26:47 +01:00
|
|
|
case 'r':
|
2009-10-06 23:33:39 +02:00
|
|
|
return resource_string(buf, end, ptr, spec, fmt);
|
2009-08-17 14:29:44 +02:00
|
|
|
case 'M': /* Colon separated: 00:01:02:03:04:05 */
|
|
|
|
case 'm': /* Contiguous: 000102030405 */
|
2010-01-07 12:43:50 +01:00
|
|
|
/* [mM]F (FDDI, bit reversed) */
|
2009-08-17 14:29:44 +02:00
|
|
|
return mac_address_string(buf, end, ptr, spec, fmt);
|
|
|
|
case 'I': /* Formatted IP supported
|
|
|
|
* 4: 1.2.3.4
|
|
|
|
* 6: 0001:0203:...:0708
|
|
|
|
* 6c: 1::708 or 1::1.2.3.4
|
|
|
|
*/
|
|
|
|
case 'i': /* Contiguous:
|
|
|
|
* 4: 001.002.003.004
|
|
|
|
* 6: 000102...0f
|
|
|
|
*/
|
|
|
|
switch (fmt[1]) {
|
|
|
|
case '6':
|
|
|
|
return ip6_addr_string(buf, end, ptr, spec, fmt);
|
|
|
|
case '4':
|
|
|
|
return ip4_addr_string(buf, end, ptr, spec, fmt);
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
2009-12-15 03:01:09 +01:00
|
|
|
case 'U':
|
|
|
|
return uuid_string(buf, end, ptr, spec, fmt);
|
2010-06-27 03:02:33 +02:00
|
|
|
case 'V':
|
|
|
|
return buf + vsnprintf(buf, end - buf,
|
|
|
|
((struct va_format *)ptr)->fmt,
|
|
|
|
*(((struct va_format *)ptr)->va));
|
kptr_restrict for hiding kernel pointers from unprivileged users
Add the %pK printk format specifier and the /proc/sys/kernel/kptr_restrict
sysctl.
The %pK format specifier is designed to hide exposed kernel pointers,
specifically via /proc interfaces. Exposing these pointers provides an
easy target for kernel write vulnerabilities, since they reveal the
locations of writable structures containing easily triggerable function
pointers. The behavior of %pK depends on the kptr_restrict sysctl.
If kptr_restrict is set to 0, no deviation from the standard %p behavior
occurs. If kptr_restrict is set to 1, the default, if the current user
(intended to be a reader via seq_printf(), etc.) does not have CAP_SYSLOG
(currently in the LSM tree), kernel pointers using %pK are printed as 0's.
If kptr_restrict is set to 2, kernel pointers using %pK are printed as
0's regardless of privileges. Replacing with 0's was chosen over the
default "(null)", which cannot be parsed by userland %p, which expects
"(nil)".
[akpm@linux-foundation.org: check for IRQ context when !kptr_restrict, save an indent level, s/WARN/WARN_ONCE/]
[akpm@linux-foundation.org: coding-style fixup]
[randy.dunlap@oracle.com: fix kernel/sysctl.c warning]
Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Cc: James Morris <jmorris@namei.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Thomas Graf <tgraf@infradead.org>
Cc: Eugene Teo <eugeneteo@kernel.org>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-01-13 01:59:41 +01:00
|
|
|
case 'K':
|
|
|
|
/*
|
|
|
|
* %pK cannot be used in IRQ context because its test
|
|
|
|
* for CAP_SYSLOG would be meaningless.
|
|
|
|
*/
|
|
|
|
if (in_irq() || in_serving_softirq() || in_nmi()) {
|
|
|
|
if (spec.field_width == -1)
|
|
|
|
spec.field_width = 2 * sizeof(void *);
|
|
|
|
return string(buf, end, "pK-error", spec);
|
|
|
|
} else if ((kptr_restrict == 0) ||
|
|
|
|
(kptr_restrict == 1 &&
|
|
|
|
has_capability_noaudit(current, CAP_SYSLOG)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (spec.field_width == -1) {
|
|
|
|
spec.field_width = 2 * sizeof(void *);
|
|
|
|
spec.flags |= ZEROPAD;
|
|
|
|
}
|
|
|
|
return number(buf, end, 0, spec);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
}
|
|
|
|
spec.flags |= SMALL;
|
|
|
|
if (spec.field_width == -1) {
|
2010-10-26 23:22:50 +02:00
|
|
|
spec.field_width = 2 * sizeof(void *);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec.flags |= ZEROPAD;
|
|
|
|
}
|
|
|
|
spec.base = 16;
|
|
|
|
|
|
|
|
return number(buf, end, (unsigned long) ptr, spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function to decode printf style format.
|
|
|
|
* Each call decode a token from the format and return the
|
|
|
|
* number of characters read (or likely the delta where it wants
|
|
|
|
* to go on the next call).
|
|
|
|
* The decoded token is returned through the parameters
|
|
|
|
*
|
|
|
|
* 'h', 'l', or 'L' for integer fields
|
|
|
|
* 'z' support added 23/7/1999 S.H.
|
|
|
|
* 'z' changed to 'Z' --davidm 1/25/99
|
|
|
|
* 't' added for ptrdiff_t
|
|
|
|
*
|
|
|
|
* @fmt: the format string
|
|
|
|
* @type of the token returned
|
|
|
|
* @flags: various flags such as +, -, # tokens..
|
|
|
|
* @field_width: overwritten width
|
|
|
|
* @base: base of the number (octal, hex, ...)
|
|
|
|
* @precision: precision of a number
|
|
|
|
* @qualifier: qualifier of a number (long, size_t, ...)
|
|
|
|
*/
|
2010-05-24 23:33:16 +02:00
|
|
|
static noinline_for_stack
|
|
|
|
int format_decode(const char *fmt, struct printf_spec *spec)
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
{
|
|
|
|
const char *start = fmt;
|
|
|
|
|
|
|
|
/* we finished early by reading the field width */
|
2009-03-14 12:08:50 +01:00
|
|
|
if (spec->type == FORMAT_TYPE_WIDTH) {
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
if (spec->field_width < 0) {
|
|
|
|
spec->field_width = -spec->field_width;
|
|
|
|
spec->flags |= LEFT;
|
|
|
|
}
|
|
|
|
spec->type = FORMAT_TYPE_NONE;
|
|
|
|
goto precision;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we finished early by reading the precision */
|
|
|
|
if (spec->type == FORMAT_TYPE_PRECISION) {
|
|
|
|
if (spec->precision < 0)
|
|
|
|
spec->precision = 0;
|
|
|
|
|
|
|
|
spec->type = FORMAT_TYPE_NONE;
|
|
|
|
goto qualifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* By default */
|
|
|
|
spec->type = FORMAT_TYPE_NONE;
|
|
|
|
|
|
|
|
for (; *fmt ; ++fmt) {
|
|
|
|
if (*fmt == '%')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the current non-format string */
|
|
|
|
if (fmt != start || !*fmt)
|
|
|
|
return fmt - start;
|
|
|
|
|
|
|
|
/* Process flags */
|
|
|
|
spec->flags = 0;
|
|
|
|
|
|
|
|
while (1) { /* this also skips first '%' */
|
|
|
|
bool found = true;
|
|
|
|
|
|
|
|
++fmt;
|
|
|
|
|
|
|
|
switch (*fmt) {
|
|
|
|
case '-': spec->flags |= LEFT; break;
|
|
|
|
case '+': spec->flags |= PLUS; break;
|
|
|
|
case ' ': spec->flags |= SPACE; break;
|
|
|
|
case '#': spec->flags |= SPECIAL; break;
|
|
|
|
case '0': spec->flags |= ZEROPAD; break;
|
|
|
|
default: found = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get field width */
|
|
|
|
spec->field_width = -1;
|
|
|
|
|
|
|
|
if (isdigit(*fmt))
|
|
|
|
spec->field_width = skip_atoi(&fmt);
|
|
|
|
else if (*fmt == '*') {
|
|
|
|
/* it's the next argument */
|
2009-03-14 12:08:50 +01:00
|
|
|
spec->type = FORMAT_TYPE_WIDTH;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
return ++fmt - start;
|
|
|
|
}
|
|
|
|
|
|
|
|
precision:
|
|
|
|
/* get the precision */
|
|
|
|
spec->precision = -1;
|
|
|
|
if (*fmt == '.') {
|
|
|
|
++fmt;
|
|
|
|
if (isdigit(*fmt)) {
|
|
|
|
spec->precision = skip_atoi(&fmt);
|
|
|
|
if (spec->precision < 0)
|
|
|
|
spec->precision = 0;
|
|
|
|
} else if (*fmt == '*') {
|
|
|
|
/* it's the next argument */
|
2009-03-14 12:08:50 +01:00
|
|
|
spec->type = FORMAT_TYPE_PRECISION;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
return ++fmt - start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qualifier:
|
|
|
|
/* get the conversion qualifier */
|
|
|
|
spec->qualifier = -1;
|
2009-12-15 03:00:58 +01:00
|
|
|
if (*fmt == 'h' || TOLOWER(*fmt) == 'l' ||
|
|
|
|
TOLOWER(*fmt) == 'z' || *fmt == 't') {
|
2009-03-27 10:07:05 +01:00
|
|
|
spec->qualifier = *fmt++;
|
|
|
|
if (unlikely(spec->qualifier == *fmt)) {
|
|
|
|
if (spec->qualifier == 'l') {
|
|
|
|
spec->qualifier = 'L';
|
|
|
|
++fmt;
|
|
|
|
} else if (spec->qualifier == 'h') {
|
|
|
|
spec->qualifier = 'H';
|
|
|
|
++fmt;
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default base */
|
|
|
|
spec->base = 10;
|
|
|
|
switch (*fmt) {
|
|
|
|
case 'c':
|
|
|
|
spec->type = FORMAT_TYPE_CHAR;
|
|
|
|
return ++fmt - start;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
spec->type = FORMAT_TYPE_STR;
|
|
|
|
return ++fmt - start;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
spec->type = FORMAT_TYPE_PTR;
|
|
|
|
return fmt - start;
|
|
|
|
/* skip alnum */
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
spec->type = FORMAT_TYPE_NRCHARS;
|
|
|
|
return ++fmt - start;
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
spec->type = FORMAT_TYPE_PERCENT_CHAR;
|
|
|
|
return ++fmt - start;
|
|
|
|
|
|
|
|
/* integer number formats - set up the flags and "break" */
|
|
|
|
case 'o':
|
|
|
|
spec->base = 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x':
|
|
|
|
spec->flags |= SMALL;
|
|
|
|
|
|
|
|
case 'X':
|
|
|
|
spec->base = 16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
case 'i':
|
2009-03-09 21:15:04 +01:00
|
|
|
spec->flags |= SIGN;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case 'u':
|
2008-10-29 20:49:58 +01:00
|
|
|
break;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
spec->type = FORMAT_TYPE_INVALID;
|
|
|
|
return fmt - start;
|
2008-07-07 01:43:12 +02:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
|
|
|
if (spec->qualifier == 'L')
|
|
|
|
spec->type = FORMAT_TYPE_LONG_LONG;
|
|
|
|
else if (spec->qualifier == 'l') {
|
2009-03-09 21:15:04 +01:00
|
|
|
if (spec->flags & SIGN)
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec->type = FORMAT_TYPE_LONG;
|
|
|
|
else
|
|
|
|
spec->type = FORMAT_TYPE_ULONG;
|
2009-12-15 03:00:58 +01:00
|
|
|
} else if (TOLOWER(spec->qualifier) == 'z') {
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec->type = FORMAT_TYPE_SIZE_T;
|
|
|
|
} else if (spec->qualifier == 't') {
|
|
|
|
spec->type = FORMAT_TYPE_PTRDIFF;
|
2009-03-27 10:07:05 +01:00
|
|
|
} else if (spec->qualifier == 'H') {
|
|
|
|
if (spec->flags & SIGN)
|
|
|
|
spec->type = FORMAT_TYPE_BYTE;
|
|
|
|
else
|
|
|
|
spec->type = FORMAT_TYPE_UBYTE;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
} else if (spec->qualifier == 'h') {
|
2009-03-09 21:15:04 +01:00
|
|
|
if (spec->flags & SIGN)
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec->type = FORMAT_TYPE_SHORT;
|
|
|
|
else
|
|
|
|
spec->type = FORMAT_TYPE_USHORT;
|
|
|
|
} else {
|
2009-03-09 21:15:04 +01:00
|
|
|
if (spec->flags & SIGN)
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec->type = FORMAT_TYPE_INT;
|
|
|
|
else
|
|
|
|
spec->type = FORMAT_TYPE_UINT;
|
2008-07-07 01:16:15 +02:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
|
|
|
return ++fmt - start;
|
2008-07-07 01:16:15 +02:00
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/**
|
|
|
|
* vsnprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @size: The size of the buffer, including the trailing null space
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @args: Arguments for the format string
|
|
|
|
*
|
2008-10-16 07:02:02 +02:00
|
|
|
* This function follows C99 vsnprintf, but has some extensions:
|
2009-09-17 02:03:06 +02:00
|
|
|
* %pS output the name of a text symbol with offset
|
|
|
|
* %ps output the name of a text symbol without offset
|
vsprintf: introduce %pf format specifier
A printf format specifier which would allow us to print a pure
function name has been suggested by Andrew Morton a couple of
months ago.
The current %pF is very convenient to print a function symbol,
but often we only want to print the name of the function, without
its asm offset.
That's what %pf does in this patch. The lowecase f has been chosen
for its intuitive meaning of a 'weak kind of %pF'.
The support for this new format would be welcome by the tracing code
where the need to print pure function names is often needed. This is
also true for other parts of the kernel:
$ git-grep -E "kallsyms_lookup\(.+?\)"
arch/blackfin/kernel/traps.c: symname = kallsyms_lookup(address, &symsize, &offset, &modname, namebuf);
arch/powerpc/xmon/xmon.c: name = kallsyms_lookup(pc, &size, &offset, NULL, tmpstr);
arch/sh/kernel/cpu/sh5/unwind.c: sym = kallsyms_lookup(pc, NULL, &offset, NULL, namebuf);
arch/x86/kernel/ftrace.c: kallsyms_lookup((unsigned long) syscall, NULL, NULL, NULL, str);
kernel/kprobes.c: sym = kallsyms_lookup((unsigned long)p->addr, NULL,
kernel/lockdep.c: return kallsyms_lookup((unsigned long)key, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup((unsigned long)rec->ops->func, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
kernel/trace/ftrace.c: kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
kernel/trace/ftrace.c: kallsyms_lookup(*ptr, NULL, NULL, NULL, str);
kernel/trace/trace_functions.c: kallsyms_lookup(ip, NULL, NULL, NULL, str);
kernel/trace/trace_output.c: kallsyms_lookup(address, NULL, NULL, NULL, str);
Changes in v2:
- Add the explanation of the %pf role for vsnprintf() and bstr_printf()
- Change the comments by dropping the "asm offset" notion and only
define the %pf against the actual function offset notion.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20090415154817.GC5989@nowhere>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-15 17:48:18 +02:00
|
|
|
* %pF output the name of a function pointer with its offset
|
|
|
|
* %pf output the name of a function pointer without its offset
|
2009-12-18 00:27:12 +01:00
|
|
|
* %pR output the address range in a struct resource with decoded flags
|
|
|
|
* %pr output the address range in a struct resource with raw flags
|
|
|
|
* %pM output a 6-byte MAC address with colons
|
|
|
|
* %pm output a 6-byte MAC address without colons
|
|
|
|
* %pI4 print an IPv4 address without leading zeros
|
|
|
|
* %pi4 print an IPv4 address with leading zeros
|
|
|
|
* %pI6 print an IPv6 address with colons
|
|
|
|
* %pi6 print an IPv6 address without colons
|
|
|
|
* %pI6c print an IPv6 address as specified by
|
2010-01-08 23:43:02 +01:00
|
|
|
* http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-00
|
2009-12-18 00:27:12 +01:00
|
|
|
* %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper
|
|
|
|
* case.
|
2009-09-17 15:27:29 +02:00
|
|
|
* %n is ignored
|
2008-10-16 07:02:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* The return value is the number of characters which would
|
|
|
|
* be generated for the given input, excluding the trailing
|
|
|
|
* '\0', as per ISO C99. If you want to have the exact
|
|
|
|
* number of characters written into @buf as return value
|
2007-02-10 10:45:59 +01:00
|
|
|
* (not including the trailing '\0'), use vscnprintf(). If the
|
2005-04-17 00:20:36 +02:00
|
|
|
* return is greater than or equal to @size, the resulting
|
|
|
|
* string is truncated.
|
|
|
|
*
|
|
|
|
* Call this function if you are already dealing with a va_list.
|
2007-02-10 10:45:59 +01:00
|
|
|
* You probably want snprintf() instead.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
unsigned long long num;
|
2009-12-15 03:00:59 +01:00
|
|
|
char *str, *end;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
struct printf_spec spec = {0};
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-06-25 14:49:17 +02:00
|
|
|
/* Reject out-of-range values early. Large positive sizes are
|
|
|
|
used for unknown buffer sizes. */
|
2009-09-22 02:04:29 +02:00
|
|
|
if (WARN_ON_ONCE((int) size < 0))
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
str = buf;
|
2006-06-25 14:49:17 +02:00
|
|
|
end = buf + size;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-06-25 14:49:17 +02:00
|
|
|
/* Make sure end is always >= buf */
|
|
|
|
if (end < buf) {
|
|
|
|
end = ((void *)-1);
|
|
|
|
size = end - buf;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
while (*fmt) {
|
|
|
|
const char *old_fmt = fmt;
|
2009-12-15 03:00:59 +01:00
|
|
|
int read = format_decode(fmt, &spec);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
fmt += read;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
switch (spec.type) {
|
|
|
|
case FORMAT_TYPE_NONE: {
|
|
|
|
int copy = read;
|
|
|
|
if (str < end) {
|
|
|
|
if (copy > end - str)
|
|
|
|
copy = end - str;
|
|
|
|
memcpy(str, old_fmt, copy);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
str += read;
|
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2009-03-14 12:08:50 +01:00
|
|
|
case FORMAT_TYPE_WIDTH:
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec.field_width = va_arg(args, int);
|
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_PRECISION:
|
|
|
|
spec.precision = va_arg(args, int);
|
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2009-12-15 03:00:59 +01:00
|
|
|
case FORMAT_TYPE_CHAR: {
|
|
|
|
char c;
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
if (!(spec.flags & LEFT)) {
|
|
|
|
while (--spec.field_width > 0) {
|
2006-06-25 14:49:17 +02:00
|
|
|
if (str < end)
|
2005-04-17 00:20:36 +02:00
|
|
|
*str = ' ';
|
|
|
|
++str;
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
c = (unsigned char) va_arg(args, int);
|
|
|
|
if (str < end)
|
|
|
|
*str = c;
|
|
|
|
++str;
|
|
|
|
while (--spec.field_width > 0) {
|
2006-06-25 14:49:17 +02:00
|
|
|
if (str < end)
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
*str = ' ';
|
2005-04-17 00:20:36 +02:00
|
|
|
++str;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
}
|
|
|
|
break;
|
2009-12-15 03:00:59 +01:00
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_STR:
|
|
|
|
str = string(str, end, va_arg(args, char *), spec);
|
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_PTR:
|
|
|
|
str = pointer(fmt+1, str, end, va_arg(args, void *),
|
|
|
|
spec);
|
|
|
|
while (isalnum(*fmt))
|
|
|
|
fmt++;
|
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_PERCENT_CHAR:
|
|
|
|
if (str < end)
|
|
|
|
*str = '%';
|
|
|
|
++str;
|
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_INVALID:
|
|
|
|
if (str < end)
|
|
|
|
*str = '%';
|
|
|
|
++str;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_TYPE_NRCHARS: {
|
2010-03-07 02:10:14 +01:00
|
|
|
u8 qualifier = spec.qualifier;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
|
|
|
if (qualifier == 'l') {
|
|
|
|
long *ip = va_arg(args, long *);
|
|
|
|
*ip = (str - buf);
|
2009-12-15 03:00:58 +01:00
|
|
|
} else if (TOLOWER(qualifier) == 'z') {
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
size_t *ip = va_arg(args, size_t *);
|
|
|
|
*ip = (str - buf);
|
|
|
|
} else {
|
|
|
|
int *ip = va_arg(args, int *);
|
|
|
|
*ip = (str - buf);
|
|
|
|
}
|
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
switch (spec.type) {
|
|
|
|
case FORMAT_TYPE_LONG_LONG:
|
|
|
|
num = va_arg(args, long long);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_ULONG:
|
|
|
|
num = va_arg(args, unsigned long);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_LONG:
|
|
|
|
num = va_arg(args, long);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_SIZE_T:
|
|
|
|
num = va_arg(args, size_t);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_PTRDIFF:
|
|
|
|
num = va_arg(args, ptrdiff_t);
|
|
|
|
break;
|
2009-03-27 10:07:05 +01:00
|
|
|
case FORMAT_TYPE_UBYTE:
|
|
|
|
num = (unsigned char) va_arg(args, int);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_BYTE:
|
|
|
|
num = (signed char) va_arg(args, int);
|
|
|
|
break;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_USHORT:
|
|
|
|
num = (unsigned short) va_arg(args, int);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_SHORT:
|
|
|
|
num = (short) va_arg(args, int);
|
|
|
|
break;
|
2009-03-09 21:15:04 +01:00
|
|
|
case FORMAT_TYPE_INT:
|
|
|
|
num = (int) va_arg(args, int);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
num = va_arg(args, unsigned int);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = number(str, end, num, spec);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
2006-06-25 14:49:17 +02:00
|
|
|
if (size > 0) {
|
|
|
|
if (str < end)
|
|
|
|
*str = '\0';
|
|
|
|
else
|
2006-06-29 02:09:34 +02:00
|
|
|
end[-1] = '\0';
|
2006-06-25 14:49:17 +02:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
2006-06-25 14:49:17 +02:00
|
|
|
/* the trailing null byte doesn't count towards the total */
|
2005-04-17 00:20:36 +02:00
|
|
|
return str-buf;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vsnprintf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vscnprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @size: The size of the buffer, including the trailing null space
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @args: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The return value is the number of characters which have been written into
|
2011-01-13 01:59:49 +01:00
|
|
|
* the @buf not including the trailing '\0'. If @size is == 0 the function
|
2005-04-17 00:20:36 +02:00
|
|
|
* returns 0.
|
|
|
|
*
|
|
|
|
* Call this function if you are already dealing with a va_list.
|
2007-02-10 10:45:59 +01:00
|
|
|
* You probably want scnprintf() instead.
|
2008-10-16 07:02:02 +02:00
|
|
|
*
|
|
|
|
* See the vsnprintf() documentation for format string extensions over C99.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-12-15 03:00:57 +01:00
|
|
|
i = vsnprintf(buf, size, fmt, args);
|
|
|
|
|
2011-01-13 01:59:49 +01:00
|
|
|
if (likely(i < size))
|
|
|
|
return i;
|
|
|
|
if (size != 0)
|
|
|
|
return size - 1;
|
|
|
|
return 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vscnprintf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @size: The size of the buffer, including the trailing null space
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @...: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The return value is the number of characters which would be
|
|
|
|
* generated for the given input, excluding the trailing null,
|
|
|
|
* as per ISO C99. If the return is greater than or equal to
|
|
|
|
* @size, the resulting string is truncated.
|
2008-10-16 07:02:02 +02:00
|
|
|
*
|
|
|
|
* See the vsnprintf() documentation for format string extensions over C99.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2009-12-15 03:00:57 +01:00
|
|
|
int snprintf(char *buf, size_t size, const char *fmt, ...)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2009-12-15 03:00:57 +01:00
|
|
|
i = vsnprintf(buf, size, fmt, args);
|
2005-04-17 00:20:36 +02:00
|
|
|
va_end(args);
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(snprintf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* scnprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @size: The size of the buffer, including the trailing null space
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @...: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The return value is the number of characters written into @buf not including
|
2010-10-26 23:22:50 +02:00
|
|
|
* the trailing '\0'. If @size is == 0 the function returns 0.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
|
2009-12-15 03:00:57 +01:00
|
|
|
int scnprintf(char *buf, size_t size, const char *fmt, ...)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2011-01-13 01:59:49 +01:00
|
|
|
i = vscnprintf(buf, size, fmt, args);
|
2005-04-17 00:20:36 +02:00
|
|
|
va_end(args);
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2011-01-13 01:59:49 +01:00
|
|
|
return i;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(scnprintf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vsprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @args: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The function returns the number of characters written
|
2007-02-10 10:45:59 +01:00
|
|
|
* into @buf. Use vsnprintf() or vscnprintf() in order to avoid
|
2005-04-17 00:20:36 +02:00
|
|
|
* buffer overflows.
|
|
|
|
*
|
|
|
|
* Call this function if you are already dealing with a va_list.
|
2007-02-10 10:45:59 +01:00
|
|
|
* You probably want sprintf() instead.
|
2008-10-16 07:02:02 +02:00
|
|
|
*
|
|
|
|
* See the vsnprintf() documentation for format string extensions over C99.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
int vsprintf(char *buf, const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
return vsnprintf(buf, INT_MAX, fmt, args);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vsprintf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sprintf - Format a string and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @...: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The function returns the number of characters written
|
2007-02-10 10:45:59 +01:00
|
|
|
* into @buf. Use snprintf() or scnprintf() in order to avoid
|
2005-04-17 00:20:36 +02:00
|
|
|
* buffer overflows.
|
2008-10-16 07:02:02 +02:00
|
|
|
*
|
|
|
|
* See the vsnprintf() documentation for format string extensions over C99.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2009-12-15 03:00:57 +01:00
|
|
|
int sprintf(char *buf, const char *fmt, ...)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2009-12-15 03:00:57 +01:00
|
|
|
i = vsnprintf(buf, INT_MAX, fmt, args);
|
2005-04-17 00:20:36 +02:00
|
|
|
va_end(args);
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sprintf);
|
|
|
|
|
2009-03-06 17:21:46 +01:00
|
|
|
#ifdef CONFIG_BINARY_PRINTF
|
|
|
|
/*
|
|
|
|
* bprintf service:
|
|
|
|
* vbin_printf() - VA arguments to binary data
|
|
|
|
* bstr_printf() - Binary data to text string
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vbin_printf - Parse a format string and place args' binary value in a buffer
|
|
|
|
* @bin_buf: The buffer to place args' binary value
|
|
|
|
* @size: The size of the buffer(by words(32bits), not characters)
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @args: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The format follows C99 vsnprintf, except %n is ignored, and its argument
|
|
|
|
* is skiped.
|
|
|
|
*
|
|
|
|
* The return value is the number of words(32bits) which would be generated for
|
|
|
|
* the given input.
|
|
|
|
*
|
|
|
|
* NOTE:
|
|
|
|
* If the return value is greater than @size, the resulting bin_buf is NOT
|
|
|
|
* valid for bstr_printf().
|
|
|
|
*/
|
|
|
|
int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args)
|
|
|
|
{
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
struct printf_spec spec = {0};
|
2009-03-06 17:21:46 +01:00
|
|
|
char *str, *end;
|
|
|
|
|
|
|
|
str = (char *)bin_buf;
|
|
|
|
end = (char *)(bin_buf + size);
|
|
|
|
|
|
|
|
#define save_arg(type) \
|
|
|
|
do { \
|
|
|
|
if (sizeof(type) == 8) { \
|
|
|
|
unsigned long long value; \
|
|
|
|
str = PTR_ALIGN(str, sizeof(u32)); \
|
|
|
|
value = va_arg(args, unsigned long long); \
|
|
|
|
if (str + sizeof(type) <= end) { \
|
|
|
|
*(u32 *)str = *(u32 *)&value; \
|
|
|
|
*(u32 *)(str + 4) = *((u32 *)&value + 1); \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
unsigned long value; \
|
|
|
|
str = PTR_ALIGN(str, sizeof(type)); \
|
|
|
|
value = va_arg(args, int); \
|
|
|
|
if (str + sizeof(type) <= end) \
|
|
|
|
*(typeof(type) *)str = (type)value; \
|
|
|
|
} \
|
|
|
|
str += sizeof(type); \
|
|
|
|
} while (0)
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
while (*fmt) {
|
2009-12-15 03:00:59 +01:00
|
|
|
int read = format_decode(fmt, &spec);
|
2009-03-06 17:21:46 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
fmt += read;
|
2009-03-06 17:21:46 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
switch (spec.type) {
|
|
|
|
case FORMAT_TYPE_NONE:
|
2009-12-15 03:00:59 +01:00
|
|
|
case FORMAT_TYPE_INVALID:
|
|
|
|
case FORMAT_TYPE_PERCENT_CHAR:
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
|
|
|
|
2009-03-14 12:08:50 +01:00
|
|
|
case FORMAT_TYPE_WIDTH:
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_PRECISION:
|
|
|
|
save_arg(int);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_TYPE_CHAR:
|
2009-03-06 17:21:46 +01:00
|
|
|
save_arg(char);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_TYPE_STR: {
|
2009-03-06 17:21:46 +01:00
|
|
|
const char *save_str = va_arg(args, char *);
|
|
|
|
size_t len;
|
2009-12-15 03:00:56 +01:00
|
|
|
|
2009-03-06 17:21:46 +01:00
|
|
|
if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
|
|
|
|
|| (unsigned long)save_str < PAGE_SIZE)
|
2009-12-15 03:00:55 +01:00
|
|
|
save_str = "(null)";
|
2009-12-15 03:00:56 +01:00
|
|
|
len = strlen(save_str) + 1;
|
|
|
|
if (str + len < end)
|
|
|
|
memcpy(str, save_str, len);
|
|
|
|
str += len;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
2009-03-06 17:21:46 +01:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
|
|
|
case FORMAT_TYPE_PTR:
|
2009-03-06 17:21:46 +01:00
|
|
|
save_arg(void *);
|
|
|
|
/* skip all alphanumeric pointer suffixes */
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
while (isalnum(*fmt))
|
2009-03-06 17:21:46 +01:00
|
|
|
fmt++;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_TYPE_NRCHARS: {
|
2009-03-06 17:21:46 +01:00
|
|
|
/* skip %n 's argument */
|
2010-03-07 02:10:14 +01:00
|
|
|
u8 qualifier = spec.qualifier;
|
2009-03-06 17:21:46 +01:00
|
|
|
void *skip_arg;
|
|
|
|
if (qualifier == 'l')
|
|
|
|
skip_arg = va_arg(args, long *);
|
2009-12-15 03:00:58 +01:00
|
|
|
else if (TOLOWER(qualifier) == 'z')
|
2009-03-06 17:21:46 +01:00
|
|
|
skip_arg = va_arg(args, size_t *);
|
|
|
|
else
|
|
|
|
skip_arg = va_arg(args, int *);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
2009-03-06 17:21:46 +01:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
switch (spec.type) {
|
|
|
|
|
|
|
|
case FORMAT_TYPE_LONG_LONG:
|
2009-03-06 17:21:46 +01:00
|
|
|
save_arg(long long);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_ULONG:
|
|
|
|
case FORMAT_TYPE_LONG:
|
2009-03-06 17:21:46 +01:00
|
|
|
save_arg(unsigned long);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_SIZE_T:
|
2009-03-06 17:21:46 +01:00
|
|
|
save_arg(size_t);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_PTRDIFF:
|
2009-03-06 17:21:46 +01:00
|
|
|
save_arg(ptrdiff_t);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
2009-03-27 10:07:05 +01:00
|
|
|
case FORMAT_TYPE_UBYTE:
|
|
|
|
case FORMAT_TYPE_BYTE:
|
|
|
|
save_arg(char);
|
|
|
|
break;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_USHORT:
|
|
|
|
case FORMAT_TYPE_SHORT:
|
2009-03-06 17:21:46 +01:00
|
|
|
save_arg(short);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
|
|
|
default:
|
2009-03-06 17:21:46 +01:00
|
|
|
save_arg(int);
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
}
|
2009-03-06 17:21:46 +01:00
|
|
|
}
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
2009-12-15 03:00:57 +01:00
|
|
|
return (u32 *)(PTR_ALIGN(str, sizeof(u32))) - bin_buf;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
#undef save_arg
|
2009-03-06 17:21:46 +01:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(vbin_printf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bstr_printf - Format a string from binary arguments and place it in a buffer
|
|
|
|
* @buf: The buffer to place the result into
|
|
|
|
* @size: The size of the buffer, including the trailing null space
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @bin_buf: Binary arguments for the format string
|
|
|
|
*
|
|
|
|
* This function like C99 vsnprintf, but the difference is that vsnprintf gets
|
|
|
|
* arguments from stack, and bstr_printf gets arguments from @bin_buf which is
|
|
|
|
* a binary buffer that generated by vbin_printf.
|
|
|
|
*
|
|
|
|
* The format follows C99 vsnprintf, but has some extensions:
|
2009-09-17 15:27:29 +02:00
|
|
|
* see vsnprintf comment for details.
|
2009-03-06 17:21:46 +01:00
|
|
|
*
|
|
|
|
* The return value is the number of characters which would
|
|
|
|
* be generated for the given input, excluding the trailing
|
|
|
|
* '\0', as per ISO C99. If you want to have the exact
|
|
|
|
* number of characters written into @buf as return value
|
|
|
|
* (not including the trailing '\0'), use vscnprintf(). If the
|
|
|
|
* return is greater than or equal to @size, the resulting
|
|
|
|
* string is truncated.
|
|
|
|
*/
|
|
|
|
int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
|
|
|
|
{
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
struct printf_spec spec = {0};
|
2009-12-15 03:00:59 +01:00
|
|
|
char *str, *end;
|
|
|
|
const char *args = (const char *)bin_buf;
|
2009-03-06 17:21:46 +01:00
|
|
|
|
2009-09-22 02:04:29 +02:00
|
|
|
if (WARN_ON_ONCE((int) size < 0))
|
2009-03-06 17:21:46 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
str = buf;
|
|
|
|
end = buf + size;
|
|
|
|
|
|
|
|
#define get_arg(type) \
|
|
|
|
({ \
|
|
|
|
typeof(type) value; \
|
|
|
|
if (sizeof(type) == 8) { \
|
|
|
|
args = PTR_ALIGN(args, sizeof(u32)); \
|
|
|
|
*(u32 *)&value = *(u32 *)args; \
|
|
|
|
*((u32 *)&value + 1) = *(u32 *)(args + 4); \
|
|
|
|
} else { \
|
|
|
|
args = PTR_ALIGN(args, sizeof(type)); \
|
|
|
|
value = *(typeof(type) *)args; \
|
|
|
|
} \
|
|
|
|
args += sizeof(type); \
|
|
|
|
value; \
|
|
|
|
})
|
|
|
|
|
|
|
|
/* Make sure end is always >= buf */
|
|
|
|
if (end < buf) {
|
|
|
|
end = ((void *)-1);
|
|
|
|
size = end - buf;
|
|
|
|
}
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
while (*fmt) {
|
|
|
|
const char *old_fmt = fmt;
|
2009-12-15 03:00:59 +01:00
|
|
|
int read = format_decode(fmt, &spec);
|
2009-03-06 17:21:46 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
fmt += read;
|
2009-03-06 17:21:46 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
switch (spec.type) {
|
|
|
|
case FORMAT_TYPE_NONE: {
|
|
|
|
int copy = read;
|
|
|
|
if (str < end) {
|
|
|
|
if (copy > end - str)
|
|
|
|
copy = end - str;
|
|
|
|
memcpy(str, old_fmt, copy);
|
2009-03-06 17:21:46 +01:00
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
str += read;
|
|
|
|
break;
|
2009-03-06 17:21:46 +01:00
|
|
|
}
|
|
|
|
|
2009-03-14 12:08:50 +01:00
|
|
|
case FORMAT_TYPE_WIDTH:
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
spec.field_width = get_arg(int);
|
|
|
|
break;
|
2009-03-06 17:21:46 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_PRECISION:
|
|
|
|
spec.precision = get_arg(int);
|
|
|
|
break;
|
2009-03-06 17:21:46 +01:00
|
|
|
|
2009-12-15 03:00:59 +01:00
|
|
|
case FORMAT_TYPE_CHAR: {
|
|
|
|
char c;
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
if (!(spec.flags & LEFT)) {
|
|
|
|
while (--spec.field_width > 0) {
|
2009-03-06 17:21:46 +01:00
|
|
|
if (str < end)
|
|
|
|
*str = ' ';
|
|
|
|
++str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c = (unsigned char) get_arg(char);
|
|
|
|
if (str < end)
|
|
|
|
*str = c;
|
|
|
|
++str;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
while (--spec.field_width > 0) {
|
2009-03-06 17:21:46 +01:00
|
|
|
if (str < end)
|
|
|
|
*str = ' ';
|
|
|
|
++str;
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
2009-12-15 03:00:59 +01:00
|
|
|
}
|
2009-03-06 17:21:46 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_STR: {
|
2009-03-06 17:21:46 +01:00
|
|
|
const char *str_arg = args;
|
2009-12-15 03:00:59 +01:00
|
|
|
args += strlen(str_arg) + 1;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
str = string(str, end, (char *)str_arg, spec);
|
|
|
|
break;
|
2009-03-06 17:21:46 +01:00
|
|
|
}
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_PTR:
|
|
|
|
str = pointer(fmt+1, str, end, get_arg(void *), spec);
|
|
|
|
while (isalnum(*fmt))
|
2009-03-06 17:21:46 +01:00
|
|
|
fmt++;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
2009-03-06 17:21:46 +01:00
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_PERCENT_CHAR:
|
|
|
|
case FORMAT_TYPE_INVALID:
|
2009-03-06 17:21:46 +01:00
|
|
|
if (str < end)
|
|
|
|
*str = '%';
|
|
|
|
++str;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FORMAT_TYPE_NRCHARS:
|
|
|
|
/* skip */
|
|
|
|
break;
|
|
|
|
|
2009-12-15 03:00:59 +01:00
|
|
|
default: {
|
|
|
|
unsigned long long num;
|
|
|
|
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
switch (spec.type) {
|
|
|
|
|
|
|
|
case FORMAT_TYPE_LONG_LONG:
|
|
|
|
num = get_arg(long long);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_ULONG:
|
|
|
|
case FORMAT_TYPE_LONG:
|
|
|
|
num = get_arg(unsigned long);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_SIZE_T:
|
|
|
|
num = get_arg(size_t);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_PTRDIFF:
|
|
|
|
num = get_arg(ptrdiff_t);
|
|
|
|
break;
|
2009-03-27 10:07:05 +01:00
|
|
|
case FORMAT_TYPE_UBYTE:
|
|
|
|
num = get_arg(unsigned char);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_BYTE:
|
|
|
|
num = get_arg(signed char);
|
|
|
|
break;
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
case FORMAT_TYPE_USHORT:
|
|
|
|
num = get_arg(unsigned short);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_SHORT:
|
|
|
|
num = get_arg(short);
|
|
|
|
break;
|
|
|
|
case FORMAT_TYPE_UINT:
|
|
|
|
num = get_arg(unsigned int);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
num = get_arg(int);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = number(str, end, num, spec);
|
2009-12-15 03:00:59 +01:00
|
|
|
} /* default: */
|
|
|
|
} /* switch(spec.type) */
|
|
|
|
} /* while(*fmt) */
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
2009-03-06 17:21:46 +01:00
|
|
|
if (size > 0) {
|
|
|
|
if (str < end)
|
|
|
|
*str = '\0';
|
|
|
|
else
|
|
|
|
end[-1] = '\0';
|
|
|
|
}
|
vsprintf: unify the format decoding layer for its 3 users
An new optimization is making its way to ftrace. Its purpose is to
make trace_printk() consuming less memory and be faster.
Written by Lai Jiangshan, the approach is to delay the formatting
job from tracing time to output time.
Currently, a call to trace_printk() will format the whole string and
insert it into the ring buffer. Then you can read it on /debug/tracing/trace
file.
The new implementation stores the address of the format string and
the binary parameters into the ring buffer, making the packet more compact
and faster to insert.
Later, when the user exports the traces, the format string is retrieved
with the binary parameters and the formatting job is eventually done.
The new implementation rewrites a lot of format decoding bits from
vsnprintf() function, making now 3 differents functions to maintain
in their duplicated parts of printf format decoding bits.
Suggested by Ingo Molnar, this patch tries to factorize the most
possible common bits from these functions.
The real common part between them is the format decoding. Although
they do somewhat similar jobs, their way to export or import the parameters
is very different. Thus, only the decoding layer is extracted, unless you see
other parts that could be worth factorized.
Changes in V2:
- Address a suggestion from Linus to group the format_decode() parameters inside
a structure.
Changes in v3:
- Address other cleanups suggested by Ingo and Linus such as passing the
printf_spec struct to the format helpers: pointer()/number()/string()
Note that this struct is passed by copy and not by address. This is to
avoid side effects because these functions often change these values and the
changes shoudn't be persistant when a callee helper returns.
It would be too risky.
- Various cleanups (code alignement, switch/case instead of if/else fountains).
- Fix a bug that printed the first format specifier following a %p
Changes in v4:
- drop unapropriate const qualifier loss while casting fmt to a char *
(thanks to Vegard Nossum for having pointed this out).
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1236356510-8381-6-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-03-06 17:21:50 +01:00
|
|
|
|
2009-03-06 17:21:46 +01:00
|
|
|
#undef get_arg
|
|
|
|
|
|
|
|
/* the trailing null byte doesn't count towards the total */
|
|
|
|
return str - buf;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(bstr_printf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bprintf - Parse a format string and place args' binary value in a buffer
|
|
|
|
* @bin_buf: The buffer to place args' binary value
|
|
|
|
* @size: The size of the buffer(by words(32bits), not characters)
|
|
|
|
* @fmt: The format string to use
|
|
|
|
* @...: Arguments for the format string
|
|
|
|
*
|
|
|
|
* The function returns the number of words(u32) written
|
|
|
|
* into @bin_buf.
|
|
|
|
*/
|
|
|
|
int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
ret = vbin_printf(bin_buf, size, fmt, args);
|
|
|
|
va_end(args);
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2009-03-06 17:21:46 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(bprintf);
|
|
|
|
|
|
|
|
#endif /* CONFIG_BINARY_PRINTF */
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/**
|
|
|
|
* vsscanf - Unformat a buffer into a list of arguments
|
|
|
|
* @buf: input buffer
|
|
|
|
* @fmt: format of buffer
|
|
|
|
* @args: arguments
|
|
|
|
*/
|
2009-12-15 03:00:57 +01:00
|
|
|
int vsscanf(const char *buf, const char *fmt, va_list args)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
const char *str = buf;
|
|
|
|
char *next;
|
|
|
|
char digit;
|
|
|
|
int num = 0;
|
2010-03-07 02:10:14 +01:00
|
|
|
u8 qualifier;
|
|
|
|
u8 base;
|
|
|
|
s16 field_width;
|
2009-12-15 03:00:59 +01:00
|
|
|
bool is_sign;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2009-12-15 03:00:57 +01:00
|
|
|
while (*fmt && *str) {
|
2005-04-17 00:20:36 +02:00
|
|
|
/* skip any white space in format */
|
|
|
|
/* white space in format matchs any amount of
|
|
|
|
* white space, including none, in the input.
|
|
|
|
*/
|
|
|
|
if (isspace(*fmt)) {
|
2009-12-15 03:01:06 +01:00
|
|
|
fmt = skip_spaces(++fmt);
|
|
|
|
str = skip_spaces(str);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* anything that is not a conversion must match exactly */
|
|
|
|
if (*fmt != '%' && *fmt) {
|
|
|
|
if (*fmt++ != *str++)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*fmt)
|
|
|
|
break;
|
|
|
|
++fmt;
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* skip this conversion.
|
|
|
|
* advance both strings to next white space
|
|
|
|
*/
|
|
|
|
if (*fmt == '*') {
|
2009-10-02 00:44:27 +02:00
|
|
|
while (!isspace(*fmt) && *fmt != '%' && *fmt)
|
2005-04-17 00:20:36 +02:00
|
|
|
fmt++;
|
|
|
|
while (!isspace(*str) && *str)
|
|
|
|
str++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get field width */
|
|
|
|
field_width = -1;
|
|
|
|
if (isdigit(*fmt))
|
|
|
|
field_width = skip_atoi(&fmt);
|
|
|
|
|
|
|
|
/* get conversion qualifier */
|
|
|
|
qualifier = -1;
|
2009-12-15 03:00:58 +01:00
|
|
|
if (*fmt == 'h' || TOLOWER(*fmt) == 'l' ||
|
|
|
|
TOLOWER(*fmt) == 'z') {
|
2005-04-17 00:20:36 +02:00
|
|
|
qualifier = *fmt++;
|
|
|
|
if (unlikely(qualifier == *fmt)) {
|
|
|
|
if (qualifier == 'h') {
|
|
|
|
qualifier = 'H';
|
|
|
|
fmt++;
|
|
|
|
} else if (qualifier == 'l') {
|
|
|
|
qualifier = 'L';
|
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*fmt || !*str)
|
|
|
|
break;
|
|
|
|
|
2009-12-15 03:00:59 +01:00
|
|
|
base = 10;
|
|
|
|
is_sign = 0;
|
|
|
|
|
2009-12-15 03:00:57 +01:00
|
|
|
switch (*fmt++) {
|
2005-04-17 00:20:36 +02:00
|
|
|
case 'c':
|
|
|
|
{
|
2009-12-15 03:00:57 +01:00
|
|
|
char *s = (char *)va_arg(args, char*);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (field_width == -1)
|
|
|
|
field_width = 1;
|
|
|
|
do {
|
|
|
|
*s++ = *str++;
|
|
|
|
} while (--field_width > 0 && *str);
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case 's':
|
|
|
|
{
|
2009-12-15 03:00:57 +01:00
|
|
|
char *s = (char *)va_arg(args, char *);
|
|
|
|
if (field_width == -1)
|
2010-05-24 23:33:03 +02:00
|
|
|
field_width = SHRT_MAX;
|
2005-04-17 00:20:36 +02:00
|
|
|
/* first, skip leading white space in buffer */
|
2009-12-15 03:01:06 +01:00
|
|
|
str = skip_spaces(str);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* now copy until next white space */
|
2009-12-15 03:00:57 +01:00
|
|
|
while (*str && !isspace(*str) && field_width--)
|
2005-04-17 00:20:36 +02:00
|
|
|
*s++ = *str++;
|
|
|
|
*s = '\0';
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case 'n':
|
|
|
|
/* return number of characters read so far */
|
|
|
|
{
|
2009-12-15 03:00:57 +01:00
|
|
|
int *i = (int *)va_arg(args, int*);
|
2005-04-17 00:20:36 +02:00
|
|
|
*i = str - buf;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case 'o':
|
|
|
|
base = 8;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
base = 16;
|
|
|
|
break;
|
|
|
|
case 'i':
|
2009-12-15 03:00:57 +01:00
|
|
|
base = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
case 'd':
|
|
|
|
is_sign = 1;
|
|
|
|
case 'u':
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
/* looking for '%' in str */
|
2009-12-15 03:00:57 +01:00
|
|
|
if (*str++ != '%')
|
2005-04-17 00:20:36 +02:00
|
|
|
return num;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
/* invalid format; stop here */
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* have some sort of integer conversion.
|
|
|
|
* first, skip white space in buffer.
|
|
|
|
*/
|
2009-12-15 03:01:06 +01:00
|
|
|
str = skip_spaces(str);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
digit = *str;
|
|
|
|
if (is_sign && digit == '-')
|
|
|
|
digit = *(str + 1);
|
|
|
|
|
|
|
|
if (!digit
|
2009-12-15 03:00:57 +01:00
|
|
|
|| (base == 16 && !isxdigit(digit))
|
|
|
|
|| (base == 10 && !isdigit(digit))
|
|
|
|
|| (base == 8 && (!isdigit(digit) || digit > '7'))
|
|
|
|
|| (base == 0 && !isdigit(digit)))
|
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2009-12-15 03:00:57 +01:00
|
|
|
switch (qualifier) {
|
2005-04-17 00:20:36 +02:00
|
|
|
case 'H': /* that's 'hh' in format */
|
|
|
|
if (is_sign) {
|
2009-12-15 03:00:57 +01:00
|
|
|
signed char *s = (signed char *)va_arg(args, signed char *);
|
|
|
|
*s = (signed char)simple_strtol(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else {
|
2009-12-15 03:00:57 +01:00
|
|
|
unsigned char *s = (unsigned char *)va_arg(args, unsigned char *);
|
|
|
|
*s = (unsigned char)simple_strtoul(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
if (is_sign) {
|
2009-12-15 03:00:57 +01:00
|
|
|
short *s = (short *)va_arg(args, short *);
|
|
|
|
*s = (short)simple_strtol(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else {
|
2009-12-15 03:00:57 +01:00
|
|
|
unsigned short *s = (unsigned short *)va_arg(args, unsigned short *);
|
|
|
|
*s = (unsigned short)simple_strtoul(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
if (is_sign) {
|
2009-12-15 03:00:57 +01:00
|
|
|
long *l = (long *)va_arg(args, long *);
|
|
|
|
*l = simple_strtol(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else {
|
2009-12-15 03:00:57 +01:00
|
|
|
unsigned long *l = (unsigned long *)va_arg(args, unsigned long *);
|
|
|
|
*l = simple_strtoul(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
if (is_sign) {
|
2009-12-15 03:00:57 +01:00
|
|
|
long long *l = (long long *)va_arg(args, long long *);
|
|
|
|
*l = simple_strtoll(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else {
|
2009-12-15 03:00:57 +01:00
|
|
|
unsigned long long *l = (unsigned long long *)va_arg(args, unsigned long long *);
|
|
|
|
*l = simple_strtoull(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'Z':
|
|
|
|
case 'z':
|
|
|
|
{
|
2009-12-15 03:00:57 +01:00
|
|
|
size_t *s = (size_t *)va_arg(args, size_t *);
|
|
|
|
*s = (size_t)simple_strtoul(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (is_sign) {
|
2009-12-15 03:00:57 +01:00
|
|
|
int *i = (int *)va_arg(args, int *);
|
|
|
|
*i = (int)simple_strtol(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else {
|
2009-12-15 03:00:57 +01:00
|
|
|
unsigned int *i = (unsigned int *)va_arg(args, unsigned int*);
|
|
|
|
*i = (unsigned int)simple_strtoul(str, &next, base);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
num++;
|
|
|
|
|
|
|
|
if (!next)
|
|
|
|
break;
|
|
|
|
str = next;
|
|
|
|
}
|
2007-05-08 09:27:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we've come all the way through so either the input string or the
|
|
|
|
* format ended. In the former case, there can be a %n at the current
|
|
|
|
* position in the format that needs to be filled.
|
|
|
|
*/
|
|
|
|
if (*fmt == '%' && *(fmt + 1) == 'n') {
|
|
|
|
int *p = (int *)va_arg(args, int *);
|
|
|
|
*p = str - buf;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vsscanf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sscanf - Unformat a buffer into a list of arguments
|
|
|
|
* @buf: input buffer
|
|
|
|
* @fmt: formatting of buffer
|
|
|
|
* @...: resulting arguments
|
|
|
|
*/
|
2009-12-15 03:00:57 +01:00
|
|
|
int sscanf(const char *buf, const char *fmt, ...)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
2009-12-15 03:00:57 +01:00
|
|
|
va_start(args, fmt);
|
|
|
|
i = vsscanf(buf, fmt, args);
|
2005-04-17 00:20:36 +02:00
|
|
|
va_end(args);
|
2009-12-15 03:00:57 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sscanf);
|