From: Joe Perches <joe@perches.com>
To: Petr Mladek <pmladek@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Jonathan Corbet <corbet@lwn.net>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/5] vsprintf/Documentation: Add X to %*ph extension to output upper case hex
Date: Thu, 26 Aug 2021 11:43:01 -0700 [thread overview]
Message-ID: <bc33e306a9064dfbf1180a35f9bfa587c6502eca.1630003183.git.joe@perches.com> (raw)
In-Reply-To: <cover.1630003183.git.joe@perches.com>
A few sysfs output uses of hex arrays are uppercase and are nominally ABI.
Add a mechanism to the existing vsprintf %*ph hex output extension to
support upper case hex output.
Signed-off-by: Joe Perches <joe@perches.com>
---
Documentation/core-api/printk-formats.rst | 6 ++++
lib/vsprintf.c | 42 ++++++++++++++---------
2 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index e08bbe9b0cbf3..ca750274992e6 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -284,10 +284,16 @@ Raw buffer as a hex string
::
+ The preferred output is lowercase
%*ph 00 01 02 ... 3f
%*phC 00:01:02: ... :3f
%*phD 00-01-02- ... -3f
%*phN 000102 ... 3f
+ Formats with X are uppercase, used for backwards compatibility
+ %*phX 00 01 02 ... 3F
+ %*phCX 00:01:02: ... :3F
+ %*phDX 00-01-02- ... -3F
+ %*phNX 000102 ... 3F
For printing small buffers (up to 64 bytes long) as a hex string with a
certain separator. For larger buffers consider using
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 134216c45980e..5c22a07bbe3a7 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1147,7 +1147,10 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
{
int i, len = 1; /* if we pass '%ph[CDN]', field width remains
negative value, fallback to the default */
- char separator;
+ char separator = ' ';
+ int count = 1;
+ bool found = true;
+ char locase = 0x20; /* ASCII OR'd for lower case see: number() */
if (spec.field_width == 0)
/* nothing to print */
@@ -1156,30 +1159,35 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
if (check_pointer(&buf, end, addr, spec))
return buf;
- switch (fmt[1]) {
- case 'C':
- separator = ':';
- break;
- case 'D':
- separator = '-';
- break;
- case 'N':
- separator = 0;
- break;
- default:
- separator = ' ';
- break;
- }
+ do {
+ switch (fmt[count++]) {
+ case 'C':
+ separator = ':';
+ break;
+ case 'D':
+ separator = '-';
+ break;
+ case 'N':
+ separator = 0;
+ break;
+ case 'X':
+ locase = 0;
+ break;
+ default:
+ found = false;
+ break;
+ }
+ } while (found);
if (spec.field_width > 0)
len = min_t(int, spec.field_width, 64);
for (i = 0; i < len; ++i) {
if (buf < end)
- *buf = hex_asc_hi(addr[i]);
+ *buf = hex_asc_upper_hi(addr[i]) | locase;
++buf;
if (buf < end)
- *buf = hex_asc_lo(addr[i]);
+ *buf = hex_asc_upper_lo(addr[i]) | locase;
++buf;
if (separator && i != len - 1) {
--
2.30.0
next prev parent reply other threads:[~2021-08-26 18:43 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-26 18:43 [PATCH 0/5] vsprintf and uses: Add upper case output to %*ph extension Joe Perches
2021-08-26 18:43 ` Joe Perches [this message]
2021-08-27 7:48 ` [PATCH 1/5] vsprintf/Documentation: Add X to %*ph extension to output upper case hex Andy Shevchenko
2021-08-27 8:08 ` Joe Perches
2021-08-27 8:49 ` Andy Shevchenko
2021-08-27 10:49 ` Petr Mladek
2021-08-28 2:49 ` Joe Perches
2021-08-26 18:43 ` [PATCH 2/5] scsi: aacraid: Use vsprintf %phNX extension Joe Perches
2021-08-26 18:43 ` [PATCH 3/5] scsi: hpsa: " Joe Perches
2021-08-26 18:43 ` [PATCH 4/5] scsi: smartpqi: " Joe Perches
2021-08-26 18:43 ` [PATCH 5/5] staging: r8188eu: Use vsprintf extension %phCX to format a copy_to_user string Joe Perches
2021-08-27 8:42 ` Greg Kroah-Hartman
2021-08-27 15:23 ` Joe Perches
2021-08-27 15:27 ` Greg Kroah-Hartman
2021-08-27 15:52 ` Joe Perches
2021-08-27 7:51 ` [PATCH 0/5] vsprintf and uses: Add upper case output to %*ph extension Andy Shevchenko
2021-08-27 8:10 ` Joe Perches
2021-08-27 8:46 ` Andy Shevchenko
2021-08-27 10:23 ` Greg KH
2021-08-27 16:09 ` Joe Perches
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=bc33e306a9064dfbf1180a35f9bfa587c6502eca.1630003183.git.joe@perches.com \
--to=joe@perches.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
/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;
as well as URLs for NNTP newsgroup(s).