From: Joe Perches <joe@perches.com> Date: 2021-08-26 18:43:13
Several sysfs uses that could use %*ph are upper case hex output.
Add a flag to the short hex formatting routine in vsprintf to support them.
Add documentation too.
Joe Perches (5):
vsprintf/Documentation: Add X to %*ph extension to output upper case hex
scsi: aacraid: Use vsprintf %phNX extension
scsi: hpsa: Use vsprintf %phNX extension
scsi: smartpqi: Use vsprintf %phNX extension
staging: r8188eu: Use vsprintf extension %phCX to format a copy_to_user string
Documentation/core-api/printk-formats.rst | 6 +++
drivers/scsi/aacraid/linit.c | 7 +---
drivers/scsi/hpsa.c | 8 +---
drivers/scsi/smartpqi/smartpqi_init.c | 8 +---
drivers/staging/r8188eu/os_dep/ioctl_linux.c | 9 ++---
lib/vsprintf.c | 42 ++++++++++++--------
6 files changed, 37 insertions(+), 43 deletions(-)
--
2.30.0
From: Joe Perches <joe@perches.com> Date: 2021-08-26 18:43:15
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(-)
@@ -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
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Date: 2021-08-27 07:48:47
On Thu, Aug 26, 2021 at 11:43:01AM -0700, Joe Perches wrote:
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.
...
+ 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
Why not using %*pH...?
...
+ char locase = 0x20; /* ASCII OR'd for lower case see: number() */
If you use h vs H, you may derive this from (fmt[...] & SMALL).
--
With Best Regards,
Andy Shevchenko
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Date: 2021-08-27 07:52:10
On Thu, Aug 26, 2021 at 11:43:00AM -0700, Joe Perches wrote:
Several sysfs uses that could use %*ph are upper case hex output.
Add a flag to the short hex formatting routine in vsprintf to support them.
Add documentation too.
Thanks!
Unfortunately I have got only first patch and this cover letter. Can you,
please, Cc entire series?
--
With Best Regards,
Andy Shevchenko
From: Joe Perches <joe@perches.com> Date: 2021-08-27 08:08:21
On Fri, 2021-08-27 at 10:48 +0300, Andy Shevchenko wrote:
On Thu, Aug 26, 2021 at 11:43:01AM -0700, Joe Perches wrote:
quoted
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.
...
quoted
+ 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
Why not using %*pH...?
I find X more intelligible.
quoted
+ char locase = 0x20; /* ASCII OR'd for lower case see: number() */
If you use h vs H, you may derive this from (fmt[...] & SMALL).
It's not necessary to use any more of the rather limited vsprintf
extension namespace.
From: Joe Perches <joe@perches.com> Date: 2021-08-27 08:10:49
On Fri, 2021-08-27 at 10:51 +0300, Andy Shevchenko wrote:
On Thu, Aug 26, 2021 at 11:43:00AM -0700, Joe Perches wrote:
quoted
Several sysfs uses that could use %*ph are upper case hex output.
Add a flag to the short hex formatting routine in vsprintf to support them.
Add documentation too.
Thanks!
Unfortunately I have got only first patch and this cover letter. Can you,
please, Cc entire series?
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Date: 2021-08-27 08:46:33
On Fri, Aug 27, 2021 at 01:10:41AM -0700, Joe Perches wrote:
On Fri, 2021-08-27 at 10:51 +0300, Andy Shevchenko wrote:
quoted
On Thu, Aug 26, 2021 at 11:43:00AM -0700, Joe Perches wrote:
quoted
Several sysfs uses that could use %*ph are upper case hex output.
Add a flag to the short hex formatting routine in vsprintf to support them.
Add documentation too.
Thanks!
Unfortunately I have got only first patch and this cover letter. Can you,
please, Cc entire series?
Thanks. So, you won't me to review them in a regular way :-)
TBH, I think those examples may pretty much be safe to use small
letters always.
--
With Best Regards,
Andy Shevchenko
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Date: 2021-08-27 08:49:17
On Fri, Aug 27, 2021 at 01:08:10AM -0700, Joe Perches wrote:
On Fri, 2021-08-27 at 10:48 +0300, Andy Shevchenko wrote:
quoted
On Thu, Aug 26, 2021 at 11:43:01AM -0700, Joe Perches wrote:
quoted
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.
...
quoted
+ 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
Why not using %*pH...?
I find X more intelligible.
quoted
quoted
+ char locase = 0x20; /* ASCII OR'd for lower case see: number() */
If you use h vs H, you may derive this from (fmt[...] & SMALL).
It's not necessary to use any more of the rather limited vsprintf
extension namespace.
I understand your concern, but %*ph is quite widely used (I guess top 1 or 2
among all %p extensions), its performance degradation with your code may affect
a lot of other users and hence a kernel as a whole.
So, that's why my proposal stays.
Of course you may provide a benchmark (btw, where are the test cases for this?)
for yours and mine variant and we will see if it makes sense to optimize.
--
With Best Regards,
Andy Shevchenko
On Fri, Aug 27, 2021 at 11:46:20AM +0300, Andy Shevchenko wrote:
On Fri, Aug 27, 2021 at 01:10:41AM -0700, Joe Perches wrote:
quoted
On Fri, 2021-08-27 at 10:51 +0300, Andy Shevchenko wrote:
quoted
On Thu, Aug 26, 2021 at 11:43:00AM -0700, Joe Perches wrote:
quoted
Several sysfs uses that could use %*ph are upper case hex output.
Add a flag to the short hex formatting routine in vsprintf to support them.
Add documentation too.
Thanks!
Unfortunately I have got only first patch and this cover letter. Can you,
please, Cc entire series?
From: Petr Mladek <pmladek@suse.com> Date: 2021-08-27 10:49:19
On Fri 2021-08-27 11:49:07, Andy Shevchenko wrote:
On Fri, Aug 27, 2021 at 01:08:10AM -0700, Joe Perches wrote:
quoted
On Fri, 2021-08-27 at 10:48 +0300, Andy Shevchenko wrote:
quoted
On Thu, Aug 26, 2021 at 11:43:01AM -0700, Joe Perches wrote:
quoted
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.
...
quoted
+ 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
Why not using %*pH...?
I though about this as well.
quoted
I find X more intelligible.
I would slightly prefer %pH. I always have problems to parse long
sequences of modifiers. So, the shorter format the better.
Of course, it means that 'H' won't be usable for another purpose.
But it will happen one day anyway. Well, this is why I do not
have strong opinion.
I am more and more convinced that we will need another approach.
Mathew Wilcox has had an idea to add support for custom callbacks
that would be able to format the string, something like:
vsprintf("Date: %pX(%p)\n", format_date, time_stamp);
I think that it might even be possible to do something like:
vsprintf("Date: %pX\n", format_date(time));
, where the format_date() would be a macro that would create
a struct at stack a pass it as a pointer:
#define format_date(time) \
({ \
struct vsprintf_callback c = { \
.func = vsprintf_format_date, \
.arg1 = time, \
} \
\
&c; \
})
and vsprintf would internally do something like:
char *custom_format(char *buf, char *end, vsprintf_callback *c,
struct printf_spec spec, const char *fmt)
{
return c->func(buf, end, c->arg1, spec);
}
It would allow to replace all the magic %pXYZ modifiers with
self-explanatory callbacks. While still keeping it easy to use.
Best Regards,
Petr
From: Joe Perches <joe@perches.com> Date: 2021-08-27 16:09:45
On Fri, 2021-08-27 at 12:23 +0200, Greg KH wrote:
On Fri, Aug 27, 2021 at 11:46:20AM +0300, Andy Shevchenko wrote:
quoted
On Fri, Aug 27, 2021 at 01:10:41AM -0700, Joe Perches wrote:
quoted
On Fri, 2021-08-27 at 10:51 +0300, Andy Shevchenko wrote:
quoted
On Thu, Aug 26, 2021 at 11:43:00AM -0700, Joe Perches wrote:
quoted
Several sysfs uses that could use %*ph are upper case hex output.
Add a flag to the short hex formatting routine in vsprintf to support them.
Add documentation too.
Thanks!
Unfortunately I have got only first patch and this cover letter. Can you,
please, Cc entire series?
From: Joe Perches <joe@perches.com> Date: 2021-08-28 02:49:33
On Fri, 2021-08-27 at 11:49 +0300, Andy Shevchenko wrote:
On Fri, Aug 27, 2021 at 01:08:10AM -0700, Joe Perches wrote:
quoted
On Fri, 2021-08-27 at 10:48 +0300, Andy Shevchenko wrote:
quoted
On Thu, Aug 26, 2021 at 11:43:01AM -0700, Joe Perches wrote:
quoted
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.
...
quoted
+ 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
Why not using %*pH...?
I find X more intelligible.
quoted
quoted
+ char locase = 0x20; /* ASCII OR'd for lower case see: number() */
If you use h vs H, you may derive this from (fmt[...] & SMALL).
It's not necessary to use any more of the rather limited vsprintf
extension namespace.
I understand your concern, but %*ph is quite widely used (I guess top 1 or 2
among all %p extensions),
Cumulatively 3rd after %pM and %pOF
its performance degradation with your code may affect
a lot of other users and hence a kernel as a whole.
So, that's why my proposal stays.
Knock yourself out.
Of course you may provide a benchmark (btw, where are the test cases for this?)
You are welcome to provide both test cases and benchmarks.
I find the whole thing rather dull.
for yours and mine variant and we will see if it makes sense to optimize.
It doesn't. Anyone thinking there is a required printf/vsprintf
optimization in the kernel is decidedly barking up the wrong tree.