Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1298726

Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to xnumber()

From Joe Perches <joe@perches.com>
Newsgroups linux.kernel
Subject Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to xnumber()
Date 2015-12-28 19:30 +0100
Message-ID <qKKIq-5Qe-7@gated-at.bofh.it> (permalink)
References <qKKyK-5LQ-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, 2015-12-28 at 20:18 +0200, Andy Shevchenko wrote:
> xnumber() is a special helper to print a fixed size type in a hex format with
> '0x' prefix with padding and reduced size. In the module we have already
> several copies of such code. Consolidate them under xnumber() helper.
> 
> There are couple of differences though.
> 
> It seems nobody cared about the output in case of CONFIG_KALLSYMS=n when
> printing symbol address because the asked width is not enough to care either
> prefix or last byte. Fixed here.
> 
> The %pNF specifier used to be allowed with a specific field width, though there
> is neither any user of it nor mention in the documentation.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  lib/vsprintf.c | 43 +++++++++++++++----------------------------
>  1 file changed, 15 insertions(+), 28 deletions(-)
> 
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index dcf5646..e971549 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -514,6 +514,16 @@ char *number(char *buf, char *end, unsigned long long num,
>  	return buf;
>  }
>  
> +static noinline_for_stack
> +char *xnumber(char *buf, char *end, unsigned long long value, unsigned int type,
> +	      struct printf_spec spec)

xnumber isn't a great name.

unsigned int type should probably be size_t size

> +{
> +	spec.field_width = 2 + 2 * type;
> +	spec.flags |= SPECIAL | SMALL | ZEROPAD;
> +	spec.base = 16;
> +	return number(buf, end, value, spec);
> +}
> +
>  static void move_right(char *buf, char *end, unsigned len, unsigned spaces)
>  {
>  	size_t size;
> @@ -649,11 +659,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
>  
>  	return string(buf, end, sym, spec);
>  #else
> -	spec.field_width = 2 * sizeof(void *);
> -	spec.flags |= SPECIAL | SMALL | ZEROPAD;
> -	spec.base = 16;
> -
> -	return number(buf, end, value, spec);
> +	return xnumber(buf, end, value, sizeof(void *), spec);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v1 1/1] lib/vsprintf: refactor duplicate code to xnumber() Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-12-28 19:20 +0100
  Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to  xnumber() Joe Perches <joe@perches.com> - 2015-12-28 19:30 +0100
    Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to xnumber() Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-12-28 20:10 +0100
      Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to  xnumber() Joe Perches <joe@perches.com> - 2015-12-29 01:20 +0100
    Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to xnumber() Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-28 22:50 +0100
      Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to xnumber() Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-12-28 23:30 +0100
        Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to xnumber() Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-29 00:10 +0100
        Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to  xnumber() Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-12-29 16:10 +0100
      Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to xnumber() Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-12-28 23:30 +0100
      Re: [PATCH v1 1/1] lib/vsprintf: refactor duplicate code to xnumber() Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-28 23:30 +0100

csiph-web