Re: [RFC/PATCH] lib/vsprintf: Add support to store cpumask
From: Steven Rostedt
Date: Tue Jun 28 2016 - 18:08:28 EST
On Tue, 28 Jun 2016 21:27:29 +0200
Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx> wrote:
> > I probably should make a trace_printk() that doesn't default to the
> > binary print, to handle things like this.
> >
> > trace_printk_ptr()?
> >
> > Or even just see if I can find a way that detects this in the fmt
> > string. Hmm, that probably can't be done at compile time :-/
>
> Well, not with gcc itself, but it wouldn't be too hard to make smatch
> complain loudly if trace_printk is used on a format string with any %p
> extension (directing people to use trace_printk_ptr()) - the format
> parsing (and type checking) is already there.
Well, actually gcc can (see below). Although, the more I think about
this, the more I'm thinking that the bin_printk() should be default
just copy the pointer content. As the whole point of bin_printk() is to
print the content at another time. And since pointers should not be
dereferenced later, it should be saved at the moment the bprintk() is
called and not dereferenced later.
-- Steve
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 94aa10ffe156..62693900cc4b 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -631,7 +631,24 @@ do { \
\
__trace_printk_check_format(fmt, ##args); \
\
- if (__builtin_constant_p(fmt)) \
+ if (__builtin_constant_p(fmt) && \
+ !__builtin_strstr(fmt, "%pF") && \
+ !__builtin_strstr(fmt, "%pf") && \
+ !__builtin_strstr(fmt, "%pR") && \
+ !__builtin_strstr(fmt, "%pr") && \
+ !__builtin_strstr(fmt, "%pb") && \
+ !__builtin_strstr(fmt, "%pM") && \
+ !__builtin_strstr(fmt, "%pI") && \
+ !__builtin_strstr(fmt, "%pE") && \
+ !__builtin_strstr(fmt, "%pU") && \
+ !__builtin_strstr(fmt, "%pV") && \
+ !__builtin_strstr(fmt, "%pN") && \
+ !__builtin_strstr(fmt, "%pa") && \
+ !__builtin_strstr(fmt, "%pd") && \
+ !__builtin_strstr(fmt, "%pC") && \
+ !__builtin_strstr(fmt, "%pD") && \
+ !__builtin_strstr(fmt, "%pg") && \
+ !__builtin_strstr(fmt, "%pG")) \
__trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args); \
else \
__trace_printk(_THIS_IP_, fmt, ##args); \