Re: [PATCH v4 1/2] sunrpc: fix unused variable warnings by using no_printk

From
Sean Chang <hidden>
Date
2026-02-28 14:56:39
Also in
linux-nfs, lkml
Reply to
David Laight, 2026-02-27
On Sat, Feb 28, 2026 at 2:15 AM David Laight
[off-list ref] wrote:
On Fri, 27 Feb 2026 18:57:33 +0100
Andrew Lunn [off-list ref] wrote:
quoted
quoted
quoted
 # define ifdebug(fac)            if (0)
-# define dfprintk(fac, fmt, ...) do {} while (0)
-# define dfprintk_rcu(fac, fmt, ...)     do {} while (0)
+# define dfprintk(fac, fmt, ...) no_printk(fmt, ##__VA_ARGS__)
+# define dfprintk_rcu(fac, fmt, ...)     no_printk(fmt, ##__VA_ARGS__)
You can omit fmt, then you don't need the ##
#define dfprintk(fac, ...)  no_printk(__VA_ARGS__)
/*
 * Dummy printk for disabled debugging statements to use whilst maintaining
 * gcc's format checking.
 */
#define no_printk(fmt, ...)                           \
({                                                    \
      if (0)                                          \
              _printk(fmt, ##__VA_ARGS__);            \
      0;                                              \
})

Without fmt, gcc cannot do format checking. Or worse, it takes the
first member of __VA_ARGS__ as the format, and gives spurious errors?
By the time the compiler looks at it the pre-processor has expanded
__VA_ARGS__.
So it doesn't matter that the format string is in the __VA_ARGS__
list rather than preceding it.
Hi David,
Thanks for the explanation. I agree that since __VA_ARGS__ will
always contain the format string in this context, the ## and explicit
fmt are indeed redundant. Since no_printk itself already handles
the ##__VA_ARGS__ logic internally, there's no need to duplicate
it in the dfprintk definition.

I'll switch to the simpler in v5:
-# define dfprintk(fac, fmt, ...)            no_printk(fmt, ##__VA_ARGS__)
-# define dfprintk_rcu(fac, fmt, ...)     no_printk(fmt, ##__VA_ARGS__)
+#define dfprintk(fac, ...)                   no_printk(__VA_ARGS__)
+# define dfprintk_rcu(fac, ...)           no_printk(__VA_ARGS__)

Best regards,
Sean
Thread (12 messages) 12 messages, 4 authors, last reply 2026-03-01
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help