The Xe driver's XE_IOCTL_DBG macro calls drm_dbg() from inside an if
(expression).  This breaks when CONFIG_DRM_USE_DYNAMIC_DEBUG=y because
the invoked macro has a do-while-0 wrapper, and is not an expression.

   if (cond && (drm_dbg("expr-form"),1)) {
      ... do some more stuff
   }

Fix for this usage by changing __dynamic_func_call_cls{,_no_desc}
macros into expressions, by replacing the do-while-0s with a ({ })
wrapper.  In the common usage, the trailing ';' converts the
expression into a statement.

   drm_dbg("statement form");

Signed-off-by: Jim Cromie <[email protected]>
Reviewed-by: Louis Chauvet <[email protected]>
---
v2:

fix statement-expressions to return 0 (not void) like their respective fallbacks

   1. Add 0; to __dynamic_func_call_cls
   2. Add 0; to __dynamic_func_call_cls_no_desc
   3. Convert the disabled fallback of dynamic_hex_dump from do { ... } 
while(0) to ({ ... 0; })

move RvB after SoB
---
 include/linux/dynamic_debug.h | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 11ec40f488f3..fe73aa27b350 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -224,24 +224,26 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
  * (|_cls):    adds in _DPRINT_CLASS_DFLT as needed
  * (|_no_desc):        former gets callsite descriptor as 1st arg (for prdbgs)
  */
-#define __dynamic_func_call_cls(id, cls, fmt, func, ...) do {  \
+#define __dynamic_func_call_cls(id, cls, fmt, func, ...) ({    \
        DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt);        \
        if (DYNAMIC_DEBUG_BRANCH(id)) {                         \
                func(&id, ##__VA_ARGS__);                       \
                __dynamic_dump_stack(id);                       \
        }                                                       \
-} while (0)
+       0; /* match no_printk return value */                   \
+})
 #define __dynamic_func_call(id, fmt, func, ...)                                
\
        __dynamic_func_call_cls(id, _DPRINTK_CLASS_DFLT, fmt,           \
                                func, ##__VA_ARGS__)
 
-#define __dynamic_func_call_cls_no_desc(id, cls, fmt, func, ...) do {  \
+#define __dynamic_func_call_cls_no_desc(id, cls, fmt, func, ...) ({    \
        DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt);                \
        if (DYNAMIC_DEBUG_BRANCH(id)) {                                 \
                func(__VA_ARGS__);                                      \
                __dynamic_dump_stack(id);                               \
        }                                                               \
-} while (0)
+       0; /* match no_printk return value */                           \
+})
 #define __dynamic_func_call_no_desc(id, fmt, func, ...)                        
\
        __dynamic_func_call_cls_no_desc(id, _DPRINTK_CLASS_DFLT,        \
                                        fmt, func, ##__VA_ARGS__)
@@ -321,10 +323,12 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
        dev_no_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__)
 #define dynamic_hex_dump(prefix_str, prefix_type, rowsize,             \
                         groupsize, buf, len, ascii)                    \
-       do { if (0)                                                     \
+({                                                                     \
+       if (0)                                                          \
                print_hex_dump(KERN_DEBUG, prefix_str, prefix_type,     \
-                               rowsize, groupsize, buf, len, ascii);   \
-       } while (0)
+                              rowsize, groupsize, buf, len, ascii);    \
+       0;                                                              \
+})
 
 #endif /* CONFIG_DYNAMIC_DEBUG || (CONFIG_DYNAMIC_DEBUG_CORE && 
DYNAMIC_DEBUG_MODULE) */
 

-- 
2.54.0


Reply via email to