Thread (6 messages) 6 messages, 2 authors, 2026-02-25

Re: [PATCH v3 1/2] nfs: fix unused variable warning when CONFIG_SUNRPC_DEBUG is disabled

From: Sean Chang <hidden>
Date: 2026-02-25 16:30:49
Also in: linux-nfs, lkml

On Wed, Feb 25, 2026 at 1:54 AM Andrew Lunn [off-list ref] wrote:
quoted
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c
index 9056f05a67dc..de9e8bad6af2 100644
--- a/fs/nfs/flexfilelayout/flexfilelayout.c
+++ b/fs/nfs/flexfilelayout/flexfilelayout.c
@@ -1502,7 +1502,7 @@ static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg,
 {
      struct nfs4_ff_layout_mirror *mirror;
      u32 status = *op_status;
-     int err;
+     int err __maybe_unused;
Sorry, but this is ugly. There must be a better way to fix this.

Maybe look at no_printk().

https://elixir.bootlin.com/linux/v6.19.3/source/drivers/video/fbdev/core/fbmon.c#L50

#ifdef DEBUG
#define DPRINTK(fmt, args...) printk(fmt,## args)
#else
#define DPRINTK(fmt, args...) no_printk(fmt, ##args)
#endif
You are absolutely right, adding __maybe_unused to every
variable is indeed ugly and repetitive. I investigated the suggestion
of using no_printk(). It provides the same dummy-function
behavior while allowing the compiler to perform type checking
on the arguments. This effectively silences the -Wunused-variable
warnings without generating any machine code.

I propose modifying include/linux/sunrpc/debug.h to update the
stubs for dfprintk and dfprintk_rcu when CONFIG_SUNRPC_DEBUG
is disabled:
- # 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__)

Best regards,
Sean
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help