Re: [PATCH v3 1/2] nfs: fix unused variable warning when CONFIG_SUNRPC_DEBUG is disabled
From: Andrew Lunn
Date: Tue Feb 24 2026 - 12:55:05 EST
On Wed, Feb 25, 2026 at 12:54:34AM +0800, Sean Chang wrote:
> When CONFIG_SUNRPC_DEBUG is disabled, the dprintk() macro expands to
> an empty do-while loop. This causes variables used solely within
> dprintk() calls to appear unused to the compiler, triggering
> -Wunused-variable warnings.
>
> Fix this by adding __maybe_unused to the affected variables. This
> ensures the code builds cleanly across different configurations,
> including RISC-V, ARM, and ARM64 allmodconfig, as verified in the
> mailing list discussion.
>
> Signed-off-by: Sean Chang <seanwascoding@xxxxxxxxx>
> ---
> fs/nfs/flexfilelayout/flexfilelayout.c | 2 +-
> fs/nfs/flexfilelayout/flexfilelayoutdev.c | 3 ++-
> fs/nfs/nfs4proc.c | 2 +-
> 3 files changed, 4 insertions(+), 3 deletions(-)
>
> 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
Andrew
---
pw-bot: cr