Re: [PATCH] printk-formats.txt: Add examples for %pS and %pF
From: Petr Mladek
Date: Tue Aug 15 2017 - 07:36:35 EST
On Fri 2017-08-11 09:31:28, Helge Deller wrote:
> On 11.08.2017 02:15, Sergey Senozhatsky wrote:
> > On (08/10/17 19:35), Helge Deller wrote:
> >> Sometimes people seems unclear when to use the %pS or %pF printk format.
> >> Adding some examples may help to avoid such mistakes.
> >>
> >> See for example commit 51d96dc2e2dc ("random: fix warning message on ia64 and
> >> parisc") which fixed such a wrong format string.
> >>
> >> Signed-off-by: Helge Deller <deller@xxxxxx>
> >>
> >> diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
> >> index 65ea591..be8c05b 100644
> >> --- a/Documentation/printk-formats.txt
> >> +++ b/Documentation/printk-formats.txt
> >> @@ -73,6 +73,12 @@ actually function descriptors which must first be resolved. The ``F`` and
> >> ``f`` specifiers perform this resolution and then provide the same
> >> functionality as the ``S`` and ``s`` specifiers.
> >>
> >> +Examples::
> >> +
> >> + printk("Called from %pS.\n", __builtin_return_address(0));
> >> + printk("Called from %pS.\n", (void *)regs->ip);
> >> + printk("Called from %pF.\n", &gettimeofday);
> >
> > there is this paragraph
> >
> > : On ia64, ppc64 and parisc64 architectures function pointers are
> > : actually function descriptors which must first be resolved. The ``F`` and
> > : ``f`` specifiers perform this resolution and then provide the same
> > : functionality as the ``S`` and ``s`` specifiers.
> >
> > which supposed to explain everything in details. the examples
> > don't make it any `clearer', IMHO.
>
> Experts surely do know what function descriptors are.
> Nevertheless even those often get it wrong as can be seen in
> various commits.
It seems that these specifiers are used the wrong way on many
locations. They might be worth fixing but I cannot test it
easily.
Hmm, using %pF might actually cause a crash when used
on direct function address.
> The hope with this patch is to show widely-used examples
> and avoid additional commits afterwards to fix it up.
IMHO, one problem is that the meaning of ''F'' and ''f''
is hidden at the end of the section. Also the first line
'For printing symbols and function pointers. The ``S`` and ``s`` '
kind of invites to use ``S`` and ``s`` even for function pointers.
I suggest to switch the order, slightly retranslate, add the
examples, see below.
> This patch was meant to be RFC.
> If you decide not to take it, I'm fine as well.
>
> > *may be* on "ia64, ppc64 and parisc64" we can somehow check
> > that the pointer, which we pass as %pS, belongs to .text and
> > print some build-time warnings. well, if it's actually a
> > problem. dunno.
I think that it would need to be a runtime check because many/most
printed addresses are not statically defined.
> I think it's not needed. Those bugs will be seen and fixed.
I am not sure how many people are familiar with this problem.
I might help to avoid some headaches when debugging.
If we add the warning, it should be ratelimited to reduce messing
of the original message.
I do not have strong opinion about it.
Here is the updated patch with my proposed changes.
Feel free to update it: