public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Zhaolei <zhaolei@cn.fujitsu.com>
Cc: Ingo Molnar <mingo@elte.hu>,
	torvalds@linux-foundation.org,
	Steven Rostedt <rostedt@goodmis.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] Add support of hh length modifier for printk
Date: Fri, 27 Mar 2009 17:34:35 +0800	[thread overview]
Message-ID: <49CC9DAB.9050807@cn.fujitsu.com> (raw)
In-Reply-To: <49CC9739.30107@cn.fujitsu.com>

Zhaolei wrote:
> hh is used as length modifier for signed char or unsigned char.
> It is supported by glibc, we add kernel support now.
> 
> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
> ---
>  lib/vsprintf.c |   37 ++++++++++++++++++++++++++++++++-----
>  1 files changed, 32 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index be3001f..908dd41 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -408,6 +408,8 @@ enum format_type {
>  	FORMAT_TYPE_LONG_LONG,
>  	FORMAT_TYPE_ULONG,
>  	FORMAT_TYPE_LONG,
> +	FORMAT_TYPE_UBYTE,
> +	FORMAT_TYPE_BYTE,
>  	FORMAT_TYPE_USHORT,
>  	FORMAT_TYPE_SHORT,
>  	FORMAT_TYPE_UINT,
> @@ -853,11 +855,15 @@ qualifier:
>  	spec->qualifier = -1;
>  	if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' ||
>  	    *fmt == 'Z' || *fmt == 'z' || *fmt == 't') {
> -		spec->qualifier = *fmt;
> -		++fmt;
> -		if (spec->qualifier == 'l' && *fmt == 'l') {
> -			spec->qualifier = 'L';
> -			++fmt;
> +		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;
> +			}
>  		}
>  	}
>  
> @@ -919,6 +925,11 @@ qualifier:
>  		spec->type = FORMAT_TYPE_SIZE_T;
>  	} else if (spec->qualifier == 't') {
>  		spec->type = FORMAT_TYPE_PTRDIFF;
> +	} else if (spec->qualifier == 'H') {
> +		if (spec->flags & SIGN)
> +			spec->type = FORMAT_TYPE_BYTE;
> +		else
> +			spec->type = FORMAT_TYPE_UBYTE;
>  	} else if (spec->qualifier == 'h') {
>  		if (spec->flags & SIGN)
>  			spec->type = FORMAT_TYPE_SHORT;
> @@ -1094,6 +1105,12 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
>  			case FORMAT_TYPE_PTRDIFF:
>  				num = va_arg(args, ptrdiff_t);
>  				break;
> +			case FORMAT_TYPE_UBYTE:
> +				num = (unsigned char) va_arg(args, int);
> +				break;
> +			case FORMAT_TYPE_BYTE:
> +				num = (signed char) va_arg(args, int);
> +				break;
>  			case FORMAT_TYPE_USHORT:
>  				num = (unsigned short) va_arg(args, int);
>  				break;
> @@ -1372,6 +1389,10 @@ do {									\
>  			case FORMAT_TYPE_PTRDIFF:
>  				save_arg(ptrdiff_t);
>  				break;
> +			case FORMAT_TYPE_UBYTE:
> +			case FORMAT_TYPE_BYTE:
> +				save_arg(char);
> +				break;
>  			case FORMAT_TYPE_USHORT:
>  			case FORMAT_TYPE_SHORT:
>  				save_arg(short);
> @@ -1554,6 +1575,12 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
>  			case FORMAT_TYPE_PTRDIFF:
>  				num = get_arg(ptrdiff_t);
>  				break;
> +			case FORMAT_TYPE_UBYTE:
> +				num = get_arg(unsigned char);
> +				break;
> +			case FORMAT_TYPE_BYTE:
> +				num = get_arg(signed char);
> +				break;
>  			case FORMAT_TYPE_USHORT:
>  				num = get_arg(unsigned short);
>  				break;

It's fine. hh modifier is supported by ISO C99.
And for vbin_printf(), it will consume less memory.

Review-by: Lai Jiangshan <laijs@cn.fujitsu.com>


  parent reply	other threads:[~2009-03-27  9:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-27  9:07 [PATCH 1/2] Add support of hh length modifier for printk Zhaolei
2009-03-27  9:09 ` [PATCH 2/2] Fix wrong format string iter " Zhaolei
2009-03-27  9:34   ` Lai Jiangshan
2009-03-27 12:53   ` Frederic Weisbecker
2009-04-08 15:06   ` [tip:core/urgent] printk: fix " Zhaolei
2009-03-27  9:34 ` Lai Jiangshan [this message]
2009-03-27 12:44 ` [PATCH 1/2] Add support of hh length modifier " Frederic Weisbecker
2009-04-08 15:25 ` [tip:core/printk] printk: add " Zhaolei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49CC9DAB.9050807@cn.fujitsu.com \
    --to=laijs@cn.fujitsu.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    --cc=zhaolei@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox