[Intel-gfx] [PATCH 2/2] drm/i915: Compile time concatenate WARN_ON macro strings

Daniel Vetter daniel at ffwll.ch
Mon Dec 21 05:25:51 PST 2015


On Fri, Dec 18, 2015 at 02:11:24PM +0200, Joonas Lahtinen wrote:
> On pe, 2015-12-18 at 12:03 +0000, Dave Gordon wrote:
> > On 18/12/15 10:39, Joonas Lahtinen wrote:
> > > Using __stringify(x) instead of #x adds support for macros as
> > > a parameter and reduces runtime overhead.
> > > 
> > > Slightly increases the .text size but should not matter.
> > > 
> > > v2:
> > > - Define I915_STATE_WARN_ON though I915_STATE_WARN
> > >    (Bikeshed inspiration by Chris)
> > > 
> > > Cc: Rob Clark <robdclark at gmail.com>
> > > Cc: Chris Wilson <chris at chris-wilson.co.uk>
> > > Acked-by: Daniel Vetter <daniel.vetter at ffwll.ch>
> > > Signed-off-by: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
> > > ---
> > >   drivers/gpu/drm/i915/i915_drv.h | 14 ++++----------
> > >   1 file changed, 4 insertions(+), 10 deletions(-)
> > > 
> > > 
> 
> <SNIP>
> 
> > > 					
> > > \
> > > -})
> > > +#define I915_STATE_WARN_ON(x)					
> > > 	\
> > > +	I915_STATE_WARN((x), "WARN_ON(" __stringify(x) ")")
> > > 
> > >   static inline const char *yesno(bool v)
> > >   {
> > 
> > NAK.
> > 
> > This will give compile-time warnings for lines such as:
> > 
> > 	WARN_ON(x%16 != 0);
> > 
> > because the stringified text of the expression (which in this case 
> > contains a "%" character) would appear as part of the format string, 
> > rather than inside an argument. See:
> > 
> > 4eee492 drm/i915: fix driver's versions of WARN_ON & WARN_ON_ONCE
> > 
> 
> Great catch, I'll change it to have preceding "%s". Did not get any
> compile-time warning though, this would be something caught by a
> (rather advanced?) static analysis.

New gcc seems to complain about this. At least since a few weeks I've seen
a few patches for kernel-wide changes to address this float about.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the Intel-gfx mailing list