RFC: script to convert vsprintf uses of %pf to %ps and %pF to %pS
Subsystems (3)
commit 04b8eb7a4ccd ("symbol lookup: introduce dereference_symbol_descriptor()}"
deprecated vsprintf extension %pf and %pF.
There are approximately these total uses of the symbolic lookup vsprintf extensions %p[SsFf]:
$ git grep '".*[^%]%p[SsFf]' | \
grep -oh '%p[SsFf]' | sort | uniq -c | sort -rn
231 %pS
65 %ps
60 %pf
47 %pFwhich is about a 3:1 ratio favoring %pS
so a script to convert all the %pf uses to %ps and %pF uses to %pS could be useful.
There are a few files that appear should not be converted.
$ git grep -w --name-only -i '%pf'| \ grep -vP '^(?:Documentation|tools|include/linux/freezer.h)'| \ xargs sed -i -e 's/%pf/%ps/g' -e 's/%pF/%pS/g'
If that script above is run, it leaves the following patch to be applied:
--- Documentation/core-api/printk-formats.rst | 10 ---------- lib/vsprintf.c | 12 ++---------- 2 files changed, 2 insertions(+), 20 deletions(-)
Documentation/core-api/printk-formats.rst +0 -10
@@ -70,8 +70,6 @@ Symbols/Function Pointers %pS versatile_init+0x0/0x110 %ps versatile_init - %pF versatile_init+0x0/0x110 - %pf versatile_init %pSR versatile_init+0x9/0x110 (with __builtin_extract_return_addr() translation) %pB prev_fn_of_versatile_init+0x88/0x88
@@ -81,14 +79,6 @@ The ``S`` and ``s`` specifiers are used for printing a pointer in symbolic format. They result in the symbol name with (S) or without (s) offsets. If KALLSYMS are disabled then the symbol address is printed instead. -Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``) -and thus deprecated. We have ``F`` and ``f`` because on ia64, ppc64 and -parisc64 function pointers are indirect and, in fact, are function -descriptors, which require additional dereferencing before we can lookup -the symbol. As of now, ``S`` and ``s`` perform dereferencing on those -platforms (when needed), so ``F`` and ``f`` exist for compatibility -reasons only. - The ``B`` specifier results in the symbol name with offsets and should be used when printing stack backtraces. The specifier takes into consideration the effect of compiler optimisations which may occur
lib/vsprintf.c +2 -10
@@ -795,7 +795,7 @@ char *symbol_string(char *buf, char *end, void *ptr,#ifdef CONFIG_KALLSYMS if (*fmt =='B' )sprint_backtrace (sym, value); -else if (*fmt !='f' && *fmt !='s' ) +else if (*fmt !='s' )sprint_symbol (sym, value);else sprint_symbol_no_offset (sym, value);
@@ -1756,9 +1756,7 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,* * - 'S' For symbolic direct pointers (or function descriptors) with offset * - 's' For symbolic direct pointers (or function descriptors) without offset -* - 'F' Same as 'S' -* - 'f' Same as 's' -* - '[FfSs]R' as above with __builtin_extract_return_addr() translation +* - '[Ss]R' as above with __builtin_extract_return_addr() translation * - 'B' For backtraced symbolic direct pointers with offset * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref] * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
@@ -1872,8 +1870,6 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, }switch (*fmt) { -case 'F' : -case 'f' :case 'S' :case 's' : ptr =dereference_symbol_descriptor (ptr);
@@ -2603,8 +2599,6 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args)/* Dereference of functions is still OK */ case 'S' :case 's' : -case 'F' : -case 'f' :case 'x' :case 'K' : save_arg(void *);
@@ -2779,8 +2773,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)switch (*fmt) {case 'S' :case 's' : -case 'F' : -case 'f' :case 'x' :case 'K' : process = true;
---
Hi,
Cc-ing Petr and Steven
Quoted 7 lines · Joe Perches
commit
04b8eb7a4ccd("symbol lookup: introducedereference_symbol_descriptor()}"deprecated vsprintf extension %pf and %pF.
There are approximately these total uses of the symbolic lookup vsprintf extensions %p[SsFf]:
Quoted 6 lines
$ git grep '".*[^%]%p[SsFf]' | \
grep -oh '%p[SsFf]' | sort | uniq -c | sort -rn
231 %pS
65 %ps
60 %pf
47 %pFI didn't bother to remove "pf/pF" because I didn't want to count on:
a) everyone running checkpatch.pl
b) everyone testing all printk-s they added
I guess pf/pF still can sneak in.
But I don't have a really strong opinion on this. If general consensus is that we shall remove deprecated specifiers, then I'm fine.
Quoted 5 lines
which is about a 3:1 ratio favoring %pS
so a script to convert all the %pf uses to %ps and %pF uses to %pS could be useful.
Quoted 8 lines
There are a few files that appear should not be converted.
$ git grep -w --name-only -i '%pf'| \ grep -vP '^(?:Documentation|tools|include/linux/freezer.h)'| \ xargs sed -i -e 's/%pf/%ps/g' -e 's/%pF/%pS/g'If that script above is run, it leaves the following patch to be applied:
After running this script I still have a bunch of leftovers:
//
// these two are probably not really relevant, but still - %pF/%pf //tools/lib/traceevent/event-parse.c: if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0)tools/lib/traceevent/event-parse.c: if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0)
arch/um/kernel/sysrq.c: pr_info(" [<%08lx>] %s%pF\n", address, reliable ? "" : "? ",
arch/x86/xen/multicalls.c: printk(KERN_DEBUG " call %2d/%d: op=%lu arg=[%lx] result=%ld\t%pF\n",
kernel/async.c: pr_debug("calling %lli_%pF @ %i\n",
kernel/async.c: pr_debug("initcall %lli_%pF returned 0 after %lld usecs\n",-ss
And I forgot to actually Cc Petr and Steven...
Top-posting.
-------
Hi,
Cc-ing Petr and Steven
Quoted 7 lines · Joe Perches
commit
04b8eb7a4ccd("symbol lookup: introducedereference_symbol_descriptor()}"deprecated vsprintf extension %pf and %pF.
There are approximately these total uses of the symbolic lookup vsprintf extensions %p[SsFf]:
Quoted 6 lines
$ git grep '".*[^%]%p[SsFf]' | \
grep -oh '%p[SsFf]' | sort | uniq -c | sort -rn
231 %pS
65 %ps
60 %pf
47 %pFI didn't bother to remove "pf/pF" because I didn't want to count on:
a) everyone running checkpatch.pl
b) everyone testing all printk-s they added
I guess pf/pF still can sneak in.
But I don't have a really strong opinion on this. If general consensus is that we shall remove deprecated specifiers, then I'm fine.
Quoted 5 lines
which is about a 3:1 ratio favoring %pS
so a script to convert all the %pf uses to %ps and %pF uses to %pS could be useful.
Quoted 8 lines
There are a few files that appear should not be converted.
$ git grep -w --name-only -i '%pf'| \ grep -vP '^(?:Documentation|tools|include/linux/freezer.h)'| \ xargs sed -i -e 's/%pf/%ps/g' -e 's/%pF/%pS/g'If that script above is run, it leaves the following patch to be applied:
After running this script I still have a bunch of leftovers:
//
// these two are probably not really relevant, but still - %pF/%pf //tools/lib/traceevent/event-parse.c: if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0)tools/lib/traceevent/event-parse.c: if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0)
arch/um/kernel/sysrq.c: pr_info(" [<%08lx>] %s%pF\n", address, reliable ? "" : "? ",
arch/x86/xen/multicalls.c: printk(KERN_DEBUG " call %2d/%d: op=%lu arg=[%lx] result=%ld\t%pF\n",
kernel/async.c: pr_debug("calling %lli_%pF @ %i\n",
kernel/async.c: pr_debug("initcall %lli_%pF returned 0 after %lld usecs\n",-ss
Quoted 10 lines · Sergey Senozhatsky
Quoted 9 lines
There are approximately these total uses of the symbolic lookup vsprintf extensions %p[SsFf]:
$ git grep '".*[^%]%p[SsFf]' | \ grep -oh '%p[SsFf]' | sort | uniq -c | sort -rn 231 %pS 65 %ps 60 %pf 47 %pF
Quoted 5 lines
I didn't bother to remove "pf/pF" because I didn't want to count on:
a) everyone running checkpatch.pl
b) everyone testing all printk-s they addedI guess pf/pF still can sneak in.
Any use of %p<invalid_extension> could sneak in.
And thanks, the checkpatch test for %p<invalid_extensions> should be updated too.
Quoted 3 lines
But I don't have a really strong opinion on this. If general consensus is that we shall remove deprecated specifiers, then I'm fine.
I think converting deprecated things is generally good.
Also, the %p<extension> lettering space is limited, so cleaning deprecated extensions is useful.
Quoted 7 lines
After running this script I still have a bunch of leftovers:
//
// these two are probably not really relevant, but still - %pF/%pf //tools/lib/traceevent/event-parse.c: if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr)< 0)tools/lib/traceevent/event-parse.c: if (asprintf(&format, "%s: %s", "%pf", printk->printk)< 0)
I was not/am not sure about those.
Quoted 4 lines
arch/um/kernel/sysrq.c: pr_info(" [<%08lx>] %s%pF\n", address, reliable ? "" : "? ",
arch/x86/xen/multicalls.c: printk(KERN_DEBUG " call %2d/%d: op=%lu arg=[%lx] result=%ld\t%pF\n",
kernel/async.c: pr_debug("calling %lli_%pF @ %i\n",
kernel/async.c: pr_debug("initcall %lli_%pF returned 0 after %lld usecs\n",Missed those by using \b, thanks again.
Petr Mladek
maintainerQuoted 21 lines · Joe Perches
commit
04b8eb7a4ccd("symbol lookup: introducedereference_symbol_descriptor()}"deprecated vsprintf extension %pf and %pF.
so a script to convert all the %pf uses to %ps and %pF uses to %pS could be useful.
There are a few files that appear should not be converted.
$ git grep -w --name-only -i '%pf'| \ grep -vP '^(?:Documentation|tools|include/linux/freezer.h)'| \ xargs sed -i -e 's/%pf/%ps/g' -e 's/%pF/%pS/g'If that script above is run, it leaves the following patch to be applied:
lib/vsprintf.c +0
-0
lib/vsprintf.c char *pointer(const char *fmt, char *buf, char *end, void *ptr, · line 1876
Quoted 5 lines
lib/vsprintf.c +0
-2@@ -1872,8 +1870,6 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, }switch (*fmt) { -case 'F' : -case 'f' :
Please, keep handling these modifiers so that they do not get reused anytime soon.
The pointer modifiers are evil. Any misuse can easily lead to a crash. Any mistakes with upstreaming 3rd party patches or backporting stable fixes would be hard to notice.
Well, it is perfectly fine to just explicitly fallback to the default %p behavior. I mean something like:
case 'F': case 'f': /* Replaced by %ps and %pS and removed in 4.21 */ break;
Best Regards,
Petr