From: Tim Deegan Subject: Re: [PATCH for-4.5 1/2] xen/vsprintf: Introduce %*ph extended format specifier for hex buffers Date: Fri, 26 Sep 2014 13:49:25 +0200 Message-ID: <20140926114925.GA35563@deinos.phlegethon.org> References: <1411726207-2689-1-git-send-email-andrew.cooper3@citrix.com> <1411726207-2689-2-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1411726207-2689-2-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: Keir Fraser , Jan Beulich , Xen-devel List-Id: xen-devel@lists.xenproject.org At 11:10 +0100 on 26 Sep (1411726206), Andrew Cooper wrote: > This behaves in the same way as Linux. The 64 byte limit is arbitrary but > long enough for practical purposes. > > Signed-off-by: Andrew Cooper > CC: Keir Fraser > CC: Jan Beulich > CC: Tim Deegan > CC: Konrad Rzeszutek Wilk > --- > docs/misc/printk-formats.txt | 6 ++++++ > xen/common/vsprintf.c | 25 +++++++++++++++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/docs/misc/printk-formats.txt b/docs/misc/printk-formats.txt > index 3b4323a..81b3651 100644 > --- a/docs/misc/printk-formats.txt > +++ b/docs/misc/printk-formats.txt > @@ -18,3 +18,9 @@ Symbol/Function pointers: > > %pv Domain and vCPU ID from a 'struct vcpu *' (printed as > "dv") > + > + > +Raw buffer as hex string: > + > + %*ph Up to 64 characters, printed as "00 01 02 ... ff". Buffer length > + expected via the field_width paramter. i.e. printk("%*ph", 8, buffer); > diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c > index e68886a..4a7da1c 100644 > --- a/xen/common/vsprintf.c > +++ b/xen/common/vsprintf.c > @@ -272,6 +272,31 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, > /* Custom %p suffixes. See XEN_ROOT/docs/misc/printk-formats.txt */ > switch ( fmt[1] ) > { > + case 'h': /* Raw buffer as hex string. */ > + { > + /* > + * User expected to provide an explicit count using %*. Bound between > + * 0 and 64 bytes, defaulting to 0. > + */ > + unsigned i, nr_bytes = > + ((field_width < 1) || (field_width > 64)) ? 0 : field_width; > + const uint8_t *hex_buffer = arg; > + > + /* Consumed 'h' from the format string. */ > + ++*fmt_ptr; > + > + for ( i = 0; i < nr_bytes; ++i ) > + { > + /* Each byte: 2 chars, 0-padded, base 16, no hex prefix. */ > + str = number(str, end, hex_buffer[i], 16, 2, -1, ZEROPAD); > + if ( str < end ) (str < end && i + 1 < nr_bytes) to avoid a trailing space? Otherwise, Reviewed-by: Tim Deegan Tim.